@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | if (isset($statementParts['keywords']['distinct'])) { |
170 | 170 | unset($statementParts['keywords']['distinct']); |
171 | 171 | $distinctField = $this->query->getDistinct() ? $this->query->getDistinct() : 'uid'; |
172 | - $statementParts['fields'] = array('COUNT(DISTINCT ' . $statementParts['mainTable'] . '.' . $distinctField . ')'); |
|
172 | + $statementParts['fields'] = array('COUNT(DISTINCT '.$statementParts['mainTable'].'.'.$distinctField.')'); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | $sql = $this->buildQuery($statementParts); |
@@ -232,14 +232,14 @@ discard block |
||
232 | 232 | // tx_domain_model_foo0 (the alias) <--> tx_domain_model_foo (the origin table name) |
233 | 233 | $values = []; |
234 | 234 | foreach ($statementParts['fields'] as $key => $value) { |
235 | - $values[$key] = str_replace($tableName, $tableName . '0', $value); |
|
235 | + $values[$key] = str_replace($tableName, $tableName.'0', $value); |
|
236 | 236 | } |
237 | 237 | $statementParts['fields'] = $values; |
238 | 238 | |
239 | 239 | // Same comment as above. |
240 | 240 | $values = []; |
241 | 241 | foreach ($statementParts['where'] as $key => $value) { |
242 | - $values[$key] = str_replace($tableName . '0', $tableName, $value); |
|
242 | + $values[$key] = str_replace($tableName.'0', $tableName, $value); |
|
243 | 243 | } |
244 | 244 | $statementParts['where'] = $values; |
245 | 245 | |
@@ -278,25 +278,25 @@ discard block |
||
278 | 278 | if (!empty($statementParts['unions'])) { |
279 | 279 | foreach ($statementParts['unions'] as $tableName => $unionPart) { |
280 | 280 | if (!empty($statementParts['additionalWhereClause'][$tableName])) { |
281 | - $statementParts['unions'][$tableName] .= ' AND ' . implode(' AND ', $statementParts['additionalWhereClause'][$tableName]); |
|
281 | + $statementParts['unions'][$tableName] .= ' AND '.implode(' AND ', $statementParts['additionalWhereClause'][$tableName]); |
|
282 | 282 | } |
283 | 283 | } |
284 | 284 | } |
285 | 285 | |
286 | - $statement = 'SELECT ' . implode(' ', $statementParts['keywords']) . ' ' . implode(',', $statementParts['fields']) . ' FROM ' . implode(' ', $statementParts['tables']) . ' ' . implode(' ', $statementParts['unions']); |
|
286 | + $statement = 'SELECT '.implode(' ', $statementParts['keywords']).' '.implode(',', $statementParts['fields']).' FROM '.implode(' ', $statementParts['tables']).' '.implode(' ', $statementParts['unions']); |
|
287 | 287 | if (!empty($statementParts['where'])) { |
288 | - $statement .= ' WHERE ' . implode('', $statementParts['where']); |
|
288 | + $statement .= ' WHERE '.implode('', $statementParts['where']); |
|
289 | 289 | if (!empty($statementParts['additionalWhereClause'][$this->query->getType()])) { |
290 | - $statement .= ' AND ' . implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]); |
|
290 | + $statement .= ' AND '.implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]); |
|
291 | 291 | } |
292 | 292 | } elseif (!empty($statementParts['additionalWhereClause'])) { |
293 | - $statement .= ' WHERE ' . implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]); |
|
293 | + $statement .= ' WHERE '.implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]); |
|
294 | 294 | } |
295 | 295 | if (!empty($statementParts['orderings'])) { |
296 | - $statement .= ' ORDER BY ' . implode(', ', $statementParts['orderings']); |
|
296 | + $statement .= ' ORDER BY '.implode(', ', $statementParts['orderings']); |
|
297 | 297 | } |
298 | 298 | if (!empty($statementParts['limit'])) { |
299 | - $statement .= ' LIMIT ' . $statementParts['limit']; |
|
299 | + $statement .= ' LIMIT '.$statementParts['limit']; |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | return $statement; |
@@ -312,9 +312,9 @@ discard block |
||
312 | 312 | protected function parseSource(SourceInterface $source, array &$sql) |
313 | 313 | { |
314 | 314 | $tableName = $this->getTableName(); |
315 | - $sql['fields'][$tableName] = $tableName . '.*'; |
|
315 | + $sql['fields'][$tableName] = $tableName.'.*'; |
|
316 | 316 | if ($this->query->getDistinct()) { |
317 | - $sql['fields'][$tableName] = $tableName . '.' . $this->query->getDistinct(); |
|
317 | + $sql['fields'][$tableName] = $tableName.'.'.$this->query->getDistinct(); |
|
318 | 318 | $sql['keywords']['distinct'] = 'DISTINCT'; |
319 | 319 | } |
320 | 320 | $sql['tables'][$tableName] = $tableName; |
@@ -452,7 +452,7 @@ discard block |
||
452 | 452 | if ($realInput instanceof DomainObjectInterface) { |
453 | 453 | return $realInput->getUid(); |
454 | 454 | } else { |
455 | - throw new UnexpectedTypeException('An object of class "' . get_class($realInput) . '" could not be converted to a plain value.', 1274799934); |
|
455 | + throw new UnexpectedTypeException('An object of class "'.get_class($realInput).'" could not be converted to a plain value.', 1274799934); |
|
456 | 456 | } |
457 | 457 | } elseif (is_bool($input)) { |
458 | 458 | return $input === true ? 1 : 0; |
@@ -502,9 +502,9 @@ discard block |
||
502 | 502 | : '?'; |
503 | 503 | |
504 | 504 | if ($valueFunction === null) { |
505 | - $constraintSQL .= (!empty($tableName) ? $tableName . '.' : '') . $columnName . ' ' . $resolvedOperator . ' ' . $marker; |
|
505 | + $constraintSQL .= (!empty($tableName) ? $tableName.'.' : '').$columnName.' '.$resolvedOperator.' '.$marker; |
|
506 | 506 | } else { |
507 | - $constraintSQL .= $valueFunction . '(' . (!empty($tableName) ? $tableName . '.' : '') . $columnName . ') ' . $resolvedOperator . ' ' . $marker; |
|
507 | + $constraintSQL .= $valueFunction.'('.(!empty($tableName) ? $tableName.'.' : '').$columnName.') '.$resolvedOperator.' '.$marker; |
|
508 | 508 | } |
509 | 509 | |
510 | 510 | if (isset($tableName) && !empty($this->currentChildTableNameAlias)) { |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | // to determine the relation type. Example for sys_category, property path will look like "items.sys_file" |
532 | 532 | $parts = explode('.', $propertyPath, 3); |
533 | 533 | if ($table->field($fieldName)->isGroup() && count($parts) > 2) { |
534 | - $explodedPropertyPath[0] = $parts[0] . '.' . $parts[1]; |
|
534 | + $explodedPropertyPath[0] = $parts[0].'.'.$parts[1]; |
|
535 | 535 | $explodedPropertyPath[1] = $parts[2]; |
536 | 536 | $fieldName = $explodedPropertyPath[0]; |
537 | 537 | } |
@@ -540,16 +540,16 @@ discard block |
||
540 | 540 | $childTableName = $table->field($fieldName)->getForeignTable(); |
541 | 541 | |
542 | 542 | if ($childTableName === null) { |
543 | - throw new InvalidRelationConfigurationException('The relation information for property "' . $fieldName . '" of class "' . $tableName . '" is missing.', 1353170925); |
|
543 | + throw new InvalidRelationConfigurationException('The relation information for property "'.$fieldName.'" of class "'.$tableName.'" is missing.', 1353170925); |
|
544 | 544 | } |
545 | 545 | |
546 | 546 | if ($table->field($fieldName)->hasOne()) { // includes relation "one-to-one" and "many-to-one" |
547 | 547 | // sometimes the opposite relation is not defined. We don't want to force this config for backward compatibility reasons. |
548 | 548 | // $parentKeyFieldName === null does the trick somehow. Before condition was if (isset($parentKeyFieldName)) |
549 | 549 | if ($table->field($fieldName)->hasRelationManyToOne() || $parentKeyFieldName === null) { |
550 | - $statementParts['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.' . $fieldName . '=' . $childTableName . '.uid'; |
|
550 | + $statementParts['unions'][$childTableName] = 'LEFT JOIN '.$childTableName.' ON '.$tableName.'.'.$fieldName.'='.$childTableName.'.uid'; |
|
551 | 551 | } else { |
552 | - $statementParts['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.uid=' . $childTableName . '.' . $parentKeyFieldName; |
|
552 | + $statementParts['unions'][$childTableName] = 'LEFT JOIN '.$childTableName.' ON '.$tableName.'.uid='.$childTableName.'.'.$parentKeyFieldName; |
|
553 | 553 | } |
554 | 554 | } elseif ($table->field($fieldName)->hasRelationManyToMany()) { |
555 | 555 | $relationTableName = $table->field($fieldName)->getManyToManyTable(); |
@@ -779,18 +779,18 @@ discard block |
||
779 | 779 | // If the table is found to have "workspace" support, add the corresponding fields in the statement. |
780 | 780 | if (Tca::table($tableName)->hasWorkspaceSupport()) { |
781 | 781 | if ($this->getBackendUser()->workspace === 0) { |
782 | - $statement .= ' AND ' . $tableName . '.t3ver_state<=' . new VersionState(VersionState::DEFAULT_STATE); |
|
782 | + $statement .= ' AND '.$tableName.'.t3ver_state<='.new VersionState(VersionState::DEFAULT_STATE); |
|
783 | 783 | } else { |
784 | 784 | // Show only records of live and of the current workspace |
785 | 785 | // In case we are in a Versioning preview |
786 | - $statement .= ' AND (' . |
|
787 | - $tableName . '.t3ver_wsid=0 OR ' . |
|
788 | - $tableName . '.t3ver_wsid=' . (int)$this->getBackendUser()->workspace . |
|
786 | + $statement .= ' AND ('. |
|
787 | + $tableName.'.t3ver_wsid=0 OR '. |
|
788 | + $tableName.'.t3ver_wsid='.(int)$this->getBackendUser()->workspace. |
|
789 | 789 | ')'; |
790 | 790 | } |
791 | 791 | |
792 | 792 | // Check if this segment make sense here or whether it should be in the "if" part when we have workspace = 0 |
793 | - $statement .= ' AND ' . $tableName . '.pid<>-1'; |
|
793 | + $statement .= ' AND '.$tableName.'.pid<>-1'; |
|
794 | 794 | } |
795 | 795 | |
796 | 796 | if (!$includeDeleted) { |
@@ -815,25 +815,25 @@ discard block |
||
815 | 815 | if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) { |
816 | 816 | if (!empty($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])) { |
817 | 817 | // Select all entries for the current language |
818 | - $additionalWhereClause = $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . ' IN (' . intval($querySettings->getLanguageUid()) . ',-1)'; |
|
818 | + $additionalWhereClause = $tableNameOrAlias.'.'.$GLOBALS['TCA'][$tableName]['ctrl']['languageField'].' IN ('.intval($querySettings->getLanguageUid()).',-1)'; |
|
819 | 819 | // If any language is set -> get those entries which are not translated yet |
820 | 820 | // They will be removed by t3lib_page::getRecordOverlay if not matching overlay mode |
821 | 821 | if (isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']) |
822 | 822 | && $querySettings->getLanguageUid() > 0 |
823 | 823 | ) { |
824 | - $additionalWhereClause .= ' OR (' . $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=0' . |
|
825 | - ' AND ' . $tableNameOrAlias . '.uid NOT IN (SELECT ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] . |
|
826 | - ' FROM ' . $tableName . |
|
827 | - ' WHERE ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] . '>0' . |
|
828 | - ' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '>0'; |
|
824 | + $additionalWhereClause .= ' OR ('.$tableNameOrAlias.'.'.$GLOBALS['TCA'][$tableName]['ctrl']['languageField'].'=0'. |
|
825 | + ' AND '.$tableNameOrAlias.'.uid NOT IN (SELECT '.$tableName.'.'.$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']. |
|
826 | + ' FROM '.$tableName. |
|
827 | + ' WHERE '.$tableName.'.'.$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'].'>0'. |
|
828 | + ' AND '.$tableName.'.'.$GLOBALS['TCA'][$tableName]['ctrl']['languageField'].'>0'; |
|
829 | 829 | |
830 | 830 | // Add delete clause to ensure all entries are loaded |
831 | 831 | if (isset($GLOBALS['TCA'][$tableName]['ctrl']['delete'])) { |
832 | - $additionalWhereClause .= ' AND ' . $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['delete'] . '=0'; |
|
832 | + $additionalWhereClause .= ' AND '.$tableNameOrAlias.'.'.$GLOBALS['TCA'][$tableName]['ctrl']['delete'].'=0'; |
|
833 | 833 | } |
834 | 834 | $additionalWhereClause .= '))'; |
835 | 835 | } |
836 | - $statementParts['additionalWhereClause'][$tableNameOrAlias][] = '(' . $additionalWhereClause . ')'; |
|
836 | + $statementParts['additionalWhereClause'][$tableNameOrAlias][] = '('.$additionalWhereClause.')'; |
|
837 | 837 | } |
838 | 838 | } |
839 | 839 | } |
@@ -878,7 +878,7 @@ discard block |
||
878 | 878 | protected function parseLimitAndOffset($limit, $offset, array &$statementParts) |
879 | 879 | { |
880 | 880 | if ($limit !== null && $offset !== null) { |
881 | - $statementParts['limit'] = intval($offset) . ', ' . intval($limit); |
|
881 | + $statementParts['limit'] = intval($offset).', '.intval($limit); |
|
882 | 882 | } elseif ($limit !== null) { |
883 | 883 | $statementParts['limit'] = intval($limit); |
884 | 884 | } |
@@ -946,11 +946,11 @@ discard block |
||
946 | 946 | ) { |
947 | 947 | $queryBuilder = $this->getQueryBuilder(); |
948 | 948 | $row = $queryBuilder |
949 | - ->select($tableName . '.*') |
|
949 | + ->select($tableName.'.*') |
|
950 | 950 | ->from($tableName) |
951 | 951 | ->andWhere( |
952 | - $tableName . '.uid=' . (int)$row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']], |
|
953 | - $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . ' = 0' |
|
952 | + $tableName.'.uid='.(int)$row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']], |
|
953 | + $tableName.'.'.$GLOBALS['TCA'][$tableName]['ctrl']['languageField'].' = 0' |
|
954 | 954 | ) |
955 | 955 | ->execute() |
956 | 956 | ->fetch(); |
@@ -1011,7 +1011,7 @@ discard block |
||
1011 | 1011 | } |
1012 | 1012 | |
1013 | 1013 | $numberOfAliases = $this->tableNameAliases['aliasIncrement'][$tableName]; |
1014 | - $tableNameAlias = $tableName . $numberOfAliases; |
|
1014 | + $tableNameAlias = $tableName.$numberOfAliases; |
|
1015 | 1015 | |
1016 | 1016 | $this->tableNameAliases['aliasIncrement'][$tableName]++; |
1017 | 1017 | $this->tableNameAliases['aliases'][$tableNameAlias] = $tableName; |
@@ -53,1044 +53,1044 @@ |
||
53 | 53 | */ |
54 | 54 | class VidiDbBackend |
55 | 55 | { |
56 | - public const OPERATOR_EQUAL_TO_NULL = 'operatorEqualToNull'; |
|
57 | - public const OPERATOR_NOT_EQUAL_TO_NULL = 'operatorNotEqualToNull'; |
|
58 | - |
|
59 | - /** |
|
60 | - * The TYPO3 page repository. Used for language and workspace overlay |
|
61 | - * |
|
62 | - * @var PageRepository |
|
63 | - */ |
|
64 | - protected $pageRepository; |
|
65 | - |
|
66 | - /** |
|
67 | - * @var Query |
|
68 | - */ |
|
69 | - protected $query; |
|
70 | - |
|
71 | - /** |
|
72 | - * Store some info related to table name and its aliases. |
|
73 | - * |
|
74 | - * @var array |
|
75 | - */ |
|
76 | - protected $tableNameAliases = array( |
|
77 | - 'aliases' => [], |
|
78 | - 'aliasIncrement' => [], |
|
79 | - ); |
|
80 | - |
|
81 | - /** |
|
82 | - * Use to store the current foreign table name alias. |
|
83 | - * |
|
84 | - * @var string |
|
85 | - */ |
|
86 | - protected $currentChildTableNameAlias = ''; |
|
87 | - |
|
88 | - /** |
|
89 | - * @param Query $query |
|
90 | - */ |
|
91 | - public function __construct(Query $query) |
|
92 | - { |
|
93 | - $this->query = $query; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * @param $parameters |
|
98 | - * @return array |
|
99 | - */ |
|
100 | - protected static function getTypes($parameters) |
|
101 | - { |
|
102 | - $types = []; |
|
103 | - foreach ($parameters as $parameter) { |
|
104 | - if (is_array($parameter)) { |
|
105 | - if (MathUtility::canBeInterpretedAsInteger($parameter[0])) { |
|
106 | - $types[] = \Doctrine\DBAL\Connection::PARAM_INT_ARRAY; |
|
107 | - } else { |
|
108 | - $types[] = \Doctrine\DBAL\Connection::PARAM_STR_ARRAY; |
|
109 | - } |
|
110 | - } else { |
|
111 | - if (MathUtility::canBeInterpretedAsInteger($parameter)) { |
|
112 | - $types[] = ParameterType::INTEGER; |
|
113 | - } else { |
|
114 | - $types[] = ParameterType::STRING; |
|
115 | - } |
|
116 | - } |
|
117 | - } |
|
118 | - return $types; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Returns the result of the query |
|
123 | - */ |
|
124 | - public function fetchResult() |
|
125 | - { |
|
126 | - $parameters = []; |
|
127 | - $statementParts = $this->parseQuery($parameters); |
|
128 | - $statementParts = $this->processStatementStructureForRecursiveMMRelation($statementParts); |
|
129 | - $sql = $this->buildQuery($statementParts); |
|
130 | - //print $sql; exit(); |
|
131 | - |
|
132 | - $rows = $this->getConnection() |
|
133 | - ->executeQuery($sql, $parameters, self::getTypes($parameters)) |
|
134 | - ->fetchAllAssociative(); |
|
135 | - |
|
136 | - return $this->getContentObjects($rows); |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Returns the number of tuples matching the query. |
|
141 | - * |
|
142 | - * @return int The number of matching tuples |
|
143 | - */ |
|
144 | - public function countResult() |
|
145 | - { |
|
146 | - $parameters = []; |
|
147 | - $statementParts = $this->parseQuery($parameters); |
|
148 | - $statementParts = $this->processStatementStructureForRecursiveMMRelation($statementParts); |
|
149 | - $types = self::getTypes($parameters); |
|
150 | - |
|
151 | - // if limit is set, we need to count the rows "manually" as COUNT(*) ignores LIMIT constraints |
|
152 | - if (!empty($statementParts['limit'])) { |
|
153 | - $sql = $this->buildQuery($statementParts); |
|
154 | - |
|
155 | - $count = $this |
|
156 | - ->getConnection() |
|
157 | - ->executeQuery($sql, $parameters, $types) |
|
158 | - ->rowCount(); |
|
159 | - } else { |
|
160 | - $statementParts['fields'] = array('COUNT(*)'); |
|
161 | - // having orderings without grouping is not compatible with non-MySQL DBMS |
|
162 | - $statementParts['orderings'] = []; |
|
163 | - if (isset($statementParts['keywords']['distinct'])) { |
|
164 | - unset($statementParts['keywords']['distinct']); |
|
165 | - $distinctField = $this->query->getDistinct() ? $this->query->getDistinct() : 'uid'; |
|
166 | - $statementParts['fields'] = array('COUNT(DISTINCT ' . $statementParts['mainTable'] . '.' . $distinctField . ')'); |
|
167 | - } |
|
168 | - |
|
169 | - $sql = $this->buildQuery($statementParts); |
|
170 | - $count = $this |
|
171 | - ->getConnection() |
|
172 | - ->executeQuery($sql, $parameters, $types) |
|
173 | - ->fetchColumn(0); |
|
174 | - } |
|
175 | - return (int)$count; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Parses the query and returns the SQL statement parts. |
|
180 | - * |
|
181 | - * @param array &$parameters |
|
182 | - * @return array |
|
183 | - */ |
|
184 | - public function parseQuery(array &$parameters) |
|
185 | - { |
|
186 | - $statementParts = []; |
|
187 | - $statementParts['keywords'] = []; |
|
188 | - $statementParts['tables'] = []; |
|
189 | - $statementParts['unions'] = []; |
|
190 | - $statementParts['fields'] = []; |
|
191 | - $statementParts['where'] = []; |
|
192 | - $statementParts['additionalWhereClause'] = []; |
|
193 | - $statementParts['orderings'] = []; |
|
194 | - $statementParts['limit'] = []; |
|
195 | - $query = $this->query; |
|
196 | - $source = $query->getSource(); |
|
197 | - $this->parseSource($source, $statementParts); |
|
198 | - $this->parseConstraint($query->getConstraint(), $source, $statementParts, $parameters); |
|
199 | - $this->parseOrderings($query->getOrderings(), $source, $statementParts); |
|
200 | - $this->parseLimitAndOffset($query->getLimit(), $query->getOffset(), $statementParts); |
|
201 | - $tableNames = array_unique(array_keys($statementParts['tables'] + $statementParts['unions'])); |
|
202 | - foreach ($tableNames as $tableNameOrAlias) { |
|
203 | - if (is_string($tableNameOrAlias) && strlen($tableNameOrAlias) > 0) { |
|
204 | - $this->addAdditionalWhereClause($query->getTypo3QuerySettings(), $tableNameOrAlias, $statementParts); |
|
205 | - } |
|
206 | - } |
|
207 | - |
|
208 | - return $statementParts; |
|
209 | - } |
|
210 | - |
|
211 | - /** |
|
212 | - * Fiddle with the statement structure to handle recursive MM relations. |
|
213 | - * For the recursive MM query to work, we must invert some values. |
|
214 | - * Let see if that is the best way of doing that... |
|
215 | - * |
|
216 | - * @param array $statementParts |
|
217 | - * @return array |
|
218 | - */ |
|
219 | - public function processStatementStructureForRecursiveMMRelation(array $statementParts) |
|
220 | - { |
|
221 | - if ($this->hasRecursiveMMRelation()) { |
|
222 | - $tableName = $this->query->getType(); |
|
223 | - |
|
224 | - // In order the MM query to work for a recursive MM query, we must invert some values. |
|
225 | - // tx_domain_model_foo0 (the alias) <--> tx_domain_model_foo (the origin table name) |
|
226 | - $values = []; |
|
227 | - foreach ($statementParts['fields'] as $key => $value) { |
|
228 | - $values[$key] = str_replace($tableName, $tableName . '0', $value); |
|
229 | - } |
|
230 | - $statementParts['fields'] = $values; |
|
231 | - |
|
232 | - // Same comment as above. |
|
233 | - $values = []; |
|
234 | - foreach ($statementParts['where'] as $key => $value) { |
|
235 | - $values[$key] = str_replace($tableName . '0', $tableName, $value); |
|
236 | - } |
|
237 | - $statementParts['where'] = $values; |
|
238 | - |
|
239 | - // We must be more restrictive by transforming the "left" union by "inner" |
|
240 | - $values = []; |
|
241 | - foreach ($statementParts['unions'] as $key => $value) { |
|
242 | - $values[$key] = str_replace('LEFT JOIN', 'INNER JOIN', $value); |
|
243 | - } |
|
244 | - $statementParts['unions'] = $values; |
|
245 | - } |
|
246 | - |
|
247 | - return $statementParts; |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Tell whether there is a recursive MM relation. |
|
252 | - * |
|
253 | - * @return bool |
|
254 | - */ |
|
255 | - public function hasRecursiveMMRelation() |
|
256 | - { |
|
257 | - return isset($this->tableNameAliases['aliasIncrement'][$this->query->getType()]); |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * Returns the statement, ready to be executed. |
|
262 | - * |
|
263 | - * @param array $statementParts The SQL statement parts |
|
264 | - * @return string The SQL statement |
|
265 | - */ |
|
266 | - public function buildQuery(array $statementParts) |
|
267 | - { |
|
268 | - // Add more statement to the UNION part. |
|
269 | - if (!empty($statementParts['unions'])) { |
|
270 | - foreach ($statementParts['unions'] as $tableName => $unionPart) { |
|
271 | - if (!empty($statementParts['additionalWhereClause'][$tableName])) { |
|
272 | - $statementParts['unions'][$tableName] .= ' AND ' . implode(' AND ', $statementParts['additionalWhereClause'][$tableName]); |
|
273 | - } |
|
274 | - } |
|
275 | - } |
|
276 | - |
|
277 | - $statement = 'SELECT ' . implode(' ', $statementParts['keywords']) . ' ' . implode(',', $statementParts['fields']) . ' FROM ' . implode(' ', $statementParts['tables']) . ' ' . implode(' ', $statementParts['unions']); |
|
278 | - if (!empty($statementParts['where'])) { |
|
279 | - $statement .= ' WHERE ' . implode('', $statementParts['where']); |
|
280 | - if (!empty($statementParts['additionalWhereClause'][$this->query->getType()])) { |
|
281 | - $statement .= ' AND ' . implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]); |
|
282 | - } |
|
283 | - } elseif (!empty($statementParts['additionalWhereClause'])) { |
|
284 | - $statement .= ' WHERE ' . implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]); |
|
285 | - } |
|
286 | - if (!empty($statementParts['orderings'])) { |
|
287 | - $statement .= ' ORDER BY ' . implode(', ', $statementParts['orderings']); |
|
288 | - } |
|
289 | - if (!empty($statementParts['limit'])) { |
|
290 | - $statement .= ' LIMIT ' . $statementParts['limit']; |
|
291 | - } |
|
292 | - |
|
293 | - return $statement; |
|
294 | - } |
|
295 | - |
|
296 | - /** |
|
297 | - * Transforms a Query Source into SQL and parameter arrays |
|
298 | - * |
|
299 | - * @param SourceInterface $source The source |
|
300 | - * @param array &$sql |
|
301 | - * @return void |
|
302 | - */ |
|
303 | - protected function parseSource(SourceInterface $source, array &$sql) |
|
304 | - { |
|
305 | - $tableName = $this->getTableName(); |
|
306 | - $sql['fields'][$tableName] = $tableName . '.*'; |
|
307 | - if ($this->query->getDistinct()) { |
|
308 | - $sql['fields'][$tableName] = $tableName . '.' . $this->query->getDistinct(); |
|
309 | - $sql['keywords']['distinct'] = 'DISTINCT'; |
|
310 | - } |
|
311 | - $sql['tables'][$tableName] = $tableName; |
|
312 | - $sql['mainTable'] = $tableName; |
|
313 | - } |
|
314 | - |
|
315 | - /** |
|
316 | - * Transforms a constraint into SQL and parameter arrays |
|
317 | - * |
|
318 | - * @param ConstraintInterface $constraint The constraint |
|
319 | - * @param SourceInterface $source The source |
|
320 | - * @param array &$statementParts The query parts |
|
321 | - * @param array &$parameters The parameters that will replace the markers |
|
322 | - * @return void |
|
323 | - */ |
|
324 | - protected function parseConstraint(ConstraintInterface $constraint = null, SourceInterface $source, array &$statementParts, array &$parameters) |
|
325 | - { |
|
326 | - if ($constraint instanceof AndInterface) { |
|
327 | - $statementParts['where'][] = '('; |
|
328 | - $this->parseConstraint($constraint->getConstraint1(), $source, $statementParts, $parameters); |
|
329 | - $statementParts['where'][] = ' AND '; |
|
330 | - $this->parseConstraint($constraint->getConstraint2(), $source, $statementParts, $parameters); |
|
331 | - $statementParts['where'][] = ')'; |
|
332 | - } elseif ($constraint instanceof OrInterface) { |
|
333 | - $statementParts['where'][] = '('; |
|
334 | - $this->parseConstraint($constraint->getConstraint1(), $source, $statementParts, $parameters); |
|
335 | - $statementParts['where'][] = ' OR '; |
|
336 | - $this->parseConstraint($constraint->getConstraint2(), $source, $statementParts, $parameters); |
|
337 | - $statementParts['where'][] = ')'; |
|
338 | - } elseif ($constraint instanceof NotInterface) { |
|
339 | - $statementParts['where'][] = 'NOT ('; |
|
340 | - $this->parseConstraint($constraint->getConstraint(), $source, $statementParts, $parameters); |
|
341 | - $statementParts['where'][] = ')'; |
|
342 | - } elseif ($constraint instanceof ComparisonInterface) { |
|
343 | - $this->parseComparison($constraint, $source, $statementParts, $parameters); |
|
344 | - } |
|
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * Parse a Comparison into SQL and parameter arrays. |
|
349 | - * |
|
350 | - * @param ComparisonInterface $comparison The comparison to parse |
|
351 | - * @param SourceInterface $source The source |
|
352 | - * @param array &$statementParts SQL query parts to add to |
|
353 | - * @param array &$parameters Parameters to bind to the SQL |
|
354 | - * @return void |
|
355 | - * @throws Exception\RepositoryException |
|
356 | - */ |
|
357 | - protected function parseComparison(ComparisonInterface $comparison, SourceInterface $source, array &$statementParts, array &$parameters) |
|
358 | - { |
|
359 | - $operand1 = $comparison->getOperand1(); |
|
360 | - $operator = $comparison->getOperator(); |
|
361 | - $operand2 = $comparison->getOperand2(); |
|
362 | - if ($operator === QueryInterface::OPERATOR_IN) { |
|
363 | - $items = []; |
|
364 | - $hasValue = false; |
|
365 | - foreach ($operand2 as $value) { |
|
366 | - $value = $this->getPlainValue($value); |
|
367 | - if ($value !== null) { |
|
368 | - $items[] = $value; |
|
369 | - $hasValue = true; |
|
370 | - } |
|
371 | - } |
|
372 | - if ($hasValue === false) { |
|
373 | - $statementParts['where'][] = '1<>1'; |
|
374 | - } else { |
|
375 | - $this->parseDynamicOperand($operand1, $operator, $source, $statementParts, $parameters, null); |
|
376 | - $parameters[] = $items; |
|
377 | - } |
|
378 | - } elseif ($operator === QueryInterface::OPERATOR_CONTAINS) { |
|
379 | - if ($operand2 === null) { |
|
380 | - $statementParts['where'][] = '1<>1'; |
|
381 | - } else { |
|
382 | - throw new \Exception('Not implemented! Contact extension author.', 1412931227); |
|
383 | - # @todo re-implement me if necessary. |
|
384 | - #$tableName = $this->query->getType(); |
|
385 | - #$propertyName = $operand1->getPropertyName(); |
|
386 | - #while (strpos($propertyName, '.') !== false) { |
|
387 | - # $this->addUnionStatement($tableName, $propertyName, $statementParts); |
|
388 | - #} |
|
389 | - #$columnName = $propertyName; |
|
390 | - #$columnMap = $propertyName; |
|
391 | - #$typeOfRelation = $columnMap instanceof ColumnMap ? $columnMap->getTypeOfRelation() : null; |
|
392 | - #if ($typeOfRelation === ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) { |
|
393 | - # $relationTableName = $columnMap->getRelationTableName(); |
|
394 | - # $statementParts['where'][] = $tableName . '.uid IN (SELECT ' . $columnMap->getParentKeyFieldName() . ' FROM ' . $relationTableName . ' WHERE ' . $columnMap->getChildKeyFieldName() . '=?)'; |
|
395 | - # $parameters[] = intval($this->getPlainValue($operand2)); |
|
396 | - #} elseif ($typeOfRelation === ColumnMap::RELATION_HAS_MANY) { |
|
397 | - # $parentKeyFieldName = $columnMap->getParentKeyFieldName(); |
|
398 | - # if (isset($parentKeyFieldName)) { |
|
399 | - # $childTableName = $columnMap->getChildTableName(); |
|
400 | - # $statementParts['where'][] = $tableName . '.uid=(SELECT ' . $childTableName . '.' . $parentKeyFieldName . ' FROM ' . $childTableName . ' WHERE ' . $childTableName . '.uid=?)'; |
|
401 | - # $parameters[] = intval($this->getPlainValue($operand2)); |
|
402 | - # } else { |
|
403 | - # $statementParts['where'][] = 'FIND_IN_SET(?,' . $tableName . '.' . $columnName . ')'; |
|
404 | - # $parameters[] = intval($this->getPlainValue($operand2)); |
|
405 | - # } |
|
406 | - #} else { |
|
407 | - # throw new Exception\RepositoryException('Unsupported or non-existing property name "' . $propertyName . '" used in relation matching.', 1327065745); |
|
408 | - #} |
|
409 | - } |
|
410 | - } else { |
|
411 | - if ($operand2 === null) { |
|
412 | - if ($operator === QueryInterface::OPERATOR_EQUAL_TO) { |
|
413 | - $operator = self::OPERATOR_EQUAL_TO_NULL; |
|
414 | - } elseif ($operator === QueryInterface::OPERATOR_NOT_EQUAL_TO) { |
|
415 | - $operator = self::OPERATOR_NOT_EQUAL_TO_NULL; |
|
416 | - } |
|
417 | - } |
|
418 | - $this->parseDynamicOperand($operand1, $operator, $source, $statementParts, $parameters); |
|
419 | - $parameters[] = $this->getPlainValue($operand2); |
|
420 | - } |
|
421 | - } |
|
422 | - |
|
423 | - /** |
|
424 | - * Returns a plain value, i.e. objects are flattened if possible. |
|
425 | - * |
|
426 | - * @param mixed $input |
|
427 | - * @return mixed |
|
428 | - * @throws UnexpectedTypeException |
|
429 | - */ |
|
430 | - protected function getPlainValue($input) |
|
431 | - { |
|
432 | - if (is_array($input)) { |
|
433 | - throw new UnexpectedTypeException('An array could not be converted to a plain value.', 1274799932); |
|
434 | - } |
|
435 | - if ($input instanceof \DateTime) { |
|
436 | - return $input->format('U'); |
|
437 | - } elseif (is_object($input)) { |
|
438 | - if ($input instanceof LazyLoadingProxy) { |
|
439 | - $realInput = $input->_loadRealInstance(); |
|
440 | - } else { |
|
441 | - $realInput = $input; |
|
442 | - } |
|
443 | - if ($realInput instanceof DomainObjectInterface) { |
|
444 | - return $realInput->getUid(); |
|
445 | - } else { |
|
446 | - throw new UnexpectedTypeException('An object of class "' . get_class($realInput) . '" could not be converted to a plain value.', 1274799934); |
|
447 | - } |
|
448 | - } elseif (is_bool($input)) { |
|
449 | - return $input === true ? 1 : 0; |
|
450 | - } else { |
|
451 | - return $input; |
|
452 | - } |
|
453 | - } |
|
454 | - |
|
455 | - /** |
|
456 | - * Parse a DynamicOperand into SQL and parameter arrays. |
|
457 | - * |
|
458 | - * @param DynamicOperandInterface $operand |
|
459 | - * @param string $operator One of the JCR_OPERATOR_* constants |
|
460 | - * @param SourceInterface $source The source |
|
461 | - * @param array &$statementParts The query parts |
|
462 | - * @param array &$parameters The parameters that will replace the markers |
|
463 | - * @param string $valueFunction an optional SQL function to apply to the operand value |
|
464 | - * @return void |
|
465 | - */ |
|
466 | - protected function parseDynamicOperand(DynamicOperandInterface $operand, $operator, SourceInterface $source, array &$statementParts, array &$parameters, $valueFunction = null) |
|
467 | - { |
|
468 | - if ($operand instanceof LowerCaseInterface) { |
|
469 | - $this->parseDynamicOperand($operand->getOperand(), $operator, $source, $statementParts, $parameters, 'LOWER'); |
|
470 | - } elseif ($operand instanceof UpperCaseInterface) { |
|
471 | - $this->parseDynamicOperand($operand->getOperand(), $operator, $source, $statementParts, $parameters, 'UPPER'); |
|
472 | - } elseif ($operand instanceof PropertyValueInterface) { |
|
473 | - $propertyName = $operand->getPropertyName(); |
|
474 | - |
|
475 | - // Reset value. |
|
476 | - $this->currentChildTableNameAlias = ''; |
|
477 | - |
|
478 | - if ($source instanceof SelectorInterface) { |
|
479 | - $tableName = $this->query->getType(); |
|
480 | - while (strpos($propertyName, '.') !== false) { |
|
481 | - $this->addUnionStatement($tableName, $propertyName, $statementParts); |
|
482 | - } |
|
483 | - } elseif ($source instanceof JoinInterface) { |
|
484 | - $tableName = $source->getJoinCondition()->getSelector1Name(); |
|
485 | - } |
|
486 | - |
|
487 | - $columnName = $propertyName; |
|
488 | - $resolvedOperator = $this->resolveOperator($operator); |
|
489 | - $constraintSQL = ''; |
|
490 | - |
|
491 | - $marker = $operator === QueryInterface::OPERATOR_IN |
|
492 | - ? '(?)' |
|
493 | - : '?'; |
|
494 | - |
|
495 | - if ($valueFunction === null) { |
|
496 | - $constraintSQL .= (!empty($tableName) ? $tableName . '.' : '') . $columnName . ' ' . $resolvedOperator . ' ' . $marker; |
|
497 | - } else { |
|
498 | - $constraintSQL .= $valueFunction . '(' . (!empty($tableName) ? $tableName . '.' : '') . $columnName . ') ' . $resolvedOperator . ' ' . $marker; |
|
499 | - } |
|
500 | - |
|
501 | - if (isset($tableName) && !empty($this->currentChildTableNameAlias)) { |
|
502 | - $constraintSQL = $this->replaceTableNameByAlias($tableName, $this->currentChildTableNameAlias, $constraintSQL); |
|
503 | - } |
|
504 | - $statementParts['where'][] = $constraintSQL; |
|
505 | - } |
|
506 | - } |
|
507 | - |
|
508 | - /** |
|
509 | - * @param string &$tableName |
|
510 | - * @param string &$propertyPath |
|
511 | - * @param array &$statementParts |
|
512 | - */ |
|
513 | - protected function addUnionStatement(&$tableName, &$propertyPath, array &$statementParts) |
|
514 | - { |
|
515 | - $table = Tca::table($tableName); |
|
516 | - |
|
517 | - $explodedPropertyPath = explode('.', $propertyPath, 2); |
|
518 | - $fieldName = $explodedPropertyPath[0]; |
|
519 | - |
|
520 | - // Field of type "group" are special because property path must contain the table name |
|
521 | - // to determine the relation type. Example for sys_category, property path will look like "items.sys_file" |
|
522 | - $parts = explode('.', $propertyPath, 3); |
|
523 | - if ($table->field($fieldName)->isGroup() && count($parts) > 2) { |
|
524 | - $explodedPropertyPath[0] = $parts[0] . '.' . $parts[1]; |
|
525 | - $explodedPropertyPath[1] = $parts[2]; |
|
526 | - $fieldName = $explodedPropertyPath[0]; |
|
527 | - } |
|
528 | - |
|
529 | - $parentKeyFieldName = $table->field($fieldName)->getForeignField(); |
|
530 | - $childTableName = $table->field($fieldName)->getForeignTable(); |
|
531 | - |
|
532 | - if ($childTableName === null) { |
|
533 | - throw new InvalidRelationConfigurationException('The relation information for property "' . $fieldName . '" of class "' . $tableName . '" is missing.', 1353170925); |
|
534 | - } |
|
535 | - |
|
536 | - if ($table->field($fieldName)->hasOne()) { // includes relation "one-to-one" and "many-to-one" |
|
537 | - // sometimes the opposite relation is not defined. We don't want to force this config for backward compatibility reasons. |
|
538 | - // $parentKeyFieldName === null does the trick somehow. Before condition was if (isset($parentKeyFieldName)) |
|
539 | - if ($table->field($fieldName)->hasRelationManyToOne() || $parentKeyFieldName === null) { |
|
540 | - $statementParts['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.' . $fieldName . '=' . $childTableName . '.uid'; |
|
541 | - } else { |
|
542 | - $statementParts['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.uid=' . $childTableName . '.' . $parentKeyFieldName; |
|
543 | - } |
|
544 | - } elseif ($table->field($fieldName)->hasRelationManyToMany()) { |
|
545 | - $relationTableName = $table->field($fieldName)->getManyToManyTable(); |
|
546 | - |
|
547 | - $parentKeyFieldName = $table->field($fieldName)->isOppositeRelation() ? 'uid_foreign' : 'uid_local'; |
|
548 | - $childKeyFieldName = !$table->field($fieldName)->isOppositeRelation() ? 'uid_foreign' : 'uid_local'; |
|
549 | - |
|
550 | - // MM table e.g sys_category_record_mm |
|
551 | - $relationTableNameAlias = $this->generateAlias($relationTableName); |
|
552 | - $join = sprintf( |
|
553 | - 'LEFT JOIN %s AS %s ON %s.uid=%s.%s', |
|
554 | - $relationTableName, |
|
555 | - $relationTableNameAlias, |
|
556 | - $tableName, |
|
557 | - $relationTableNameAlias, |
|
558 | - $parentKeyFieldName |
|
559 | - ); |
|
560 | - $statementParts['unions'][$relationTableNameAlias] = $join; |
|
561 | - |
|
562 | - // Foreign table e.g sys_category |
|
563 | - $childTableNameAlias = $this->generateAlias($childTableName); |
|
564 | - $this->currentChildTableNameAlias = $childTableNameAlias; |
|
565 | - $join = sprintf( |
|
566 | - 'LEFT JOIN %s AS %s ON %s.%s=%s.uid', |
|
567 | - $childTableName, |
|
568 | - $childTableNameAlias, |
|
569 | - $relationTableNameAlias, |
|
570 | - $childKeyFieldName, |
|
571 | - $childTableNameAlias |
|
572 | - ); |
|
573 | - $statementParts['unions'][$childTableNameAlias] = $join; |
|
574 | - |
|
575 | - // Find a possible table name for a MM condition. |
|
576 | - $tableNameCondition = $table->field($fieldName)->getAdditionalTableNameCondition(); |
|
577 | - if ($tableNameCondition) { |
|
578 | - // If we can find a source file name, we can then retrieve more MM conditions from the TCA such as a field name. |
|
579 | - $sourceFileName = $this->query->getSourceFieldName(); |
|
580 | - if (empty($sourceFileName)) { |
|
581 | - $additionalMMConditions = array( |
|
582 | - 'tablenames' => $tableNameCondition, |
|
583 | - ); |
|
584 | - } else { |
|
585 | - $additionalMMConditions = Tca::table($tableNameCondition)->field($sourceFileName)->getAdditionalMMCondition(); |
|
586 | - } |
|
587 | - |
|
588 | - foreach ($additionalMMConditions as $additionalFieldName => $additionalMMCondition) { |
|
589 | - $additionalJoin = sprintf(' AND %s.%s = "%s"', $relationTableNameAlias, $additionalFieldName, $additionalMMCondition); |
|
590 | - $statementParts['unions'][$relationTableNameAlias] .= $additionalJoin; |
|
591 | - |
|
592 | - $additionalJoin = sprintf(' AND %s.%s = "%s"', $relationTableNameAlias, $additionalFieldName, $additionalMMCondition); |
|
593 | - $statementParts['unions'][$childTableNameAlias] .= $additionalJoin; |
|
594 | - } |
|
595 | - } |
|
596 | - } elseif ($table->field($fieldName)->hasMany()) { // includes relations "many-to-one" and "csv" relations |
|
597 | - $childTableNameAlias = $this->generateAlias($childTableName); |
|
598 | - $this->currentChildTableNameAlias = $childTableNameAlias; |
|
599 | - |
|
600 | - if (isset($parentKeyFieldName)) { |
|
601 | - $join = sprintf( |
|
602 | - 'LEFT JOIN %s AS %s ON %s.uid=%s.%s', |
|
603 | - $childTableName, |
|
604 | - $childTableNameAlias, |
|
605 | - $tableName, |
|
606 | - $childTableNameAlias, |
|
607 | - $parentKeyFieldName |
|
608 | - ); |
|
609 | - $statementParts['unions'][$childTableNameAlias] = $join; |
|
610 | - } else { |
|
611 | - $join = sprintf( |
|
612 | - 'LEFT JOIN %s AS %s ON (FIND_IN_SET(%s.uid, %s.%s))', |
|
613 | - $childTableName, |
|
614 | - $childTableNameAlias, |
|
615 | - $childTableNameAlias, |
|
616 | - $tableName, |
|
617 | - $fieldName |
|
618 | - ); |
|
619 | - $statementParts['unions'][$childTableNameAlias] = $join; |
|
620 | - } |
|
621 | - } else { |
|
622 | - throw new Exception('Could not determine type of relation.', 1252502725); |
|
623 | - } |
|
624 | - |
|
625 | - $statementParts['keywords']['distinct'] = 'DISTINCT'; |
|
626 | - $propertyPath = $explodedPropertyPath[1]; |
|
627 | - $tableName = $childTableName; |
|
628 | - } |
|
629 | - |
|
630 | - /** |
|
631 | - * Returns the SQL operator for the given JCR operator type. |
|
632 | - * |
|
633 | - * @param string $operator One of the JCR_OPERATOR_* constants |
|
634 | - * @return string an SQL operator |
|
635 | - * @throws Exception |
|
636 | - */ |
|
637 | - protected function resolveOperator($operator) |
|
638 | - { |
|
639 | - switch ($operator) { |
|
640 | - case self::OPERATOR_EQUAL_TO_NULL: |
|
641 | - $operator = 'IS'; |
|
642 | - break; |
|
643 | - case self::OPERATOR_NOT_EQUAL_TO_NULL: |
|
644 | - $operator = 'IS NOT'; |
|
645 | - break; |
|
646 | - case QueryInterface::OPERATOR_IN: |
|
647 | - $operator = 'IN'; |
|
648 | - break; |
|
649 | - case QueryInterface::OPERATOR_EQUAL_TO: |
|
650 | - $operator = '='; |
|
651 | - break; |
|
652 | - case QueryInterface::OPERATOR_NOT_EQUAL_TO: |
|
653 | - $operator = '!='; |
|
654 | - break; |
|
655 | - case QueryInterface::OPERATOR_LESS_THAN: |
|
656 | - $operator = '<'; |
|
657 | - break; |
|
658 | - case QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO: |
|
659 | - $operator = '<='; |
|
660 | - break; |
|
661 | - case QueryInterface::OPERATOR_GREATER_THAN: |
|
662 | - $operator = '>'; |
|
663 | - break; |
|
664 | - case QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO: |
|
665 | - $operator = '>='; |
|
666 | - break; |
|
667 | - case QueryInterface::OPERATOR_LIKE: |
|
668 | - $operator = 'LIKE'; |
|
669 | - break; |
|
670 | - default: |
|
671 | - throw new Exception('Unsupported operator encountered.', 1242816073); |
|
672 | - } |
|
673 | - return $operator; |
|
674 | - } |
|
675 | - |
|
676 | - /** |
|
677 | - * Adds additional WHERE statements according to the query settings. |
|
678 | - * |
|
679 | - * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings |
|
680 | - * @param string $tableNameOrAlias The table name to add the additional where clause for |
|
681 | - * @param array &$statementParts |
|
682 | - * @return void |
|
683 | - */ |
|
684 | - protected function addAdditionalWhereClause(QuerySettingsInterface $querySettings, $tableNameOrAlias, &$statementParts) |
|
685 | - { |
|
686 | - $this->addVisibilityConstraintStatement($querySettings, $tableNameOrAlias, $statementParts); |
|
687 | - if ($querySettings->getRespectSysLanguage()) { |
|
688 | - $this->addSysLanguageStatement($tableNameOrAlias, $statementParts, $querySettings); |
|
689 | - } |
|
690 | - } |
|
691 | - |
|
692 | - /** |
|
693 | - * Adds enableFields and deletedClause to the query if necessary |
|
694 | - * |
|
695 | - * @param QuerySettingsInterface $querySettings |
|
696 | - * @param string $tableNameOrAlias The database table name |
|
697 | - * @param array &$statementParts The query parts |
|
698 | - * @return void |
|
699 | - */ |
|
700 | - protected function addVisibilityConstraintStatement(QuerySettingsInterface $querySettings, $tableNameOrAlias, array &$statementParts) |
|
701 | - { |
|
702 | - $statement = ''; |
|
703 | - $tableName = $this->resolveTableNameAlias($tableNameOrAlias); |
|
704 | - if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) { |
|
705 | - $ignoreEnableFields = $querySettings->getIgnoreEnableFields(); |
|
706 | - $enableFieldsToBeIgnored = $querySettings->getEnableFieldsToBeIgnored(); |
|
707 | - $includeDeleted = $querySettings->getIncludeDeleted(); |
|
708 | - if (Typo3Mode::isFrontendMode()) { |
|
709 | - $statement .= $this->getFrontendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $enableFieldsToBeIgnored, $includeDeleted); |
|
710 | - } else { |
|
711 | - // 'BE' case |
|
712 | - $statement .= $this->getBackendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $includeDeleted); |
|
713 | - } |
|
714 | - |
|
715 | - // Remove the prefixing "AND" if any. |
|
716 | - if (!empty($statement)) { |
|
717 | - $statement = strtolower(substr($statement, 1, 3)) === 'and' ? substr($statement, 5) : $statement; |
|
718 | - $statementParts['additionalWhereClause'][$tableNameOrAlias][] = $statement; |
|
719 | - } |
|
720 | - } |
|
721 | - } |
|
722 | - |
|
723 | - /** |
|
724 | - * Returns constraint statement for frontend context |
|
725 | - * |
|
726 | - * @param string $tableNameOrAlias |
|
727 | - * @param boolean $ignoreEnableFields A flag indicating whether the enable fields should be ignored |
|
728 | - * @param array $enableFieldsToBeIgnored If $ignoreEnableFields is true, this array specifies enable fields to be ignored. If it is null or an empty array (default) all enable fields are ignored. |
|
729 | - * @param boolean $includeDeleted A flag indicating whether deleted records should be included |
|
730 | - * @return string |
|
731 | - * @throws Exception\InconsistentQuerySettingsException |
|
732 | - */ |
|
733 | - protected function getFrontendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $enableFieldsToBeIgnored, $includeDeleted) |
|
734 | - { |
|
735 | - $statement = ''; |
|
736 | - $tableName = $this->resolveTableNameAlias($tableNameOrAlias); |
|
737 | - if ($ignoreEnableFields && !$includeDeleted) { |
|
738 | - if (count($enableFieldsToBeIgnored)) { |
|
739 | - // array_combine() is necessary because of the way \TYPO3\CMS\Frontend\Page\PageRepository::enableFields() is implemented |
|
740 | - $statement .= $this->getPageRepository()->enableFields($tableName, -1, array_combine($enableFieldsToBeIgnored, $enableFieldsToBeIgnored)); |
|
741 | - } else { |
|
742 | - $statement .= $this->getPageRepository()->deleteClause($tableName); |
|
743 | - } |
|
744 | - } elseif (!$ignoreEnableFields && !$includeDeleted) { |
|
745 | - $statement .= $this->getPageRepository()->enableFields($tableName); |
|
746 | - } elseif (!$ignoreEnableFields && $includeDeleted) { |
|
747 | - throw new InconsistentQuerySettingsException('Query setting "ignoreEnableFields=false" can not be used together with "includeDeleted=true" in frontend context.', 1327678173); |
|
748 | - } |
|
749 | - return $this->replaceTableNameByAlias($tableName, $tableNameOrAlias, $statement); |
|
750 | - } |
|
751 | - |
|
752 | - /** |
|
753 | - * Returns constraint statement for backend context |
|
754 | - * |
|
755 | - * @param string $tableNameOrAlias |
|
756 | - * @param boolean $ignoreEnableFields A flag indicating whether the enable fields should be ignored |
|
757 | - * @param boolean $includeDeleted A flag indicating whether deleted records should be included |
|
758 | - * @return string |
|
759 | - */ |
|
760 | - protected function getBackendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $includeDeleted) |
|
761 | - { |
|
762 | - $tableName = $this->resolveTableNameAlias($tableNameOrAlias); |
|
763 | - $statement = ''; |
|
764 | - if (!$ignoreEnableFields) { |
|
765 | - $statement .= BackendUtility::BEenableFields($tableName); |
|
766 | - } |
|
767 | - |
|
768 | - // If the table is found to have "workspace" support, add the corresponding fields in the statement. |
|
769 | - if (Tca::table($tableName)->hasWorkspaceSupport()) { |
|
770 | - if ($this->getBackendUser()->workspace === 0) { |
|
771 | - $statement .= ' AND ' . $tableName . '.t3ver_state<=' . new VersionState(VersionState::DEFAULT_STATE); |
|
772 | - } else { |
|
773 | - // Show only records of live and of the current workspace |
|
774 | - // In case we are in a Versioning preview |
|
775 | - $statement .= ' AND (' . |
|
776 | - $tableName . '.t3ver_wsid=0 OR ' . |
|
777 | - $tableName . '.t3ver_wsid=' . (int)$this->getBackendUser()->workspace . |
|
778 | - ')'; |
|
779 | - } |
|
780 | - |
|
781 | - // Check if this segment make sense here or whether it should be in the "if" part when we have workspace = 0 |
|
782 | - $statement .= ' AND ' . $tableName . '.pid<>-1'; |
|
783 | - } |
|
784 | - |
|
785 | - if (!$includeDeleted) { |
|
786 | - $statement .= BackendUtility::deleteClause($tableName); |
|
787 | - } |
|
788 | - |
|
789 | - return $this->replaceTableNameByAlias($tableName, $tableNameOrAlias, $statement); |
|
790 | - } |
|
791 | - |
|
792 | - /** |
|
793 | - * Builds the language field statement |
|
794 | - * |
|
795 | - * @param string $tableNameOrAlias The database table name |
|
796 | - * @param array &$statementParts The query parts |
|
797 | - * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings |
|
798 | - * @return void |
|
799 | - * @throws Exception |
|
800 | - */ |
|
801 | - protected function addSysLanguageStatement($tableNameOrAlias, array &$statementParts, $querySettings) |
|
802 | - { |
|
803 | - $tableName = $this->resolveTableNameAlias($tableNameOrAlias); |
|
804 | - if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) { |
|
805 | - if (!empty($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])) { |
|
806 | - // Select all entries for the current language |
|
807 | - $additionalWhereClause = $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . ' IN (' . intval($querySettings->getLanguageUid()) . ',-1)'; |
|
808 | - // If any language is set -> get those entries which are not translated yet |
|
809 | - // They will be removed by t3lib_page::getRecordOverlay if not matching overlay mode |
|
810 | - if (isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']) |
|
811 | - && $querySettings->getLanguageUid() > 0 |
|
812 | - ) { |
|
813 | - $additionalWhereClause .= ' OR (' . $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=0' . |
|
814 | - ' AND ' . $tableNameOrAlias . '.uid NOT IN (SELECT ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] . |
|
815 | - ' FROM ' . $tableName . |
|
816 | - ' WHERE ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] . '>0' . |
|
817 | - ' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '>0'; |
|
818 | - |
|
819 | - // Add delete clause to ensure all entries are loaded |
|
820 | - if (isset($GLOBALS['TCA'][$tableName]['ctrl']['delete'])) { |
|
821 | - $additionalWhereClause .= ' AND ' . $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['delete'] . '=0'; |
|
822 | - } |
|
823 | - $additionalWhereClause .= '))'; |
|
824 | - } |
|
825 | - $statementParts['additionalWhereClause'][$tableNameOrAlias][] = '(' . $additionalWhereClause . ')'; |
|
826 | - } |
|
827 | - } |
|
828 | - } |
|
829 | - |
|
830 | - /** |
|
831 | - * Transforms orderings into SQL. |
|
832 | - * |
|
833 | - * @param array $orderings An array of orderings (Tx_Extbase_Persistence_QOM_Ordering) |
|
834 | - * @param SourceInterface $source The source |
|
835 | - * @param array &$statementParts The query parts |
|
836 | - * @return void |
|
837 | - * @throws Exception\UnsupportedOrderException |
|
838 | - */ |
|
839 | - protected function parseOrderings(array $orderings, SourceInterface $source, array &$statementParts) |
|
840 | - { |
|
841 | - foreach ($orderings as $fieldNameAndPath => $order) { |
|
842 | - switch ($order) { |
|
843 | - case QueryInterface::ORDER_ASCENDING: |
|
844 | - $order = 'ASC'; |
|
845 | - break; |
|
846 | - case QueryInterface::ORDER_DESCENDING: |
|
847 | - $order = 'DESC'; |
|
848 | - break; |
|
849 | - default: |
|
850 | - throw new UnsupportedOrderException('Unsupported order encountered.', 1456845126); |
|
851 | - } |
|
852 | - |
|
853 | - $tableName = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->query->getType()); |
|
854 | - $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $tableName); |
|
855 | - $statementParts['orderings'][] = sprintf('%s.%s %s', $tableName, $fieldName, $order); |
|
856 | - } |
|
857 | - } |
|
858 | - |
|
859 | - /** |
|
860 | - * Transforms limit and offset into SQL |
|
861 | - * |
|
862 | - * @param int $limit |
|
863 | - * @param int $offset |
|
864 | - * @param array &$statementParts |
|
865 | - * @return void |
|
866 | - */ |
|
867 | - protected function parseLimitAndOffset($limit, $offset, array &$statementParts) |
|
868 | - { |
|
869 | - if ($limit !== null && $offset !== null) { |
|
870 | - $statementParts['limit'] = intval($offset) . ', ' . intval($limit); |
|
871 | - } elseif ($limit !== null) { |
|
872 | - $statementParts['limit'] = intval($limit); |
|
873 | - } |
|
874 | - } |
|
875 | - |
|
876 | - /** |
|
877 | - * @param array $rows |
|
878 | - * @return array |
|
879 | - */ |
|
880 | - protected function getContentObjects(array $rows): array |
|
881 | - { |
|
882 | - $contentObjects = []; |
|
883 | - foreach ($rows as $row) { |
|
884 | - // Get language uid from querySettings. |
|
885 | - // Ensure the backend handling is not broken (fallback to Get parameter 'L' if needed) |
|
886 | - $overlaidRow = $this->doLanguageAndWorkspaceOverlay( |
|
887 | - $row, |
|
888 | - $this->query->getTypo3QuerySettings() |
|
889 | - ); |
|
890 | - |
|
891 | - $contentObjects[] = GeneralUtility::makeInstance( |
|
892 | - Content::class, |
|
893 | - $this->query->getType(), |
|
894 | - $overlaidRow |
|
895 | - ); |
|
896 | - } |
|
897 | - |
|
898 | - return $contentObjects; |
|
899 | - } |
|
900 | - |
|
901 | - /** |
|
902 | - * Performs workspace and language overlay on the given row array. The language and workspace id is automatically |
|
903 | - * detected (depending on FE or BE context). You can also explicitly set the language/workspace id. |
|
904 | - * |
|
905 | - * @param array $row |
|
906 | - * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings |
|
907 | - * @return array |
|
908 | - */ |
|
909 | - protected function doLanguageAndWorkspaceOverlay(array $row, $querySettings) |
|
910 | - { |
|
911 | - $tableName = $this->getTableName(); |
|
912 | - |
|
913 | - $pageRepository = $this->getPageRepository(); |
|
914 | - if (is_object($GLOBALS['TSFE'])) { |
|
915 | - $languageMode = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('language', 'legacyLanguageMode'); |
|
916 | - #if ($this->isBackendUserLogged() && $this->getBackendUser()->workspace !== 0) { |
|
917 | - # $pageRepository->versioningWorkspaceId = $this->getBackendUser()->workspace; |
|
918 | - #} |
|
919 | - } else { |
|
920 | - $languageMode = ''; |
|
921 | - $workspaceUid = $this->getBackendUser()->workspace; |
|
922 | - #$pageRepository->versioningWorkspaceId = $workspaceUid; |
|
923 | - #if ($this->getBackendUser()->workspace !== 0) { |
|
924 | - # $pageRepository->versioningPreview = 1; |
|
925 | - #} |
|
926 | - } |
|
927 | - |
|
928 | - // If current row is a translation select its parent |
|
929 | - if (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) |
|
930 | - && isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']) |
|
931 | - ) { |
|
932 | - if (isset($row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']]) |
|
933 | - && $row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] > 0 |
|
934 | - ) { |
|
935 | - $queryBuilder = $this->getQueryBuilder(); |
|
936 | - $row = $queryBuilder |
|
937 | - ->select($tableName . '.*') |
|
938 | - ->from($tableName) |
|
939 | - ->andWhere( |
|
940 | - $tableName . '.uid=' . (int)$row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']], |
|
941 | - $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . ' = 0' |
|
942 | - ) |
|
943 | - ->execute() |
|
944 | - ->fetch(); |
|
945 | - } |
|
946 | - } |
|
947 | - |
|
948 | - // Retrieve the original uid; Used for Workspaces! |
|
949 | - if (Typo3Mode::isBackendMode()) { |
|
950 | - $pageRepository->versionOL($tableName, $row, true, true); |
|
951 | - } else { |
|
952 | - \TYPO3\CMS\Backend\Utility\BackendUtility::workspaceOL($tableName, $row); |
|
953 | - } |
|
954 | - if (isset($row['_ORIG_uid'])) { |
|
955 | - $row['uid'] = $row['_ORIG_uid']; |
|
956 | - } |
|
957 | - |
|
958 | - // Special case for table "pages" |
|
959 | - if ($tableName == 'pages') { |
|
960 | - $row = $pageRepository->getPageOverlay($row, $querySettings->getLanguageUid()); |
|
961 | - } elseif (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) |
|
962 | - && $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== '' |
|
963 | - ) { |
|
964 | - if (in_array($row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']], array(-1, 0))) { |
|
965 | - $overlayMode = $languageMode === 'strict' ? 'hideNonTranslated' : ''; |
|
966 | - $row = $pageRepository->getRecordOverlay($tableName, $row, $querySettings->getLanguageUid(), $overlayMode); |
|
967 | - } |
|
968 | - } |
|
969 | - |
|
970 | - return $row; |
|
971 | - } |
|
972 | - |
|
973 | - /** |
|
974 | - * Return a resolved table name given a possible table name alias. |
|
975 | - * |
|
976 | - * @param string $tableNameOrAlias |
|
977 | - * @return string |
|
978 | - */ |
|
979 | - protected function resolveTableNameAlias($tableNameOrAlias) |
|
980 | - { |
|
981 | - $resolvedTableName = $tableNameOrAlias; |
|
982 | - if (!empty($this->tableNameAliases['aliases'][$tableNameOrAlias])) { |
|
983 | - $resolvedTableName = $this->tableNameAliases['aliases'][$tableNameOrAlias]; |
|
984 | - } |
|
985 | - return $resolvedTableName; |
|
986 | - } |
|
987 | - |
|
988 | - /** |
|
989 | - * Generate a unique table name alias for the given table name. |
|
990 | - * |
|
991 | - * @param string $tableName |
|
992 | - * @return string |
|
993 | - */ |
|
994 | - protected function generateAlias($tableName) |
|
995 | - { |
|
996 | - if (!isset($this->tableNameAliases['aliasIncrement'][$tableName])) { |
|
997 | - $this->tableNameAliases['aliasIncrement'][$tableName] = 0; |
|
998 | - } |
|
999 | - |
|
1000 | - $numberOfAliases = $this->tableNameAliases['aliasIncrement'][$tableName]; |
|
1001 | - $tableNameAlias = $tableName . $numberOfAliases; |
|
1002 | - |
|
1003 | - $this->tableNameAliases['aliasIncrement'][$tableName]++; |
|
1004 | - $this->tableNameAliases['aliases'][$tableNameAlias] = $tableName; |
|
1005 | - |
|
1006 | - return $tableNameAlias; |
|
1007 | - } |
|
1008 | - |
|
1009 | - /** |
|
1010 | - * Replace the table names by its table name alias within the given statement. |
|
1011 | - * |
|
1012 | - * @param string $tableName |
|
1013 | - * @param string $tableNameAlias |
|
1014 | - * @param string $statement |
|
1015 | - * @return string |
|
1016 | - */ |
|
1017 | - protected function replaceTableNameByAlias($tableName, $tableNameAlias, $statement) |
|
1018 | - { |
|
1019 | - if ($statement && $tableName !== $tableNameAlias) { |
|
1020 | - $statement = str_replace($tableName, $tableNameAlias, $statement); |
|
1021 | - } |
|
1022 | - return $statement; |
|
1023 | - } |
|
1024 | - |
|
1025 | - /** |
|
1026 | - * Returns an instance of the current Backend User. |
|
1027 | - * |
|
1028 | - * @return BackendUserAuthentication |
|
1029 | - */ |
|
1030 | - protected function getBackendUser() |
|
1031 | - { |
|
1032 | - return $GLOBALS['BE_USER']; |
|
1033 | - } |
|
1034 | - |
|
1035 | - /** |
|
1036 | - * Tell whether a Backend User is logged in. |
|
1037 | - * |
|
1038 | - * @return bool |
|
1039 | - */ |
|
1040 | - protected function isBackendUserLogged() |
|
1041 | - { |
|
1042 | - return is_object($GLOBALS['BE_USER']); |
|
1043 | - } |
|
1044 | - |
|
1045 | - /** |
|
1046 | - * @return PageRepository|object |
|
1047 | - */ |
|
1048 | - protected function getPageRepository() |
|
1049 | - { |
|
1050 | - if (!$this->pageRepository instanceof PageRepository) { |
|
1051 | - if (Typo3Mode::isFrontendMode() && is_object($GLOBALS['TSFE'])) { |
|
1052 | - $this->pageRepository = $GLOBALS['TSFE']->sys_page; |
|
1053 | - } else { |
|
1054 | - $this->pageRepository = GeneralUtility::makeInstance(PageRepository::class); |
|
1055 | - } |
|
1056 | - } |
|
1057 | - |
|
1058 | - return $this->pageRepository; |
|
1059 | - } |
|
1060 | - |
|
1061 | - /** |
|
1062 | - * @return FieldPathResolver|object |
|
1063 | - */ |
|
1064 | - protected function getFieldPathResolver() |
|
1065 | - { |
|
1066 | - return GeneralUtility::makeInstance(FieldPathResolver::class); |
|
1067 | - } |
|
1068 | - |
|
1069 | - /** |
|
1070 | - * @return object|Connection |
|
1071 | - */ |
|
1072 | - protected function getConnection(): Connection |
|
1073 | - { |
|
1074 | - /** @var ConnectionPool $connectionPool */ |
|
1075 | - return GeneralUtility::makeInstance(ConnectionPool::class) |
|
1076 | - ->getConnectionForTable($this->getTableName()); |
|
1077 | - } |
|
1078 | - |
|
1079 | - /** |
|
1080 | - * @return object|QueryBuilder |
|
1081 | - */ |
|
1082 | - protected function getQueryBuilder(): QueryBuilder |
|
1083 | - { |
|
1084 | - /** @var ConnectionPool $connectionPool */ |
|
1085 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
1086 | - return $connectionPool->getQueryBuilderForTable($this->getTableName()); |
|
1087 | - } |
|
1088 | - |
|
1089 | - /** |
|
1090 | - * @return string |
|
1091 | - */ |
|
1092 | - public function getTableName(): string |
|
1093 | - { |
|
1094 | - return $this->query->getSource()->getNodeTypeName(); // getSelectorName() |
|
1095 | - } |
|
56 | + public const OPERATOR_EQUAL_TO_NULL = 'operatorEqualToNull'; |
|
57 | + public const OPERATOR_NOT_EQUAL_TO_NULL = 'operatorNotEqualToNull'; |
|
58 | + |
|
59 | + /** |
|
60 | + * The TYPO3 page repository. Used for language and workspace overlay |
|
61 | + * |
|
62 | + * @var PageRepository |
|
63 | + */ |
|
64 | + protected $pageRepository; |
|
65 | + |
|
66 | + /** |
|
67 | + * @var Query |
|
68 | + */ |
|
69 | + protected $query; |
|
70 | + |
|
71 | + /** |
|
72 | + * Store some info related to table name and its aliases. |
|
73 | + * |
|
74 | + * @var array |
|
75 | + */ |
|
76 | + protected $tableNameAliases = array( |
|
77 | + 'aliases' => [], |
|
78 | + 'aliasIncrement' => [], |
|
79 | + ); |
|
80 | + |
|
81 | + /** |
|
82 | + * Use to store the current foreign table name alias. |
|
83 | + * |
|
84 | + * @var string |
|
85 | + */ |
|
86 | + protected $currentChildTableNameAlias = ''; |
|
87 | + |
|
88 | + /** |
|
89 | + * @param Query $query |
|
90 | + */ |
|
91 | + public function __construct(Query $query) |
|
92 | + { |
|
93 | + $this->query = $query; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * @param $parameters |
|
98 | + * @return array |
|
99 | + */ |
|
100 | + protected static function getTypes($parameters) |
|
101 | + { |
|
102 | + $types = []; |
|
103 | + foreach ($parameters as $parameter) { |
|
104 | + if (is_array($parameter)) { |
|
105 | + if (MathUtility::canBeInterpretedAsInteger($parameter[0])) { |
|
106 | + $types[] = \Doctrine\DBAL\Connection::PARAM_INT_ARRAY; |
|
107 | + } else { |
|
108 | + $types[] = \Doctrine\DBAL\Connection::PARAM_STR_ARRAY; |
|
109 | + } |
|
110 | + } else { |
|
111 | + if (MathUtility::canBeInterpretedAsInteger($parameter)) { |
|
112 | + $types[] = ParameterType::INTEGER; |
|
113 | + } else { |
|
114 | + $types[] = ParameterType::STRING; |
|
115 | + } |
|
116 | + } |
|
117 | + } |
|
118 | + return $types; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Returns the result of the query |
|
123 | + */ |
|
124 | + public function fetchResult() |
|
125 | + { |
|
126 | + $parameters = []; |
|
127 | + $statementParts = $this->parseQuery($parameters); |
|
128 | + $statementParts = $this->processStatementStructureForRecursiveMMRelation($statementParts); |
|
129 | + $sql = $this->buildQuery($statementParts); |
|
130 | + //print $sql; exit(); |
|
131 | + |
|
132 | + $rows = $this->getConnection() |
|
133 | + ->executeQuery($sql, $parameters, self::getTypes($parameters)) |
|
134 | + ->fetchAllAssociative(); |
|
135 | + |
|
136 | + return $this->getContentObjects($rows); |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Returns the number of tuples matching the query. |
|
141 | + * |
|
142 | + * @return int The number of matching tuples |
|
143 | + */ |
|
144 | + public function countResult() |
|
145 | + { |
|
146 | + $parameters = []; |
|
147 | + $statementParts = $this->parseQuery($parameters); |
|
148 | + $statementParts = $this->processStatementStructureForRecursiveMMRelation($statementParts); |
|
149 | + $types = self::getTypes($parameters); |
|
150 | + |
|
151 | + // if limit is set, we need to count the rows "manually" as COUNT(*) ignores LIMIT constraints |
|
152 | + if (!empty($statementParts['limit'])) { |
|
153 | + $sql = $this->buildQuery($statementParts); |
|
154 | + |
|
155 | + $count = $this |
|
156 | + ->getConnection() |
|
157 | + ->executeQuery($sql, $parameters, $types) |
|
158 | + ->rowCount(); |
|
159 | + } else { |
|
160 | + $statementParts['fields'] = array('COUNT(*)'); |
|
161 | + // having orderings without grouping is not compatible with non-MySQL DBMS |
|
162 | + $statementParts['orderings'] = []; |
|
163 | + if (isset($statementParts['keywords']['distinct'])) { |
|
164 | + unset($statementParts['keywords']['distinct']); |
|
165 | + $distinctField = $this->query->getDistinct() ? $this->query->getDistinct() : 'uid'; |
|
166 | + $statementParts['fields'] = array('COUNT(DISTINCT ' . $statementParts['mainTable'] . '.' . $distinctField . ')'); |
|
167 | + } |
|
168 | + |
|
169 | + $sql = $this->buildQuery($statementParts); |
|
170 | + $count = $this |
|
171 | + ->getConnection() |
|
172 | + ->executeQuery($sql, $parameters, $types) |
|
173 | + ->fetchColumn(0); |
|
174 | + } |
|
175 | + return (int)$count; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Parses the query and returns the SQL statement parts. |
|
180 | + * |
|
181 | + * @param array &$parameters |
|
182 | + * @return array |
|
183 | + */ |
|
184 | + public function parseQuery(array &$parameters) |
|
185 | + { |
|
186 | + $statementParts = []; |
|
187 | + $statementParts['keywords'] = []; |
|
188 | + $statementParts['tables'] = []; |
|
189 | + $statementParts['unions'] = []; |
|
190 | + $statementParts['fields'] = []; |
|
191 | + $statementParts['where'] = []; |
|
192 | + $statementParts['additionalWhereClause'] = []; |
|
193 | + $statementParts['orderings'] = []; |
|
194 | + $statementParts['limit'] = []; |
|
195 | + $query = $this->query; |
|
196 | + $source = $query->getSource(); |
|
197 | + $this->parseSource($source, $statementParts); |
|
198 | + $this->parseConstraint($query->getConstraint(), $source, $statementParts, $parameters); |
|
199 | + $this->parseOrderings($query->getOrderings(), $source, $statementParts); |
|
200 | + $this->parseLimitAndOffset($query->getLimit(), $query->getOffset(), $statementParts); |
|
201 | + $tableNames = array_unique(array_keys($statementParts['tables'] + $statementParts['unions'])); |
|
202 | + foreach ($tableNames as $tableNameOrAlias) { |
|
203 | + if (is_string($tableNameOrAlias) && strlen($tableNameOrAlias) > 0) { |
|
204 | + $this->addAdditionalWhereClause($query->getTypo3QuerySettings(), $tableNameOrAlias, $statementParts); |
|
205 | + } |
|
206 | + } |
|
207 | + |
|
208 | + return $statementParts; |
|
209 | + } |
|
210 | + |
|
211 | + /** |
|
212 | + * Fiddle with the statement structure to handle recursive MM relations. |
|
213 | + * For the recursive MM query to work, we must invert some values. |
|
214 | + * Let see if that is the best way of doing that... |
|
215 | + * |
|
216 | + * @param array $statementParts |
|
217 | + * @return array |
|
218 | + */ |
|
219 | + public function processStatementStructureForRecursiveMMRelation(array $statementParts) |
|
220 | + { |
|
221 | + if ($this->hasRecursiveMMRelation()) { |
|
222 | + $tableName = $this->query->getType(); |
|
223 | + |
|
224 | + // In order the MM query to work for a recursive MM query, we must invert some values. |
|
225 | + // tx_domain_model_foo0 (the alias) <--> tx_domain_model_foo (the origin table name) |
|
226 | + $values = []; |
|
227 | + foreach ($statementParts['fields'] as $key => $value) { |
|
228 | + $values[$key] = str_replace($tableName, $tableName . '0', $value); |
|
229 | + } |
|
230 | + $statementParts['fields'] = $values; |
|
231 | + |
|
232 | + // Same comment as above. |
|
233 | + $values = []; |
|
234 | + foreach ($statementParts['where'] as $key => $value) { |
|
235 | + $values[$key] = str_replace($tableName . '0', $tableName, $value); |
|
236 | + } |
|
237 | + $statementParts['where'] = $values; |
|
238 | + |
|
239 | + // We must be more restrictive by transforming the "left" union by "inner" |
|
240 | + $values = []; |
|
241 | + foreach ($statementParts['unions'] as $key => $value) { |
|
242 | + $values[$key] = str_replace('LEFT JOIN', 'INNER JOIN', $value); |
|
243 | + } |
|
244 | + $statementParts['unions'] = $values; |
|
245 | + } |
|
246 | + |
|
247 | + return $statementParts; |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Tell whether there is a recursive MM relation. |
|
252 | + * |
|
253 | + * @return bool |
|
254 | + */ |
|
255 | + public function hasRecursiveMMRelation() |
|
256 | + { |
|
257 | + return isset($this->tableNameAliases['aliasIncrement'][$this->query->getType()]); |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * Returns the statement, ready to be executed. |
|
262 | + * |
|
263 | + * @param array $statementParts The SQL statement parts |
|
264 | + * @return string The SQL statement |
|
265 | + */ |
|
266 | + public function buildQuery(array $statementParts) |
|
267 | + { |
|
268 | + // Add more statement to the UNION part. |
|
269 | + if (!empty($statementParts['unions'])) { |
|
270 | + foreach ($statementParts['unions'] as $tableName => $unionPart) { |
|
271 | + if (!empty($statementParts['additionalWhereClause'][$tableName])) { |
|
272 | + $statementParts['unions'][$tableName] .= ' AND ' . implode(' AND ', $statementParts['additionalWhereClause'][$tableName]); |
|
273 | + } |
|
274 | + } |
|
275 | + } |
|
276 | + |
|
277 | + $statement = 'SELECT ' . implode(' ', $statementParts['keywords']) . ' ' . implode(',', $statementParts['fields']) . ' FROM ' . implode(' ', $statementParts['tables']) . ' ' . implode(' ', $statementParts['unions']); |
|
278 | + if (!empty($statementParts['where'])) { |
|
279 | + $statement .= ' WHERE ' . implode('', $statementParts['where']); |
|
280 | + if (!empty($statementParts['additionalWhereClause'][$this->query->getType()])) { |
|
281 | + $statement .= ' AND ' . implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]); |
|
282 | + } |
|
283 | + } elseif (!empty($statementParts['additionalWhereClause'])) { |
|
284 | + $statement .= ' WHERE ' . implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]); |
|
285 | + } |
|
286 | + if (!empty($statementParts['orderings'])) { |
|
287 | + $statement .= ' ORDER BY ' . implode(', ', $statementParts['orderings']); |
|
288 | + } |
|
289 | + if (!empty($statementParts['limit'])) { |
|
290 | + $statement .= ' LIMIT ' . $statementParts['limit']; |
|
291 | + } |
|
292 | + |
|
293 | + return $statement; |
|
294 | + } |
|
295 | + |
|
296 | + /** |
|
297 | + * Transforms a Query Source into SQL and parameter arrays |
|
298 | + * |
|
299 | + * @param SourceInterface $source The source |
|
300 | + * @param array &$sql |
|
301 | + * @return void |
|
302 | + */ |
|
303 | + protected function parseSource(SourceInterface $source, array &$sql) |
|
304 | + { |
|
305 | + $tableName = $this->getTableName(); |
|
306 | + $sql['fields'][$tableName] = $tableName . '.*'; |
|
307 | + if ($this->query->getDistinct()) { |
|
308 | + $sql['fields'][$tableName] = $tableName . '.' . $this->query->getDistinct(); |
|
309 | + $sql['keywords']['distinct'] = 'DISTINCT'; |
|
310 | + } |
|
311 | + $sql['tables'][$tableName] = $tableName; |
|
312 | + $sql['mainTable'] = $tableName; |
|
313 | + } |
|
314 | + |
|
315 | + /** |
|
316 | + * Transforms a constraint into SQL and parameter arrays |
|
317 | + * |
|
318 | + * @param ConstraintInterface $constraint The constraint |
|
319 | + * @param SourceInterface $source The source |
|
320 | + * @param array &$statementParts The query parts |
|
321 | + * @param array &$parameters The parameters that will replace the markers |
|
322 | + * @return void |
|
323 | + */ |
|
324 | + protected function parseConstraint(ConstraintInterface $constraint = null, SourceInterface $source, array &$statementParts, array &$parameters) |
|
325 | + { |
|
326 | + if ($constraint instanceof AndInterface) { |
|
327 | + $statementParts['where'][] = '('; |
|
328 | + $this->parseConstraint($constraint->getConstraint1(), $source, $statementParts, $parameters); |
|
329 | + $statementParts['where'][] = ' AND '; |
|
330 | + $this->parseConstraint($constraint->getConstraint2(), $source, $statementParts, $parameters); |
|
331 | + $statementParts['where'][] = ')'; |
|
332 | + } elseif ($constraint instanceof OrInterface) { |
|
333 | + $statementParts['where'][] = '('; |
|
334 | + $this->parseConstraint($constraint->getConstraint1(), $source, $statementParts, $parameters); |
|
335 | + $statementParts['where'][] = ' OR '; |
|
336 | + $this->parseConstraint($constraint->getConstraint2(), $source, $statementParts, $parameters); |
|
337 | + $statementParts['where'][] = ')'; |
|
338 | + } elseif ($constraint instanceof NotInterface) { |
|
339 | + $statementParts['where'][] = 'NOT ('; |
|
340 | + $this->parseConstraint($constraint->getConstraint(), $source, $statementParts, $parameters); |
|
341 | + $statementParts['where'][] = ')'; |
|
342 | + } elseif ($constraint instanceof ComparisonInterface) { |
|
343 | + $this->parseComparison($constraint, $source, $statementParts, $parameters); |
|
344 | + } |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * Parse a Comparison into SQL and parameter arrays. |
|
349 | + * |
|
350 | + * @param ComparisonInterface $comparison The comparison to parse |
|
351 | + * @param SourceInterface $source The source |
|
352 | + * @param array &$statementParts SQL query parts to add to |
|
353 | + * @param array &$parameters Parameters to bind to the SQL |
|
354 | + * @return void |
|
355 | + * @throws Exception\RepositoryException |
|
356 | + */ |
|
357 | + protected function parseComparison(ComparisonInterface $comparison, SourceInterface $source, array &$statementParts, array &$parameters) |
|
358 | + { |
|
359 | + $operand1 = $comparison->getOperand1(); |
|
360 | + $operator = $comparison->getOperator(); |
|
361 | + $operand2 = $comparison->getOperand2(); |
|
362 | + if ($operator === QueryInterface::OPERATOR_IN) { |
|
363 | + $items = []; |
|
364 | + $hasValue = false; |
|
365 | + foreach ($operand2 as $value) { |
|
366 | + $value = $this->getPlainValue($value); |
|
367 | + if ($value !== null) { |
|
368 | + $items[] = $value; |
|
369 | + $hasValue = true; |
|
370 | + } |
|
371 | + } |
|
372 | + if ($hasValue === false) { |
|
373 | + $statementParts['where'][] = '1<>1'; |
|
374 | + } else { |
|
375 | + $this->parseDynamicOperand($operand1, $operator, $source, $statementParts, $parameters, null); |
|
376 | + $parameters[] = $items; |
|
377 | + } |
|
378 | + } elseif ($operator === QueryInterface::OPERATOR_CONTAINS) { |
|
379 | + if ($operand2 === null) { |
|
380 | + $statementParts['where'][] = '1<>1'; |
|
381 | + } else { |
|
382 | + throw new \Exception('Not implemented! Contact extension author.', 1412931227); |
|
383 | + # @todo re-implement me if necessary. |
|
384 | + #$tableName = $this->query->getType(); |
|
385 | + #$propertyName = $operand1->getPropertyName(); |
|
386 | + #while (strpos($propertyName, '.') !== false) { |
|
387 | + # $this->addUnionStatement($tableName, $propertyName, $statementParts); |
|
388 | + #} |
|
389 | + #$columnName = $propertyName; |
|
390 | + #$columnMap = $propertyName; |
|
391 | + #$typeOfRelation = $columnMap instanceof ColumnMap ? $columnMap->getTypeOfRelation() : null; |
|
392 | + #if ($typeOfRelation === ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) { |
|
393 | + # $relationTableName = $columnMap->getRelationTableName(); |
|
394 | + # $statementParts['where'][] = $tableName . '.uid IN (SELECT ' . $columnMap->getParentKeyFieldName() . ' FROM ' . $relationTableName . ' WHERE ' . $columnMap->getChildKeyFieldName() . '=?)'; |
|
395 | + # $parameters[] = intval($this->getPlainValue($operand2)); |
|
396 | + #} elseif ($typeOfRelation === ColumnMap::RELATION_HAS_MANY) { |
|
397 | + # $parentKeyFieldName = $columnMap->getParentKeyFieldName(); |
|
398 | + # if (isset($parentKeyFieldName)) { |
|
399 | + # $childTableName = $columnMap->getChildTableName(); |
|
400 | + # $statementParts['where'][] = $tableName . '.uid=(SELECT ' . $childTableName . '.' . $parentKeyFieldName . ' FROM ' . $childTableName . ' WHERE ' . $childTableName . '.uid=?)'; |
|
401 | + # $parameters[] = intval($this->getPlainValue($operand2)); |
|
402 | + # } else { |
|
403 | + # $statementParts['where'][] = 'FIND_IN_SET(?,' . $tableName . '.' . $columnName . ')'; |
|
404 | + # $parameters[] = intval($this->getPlainValue($operand2)); |
|
405 | + # } |
|
406 | + #} else { |
|
407 | + # throw new Exception\RepositoryException('Unsupported or non-existing property name "' . $propertyName . '" used in relation matching.', 1327065745); |
|
408 | + #} |
|
409 | + } |
|
410 | + } else { |
|
411 | + if ($operand2 === null) { |
|
412 | + if ($operator === QueryInterface::OPERATOR_EQUAL_TO) { |
|
413 | + $operator = self::OPERATOR_EQUAL_TO_NULL; |
|
414 | + } elseif ($operator === QueryInterface::OPERATOR_NOT_EQUAL_TO) { |
|
415 | + $operator = self::OPERATOR_NOT_EQUAL_TO_NULL; |
|
416 | + } |
|
417 | + } |
|
418 | + $this->parseDynamicOperand($operand1, $operator, $source, $statementParts, $parameters); |
|
419 | + $parameters[] = $this->getPlainValue($operand2); |
|
420 | + } |
|
421 | + } |
|
422 | + |
|
423 | + /** |
|
424 | + * Returns a plain value, i.e. objects are flattened if possible. |
|
425 | + * |
|
426 | + * @param mixed $input |
|
427 | + * @return mixed |
|
428 | + * @throws UnexpectedTypeException |
|
429 | + */ |
|
430 | + protected function getPlainValue($input) |
|
431 | + { |
|
432 | + if (is_array($input)) { |
|
433 | + throw new UnexpectedTypeException('An array could not be converted to a plain value.', 1274799932); |
|
434 | + } |
|
435 | + if ($input instanceof \DateTime) { |
|
436 | + return $input->format('U'); |
|
437 | + } elseif (is_object($input)) { |
|
438 | + if ($input instanceof LazyLoadingProxy) { |
|
439 | + $realInput = $input->_loadRealInstance(); |
|
440 | + } else { |
|
441 | + $realInput = $input; |
|
442 | + } |
|
443 | + if ($realInput instanceof DomainObjectInterface) { |
|
444 | + return $realInput->getUid(); |
|
445 | + } else { |
|
446 | + throw new UnexpectedTypeException('An object of class "' . get_class($realInput) . '" could not be converted to a plain value.', 1274799934); |
|
447 | + } |
|
448 | + } elseif (is_bool($input)) { |
|
449 | + return $input === true ? 1 : 0; |
|
450 | + } else { |
|
451 | + return $input; |
|
452 | + } |
|
453 | + } |
|
454 | + |
|
455 | + /** |
|
456 | + * Parse a DynamicOperand into SQL and parameter arrays. |
|
457 | + * |
|
458 | + * @param DynamicOperandInterface $operand |
|
459 | + * @param string $operator One of the JCR_OPERATOR_* constants |
|
460 | + * @param SourceInterface $source The source |
|
461 | + * @param array &$statementParts The query parts |
|
462 | + * @param array &$parameters The parameters that will replace the markers |
|
463 | + * @param string $valueFunction an optional SQL function to apply to the operand value |
|
464 | + * @return void |
|
465 | + */ |
|
466 | + protected function parseDynamicOperand(DynamicOperandInterface $operand, $operator, SourceInterface $source, array &$statementParts, array &$parameters, $valueFunction = null) |
|
467 | + { |
|
468 | + if ($operand instanceof LowerCaseInterface) { |
|
469 | + $this->parseDynamicOperand($operand->getOperand(), $operator, $source, $statementParts, $parameters, 'LOWER'); |
|
470 | + } elseif ($operand instanceof UpperCaseInterface) { |
|
471 | + $this->parseDynamicOperand($operand->getOperand(), $operator, $source, $statementParts, $parameters, 'UPPER'); |
|
472 | + } elseif ($operand instanceof PropertyValueInterface) { |
|
473 | + $propertyName = $operand->getPropertyName(); |
|
474 | + |
|
475 | + // Reset value. |
|
476 | + $this->currentChildTableNameAlias = ''; |
|
477 | + |
|
478 | + if ($source instanceof SelectorInterface) { |
|
479 | + $tableName = $this->query->getType(); |
|
480 | + while (strpos($propertyName, '.') !== false) { |
|
481 | + $this->addUnionStatement($tableName, $propertyName, $statementParts); |
|
482 | + } |
|
483 | + } elseif ($source instanceof JoinInterface) { |
|
484 | + $tableName = $source->getJoinCondition()->getSelector1Name(); |
|
485 | + } |
|
486 | + |
|
487 | + $columnName = $propertyName; |
|
488 | + $resolvedOperator = $this->resolveOperator($operator); |
|
489 | + $constraintSQL = ''; |
|
490 | + |
|
491 | + $marker = $operator === QueryInterface::OPERATOR_IN |
|
492 | + ? '(?)' |
|
493 | + : '?'; |
|
494 | + |
|
495 | + if ($valueFunction === null) { |
|
496 | + $constraintSQL .= (!empty($tableName) ? $tableName . '.' : '') . $columnName . ' ' . $resolvedOperator . ' ' . $marker; |
|
497 | + } else { |
|
498 | + $constraintSQL .= $valueFunction . '(' . (!empty($tableName) ? $tableName . '.' : '') . $columnName . ') ' . $resolvedOperator . ' ' . $marker; |
|
499 | + } |
|
500 | + |
|
501 | + if (isset($tableName) && !empty($this->currentChildTableNameAlias)) { |
|
502 | + $constraintSQL = $this->replaceTableNameByAlias($tableName, $this->currentChildTableNameAlias, $constraintSQL); |
|
503 | + } |
|
504 | + $statementParts['where'][] = $constraintSQL; |
|
505 | + } |
|
506 | + } |
|
507 | + |
|
508 | + /** |
|
509 | + * @param string &$tableName |
|
510 | + * @param string &$propertyPath |
|
511 | + * @param array &$statementParts |
|
512 | + */ |
|
513 | + protected function addUnionStatement(&$tableName, &$propertyPath, array &$statementParts) |
|
514 | + { |
|
515 | + $table = Tca::table($tableName); |
|
516 | + |
|
517 | + $explodedPropertyPath = explode('.', $propertyPath, 2); |
|
518 | + $fieldName = $explodedPropertyPath[0]; |
|
519 | + |
|
520 | + // Field of type "group" are special because property path must contain the table name |
|
521 | + // to determine the relation type. Example for sys_category, property path will look like "items.sys_file" |
|
522 | + $parts = explode('.', $propertyPath, 3); |
|
523 | + if ($table->field($fieldName)->isGroup() && count($parts) > 2) { |
|
524 | + $explodedPropertyPath[0] = $parts[0] . '.' . $parts[1]; |
|
525 | + $explodedPropertyPath[1] = $parts[2]; |
|
526 | + $fieldName = $explodedPropertyPath[0]; |
|
527 | + } |
|
528 | + |
|
529 | + $parentKeyFieldName = $table->field($fieldName)->getForeignField(); |
|
530 | + $childTableName = $table->field($fieldName)->getForeignTable(); |
|
531 | + |
|
532 | + if ($childTableName === null) { |
|
533 | + throw new InvalidRelationConfigurationException('The relation information for property "' . $fieldName . '" of class "' . $tableName . '" is missing.', 1353170925); |
|
534 | + } |
|
535 | + |
|
536 | + if ($table->field($fieldName)->hasOne()) { // includes relation "one-to-one" and "many-to-one" |
|
537 | + // sometimes the opposite relation is not defined. We don't want to force this config for backward compatibility reasons. |
|
538 | + // $parentKeyFieldName === null does the trick somehow. Before condition was if (isset($parentKeyFieldName)) |
|
539 | + if ($table->field($fieldName)->hasRelationManyToOne() || $parentKeyFieldName === null) { |
|
540 | + $statementParts['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.' . $fieldName . '=' . $childTableName . '.uid'; |
|
541 | + } else { |
|
542 | + $statementParts['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.uid=' . $childTableName . '.' . $parentKeyFieldName; |
|
543 | + } |
|
544 | + } elseif ($table->field($fieldName)->hasRelationManyToMany()) { |
|
545 | + $relationTableName = $table->field($fieldName)->getManyToManyTable(); |
|
546 | + |
|
547 | + $parentKeyFieldName = $table->field($fieldName)->isOppositeRelation() ? 'uid_foreign' : 'uid_local'; |
|
548 | + $childKeyFieldName = !$table->field($fieldName)->isOppositeRelation() ? 'uid_foreign' : 'uid_local'; |
|
549 | + |
|
550 | + // MM table e.g sys_category_record_mm |
|
551 | + $relationTableNameAlias = $this->generateAlias($relationTableName); |
|
552 | + $join = sprintf( |
|
553 | + 'LEFT JOIN %s AS %s ON %s.uid=%s.%s', |
|
554 | + $relationTableName, |
|
555 | + $relationTableNameAlias, |
|
556 | + $tableName, |
|
557 | + $relationTableNameAlias, |
|
558 | + $parentKeyFieldName |
|
559 | + ); |
|
560 | + $statementParts['unions'][$relationTableNameAlias] = $join; |
|
561 | + |
|
562 | + // Foreign table e.g sys_category |
|
563 | + $childTableNameAlias = $this->generateAlias($childTableName); |
|
564 | + $this->currentChildTableNameAlias = $childTableNameAlias; |
|
565 | + $join = sprintf( |
|
566 | + 'LEFT JOIN %s AS %s ON %s.%s=%s.uid', |
|
567 | + $childTableName, |
|
568 | + $childTableNameAlias, |
|
569 | + $relationTableNameAlias, |
|
570 | + $childKeyFieldName, |
|
571 | + $childTableNameAlias |
|
572 | + ); |
|
573 | + $statementParts['unions'][$childTableNameAlias] = $join; |
|
574 | + |
|
575 | + // Find a possible table name for a MM condition. |
|
576 | + $tableNameCondition = $table->field($fieldName)->getAdditionalTableNameCondition(); |
|
577 | + if ($tableNameCondition) { |
|
578 | + // If we can find a source file name, we can then retrieve more MM conditions from the TCA such as a field name. |
|
579 | + $sourceFileName = $this->query->getSourceFieldName(); |
|
580 | + if (empty($sourceFileName)) { |
|
581 | + $additionalMMConditions = array( |
|
582 | + 'tablenames' => $tableNameCondition, |
|
583 | + ); |
|
584 | + } else { |
|
585 | + $additionalMMConditions = Tca::table($tableNameCondition)->field($sourceFileName)->getAdditionalMMCondition(); |
|
586 | + } |
|
587 | + |
|
588 | + foreach ($additionalMMConditions as $additionalFieldName => $additionalMMCondition) { |
|
589 | + $additionalJoin = sprintf(' AND %s.%s = "%s"', $relationTableNameAlias, $additionalFieldName, $additionalMMCondition); |
|
590 | + $statementParts['unions'][$relationTableNameAlias] .= $additionalJoin; |
|
591 | + |
|
592 | + $additionalJoin = sprintf(' AND %s.%s = "%s"', $relationTableNameAlias, $additionalFieldName, $additionalMMCondition); |
|
593 | + $statementParts['unions'][$childTableNameAlias] .= $additionalJoin; |
|
594 | + } |
|
595 | + } |
|
596 | + } elseif ($table->field($fieldName)->hasMany()) { // includes relations "many-to-one" and "csv" relations |
|
597 | + $childTableNameAlias = $this->generateAlias($childTableName); |
|
598 | + $this->currentChildTableNameAlias = $childTableNameAlias; |
|
599 | + |
|
600 | + if (isset($parentKeyFieldName)) { |
|
601 | + $join = sprintf( |
|
602 | + 'LEFT JOIN %s AS %s ON %s.uid=%s.%s', |
|
603 | + $childTableName, |
|
604 | + $childTableNameAlias, |
|
605 | + $tableName, |
|
606 | + $childTableNameAlias, |
|
607 | + $parentKeyFieldName |
|
608 | + ); |
|
609 | + $statementParts['unions'][$childTableNameAlias] = $join; |
|
610 | + } else { |
|
611 | + $join = sprintf( |
|
612 | + 'LEFT JOIN %s AS %s ON (FIND_IN_SET(%s.uid, %s.%s))', |
|
613 | + $childTableName, |
|
614 | + $childTableNameAlias, |
|
615 | + $childTableNameAlias, |
|
616 | + $tableName, |
|
617 | + $fieldName |
|
618 | + ); |
|
619 | + $statementParts['unions'][$childTableNameAlias] = $join; |
|
620 | + } |
|
621 | + } else { |
|
622 | + throw new Exception('Could not determine type of relation.', 1252502725); |
|
623 | + } |
|
624 | + |
|
625 | + $statementParts['keywords']['distinct'] = 'DISTINCT'; |
|
626 | + $propertyPath = $explodedPropertyPath[1]; |
|
627 | + $tableName = $childTableName; |
|
628 | + } |
|
629 | + |
|
630 | + /** |
|
631 | + * Returns the SQL operator for the given JCR operator type. |
|
632 | + * |
|
633 | + * @param string $operator One of the JCR_OPERATOR_* constants |
|
634 | + * @return string an SQL operator |
|
635 | + * @throws Exception |
|
636 | + */ |
|
637 | + protected function resolveOperator($operator) |
|
638 | + { |
|
639 | + switch ($operator) { |
|
640 | + case self::OPERATOR_EQUAL_TO_NULL: |
|
641 | + $operator = 'IS'; |
|
642 | + break; |
|
643 | + case self::OPERATOR_NOT_EQUAL_TO_NULL: |
|
644 | + $operator = 'IS NOT'; |
|
645 | + break; |
|
646 | + case QueryInterface::OPERATOR_IN: |
|
647 | + $operator = 'IN'; |
|
648 | + break; |
|
649 | + case QueryInterface::OPERATOR_EQUAL_TO: |
|
650 | + $operator = '='; |
|
651 | + break; |
|
652 | + case QueryInterface::OPERATOR_NOT_EQUAL_TO: |
|
653 | + $operator = '!='; |
|
654 | + break; |
|
655 | + case QueryInterface::OPERATOR_LESS_THAN: |
|
656 | + $operator = '<'; |
|
657 | + break; |
|
658 | + case QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO: |
|
659 | + $operator = '<='; |
|
660 | + break; |
|
661 | + case QueryInterface::OPERATOR_GREATER_THAN: |
|
662 | + $operator = '>'; |
|
663 | + break; |
|
664 | + case QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO: |
|
665 | + $operator = '>='; |
|
666 | + break; |
|
667 | + case QueryInterface::OPERATOR_LIKE: |
|
668 | + $operator = 'LIKE'; |
|
669 | + break; |
|
670 | + default: |
|
671 | + throw new Exception('Unsupported operator encountered.', 1242816073); |
|
672 | + } |
|
673 | + return $operator; |
|
674 | + } |
|
675 | + |
|
676 | + /** |
|
677 | + * Adds additional WHERE statements according to the query settings. |
|
678 | + * |
|
679 | + * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings |
|
680 | + * @param string $tableNameOrAlias The table name to add the additional where clause for |
|
681 | + * @param array &$statementParts |
|
682 | + * @return void |
|
683 | + */ |
|
684 | + protected function addAdditionalWhereClause(QuerySettingsInterface $querySettings, $tableNameOrAlias, &$statementParts) |
|
685 | + { |
|
686 | + $this->addVisibilityConstraintStatement($querySettings, $tableNameOrAlias, $statementParts); |
|
687 | + if ($querySettings->getRespectSysLanguage()) { |
|
688 | + $this->addSysLanguageStatement($tableNameOrAlias, $statementParts, $querySettings); |
|
689 | + } |
|
690 | + } |
|
691 | + |
|
692 | + /** |
|
693 | + * Adds enableFields and deletedClause to the query if necessary |
|
694 | + * |
|
695 | + * @param QuerySettingsInterface $querySettings |
|
696 | + * @param string $tableNameOrAlias The database table name |
|
697 | + * @param array &$statementParts The query parts |
|
698 | + * @return void |
|
699 | + */ |
|
700 | + protected function addVisibilityConstraintStatement(QuerySettingsInterface $querySettings, $tableNameOrAlias, array &$statementParts) |
|
701 | + { |
|
702 | + $statement = ''; |
|
703 | + $tableName = $this->resolveTableNameAlias($tableNameOrAlias); |
|
704 | + if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) { |
|
705 | + $ignoreEnableFields = $querySettings->getIgnoreEnableFields(); |
|
706 | + $enableFieldsToBeIgnored = $querySettings->getEnableFieldsToBeIgnored(); |
|
707 | + $includeDeleted = $querySettings->getIncludeDeleted(); |
|
708 | + if (Typo3Mode::isFrontendMode()) { |
|
709 | + $statement .= $this->getFrontendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $enableFieldsToBeIgnored, $includeDeleted); |
|
710 | + } else { |
|
711 | + // 'BE' case |
|
712 | + $statement .= $this->getBackendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $includeDeleted); |
|
713 | + } |
|
714 | + |
|
715 | + // Remove the prefixing "AND" if any. |
|
716 | + if (!empty($statement)) { |
|
717 | + $statement = strtolower(substr($statement, 1, 3)) === 'and' ? substr($statement, 5) : $statement; |
|
718 | + $statementParts['additionalWhereClause'][$tableNameOrAlias][] = $statement; |
|
719 | + } |
|
720 | + } |
|
721 | + } |
|
722 | + |
|
723 | + /** |
|
724 | + * Returns constraint statement for frontend context |
|
725 | + * |
|
726 | + * @param string $tableNameOrAlias |
|
727 | + * @param boolean $ignoreEnableFields A flag indicating whether the enable fields should be ignored |
|
728 | + * @param array $enableFieldsToBeIgnored If $ignoreEnableFields is true, this array specifies enable fields to be ignored. If it is null or an empty array (default) all enable fields are ignored. |
|
729 | + * @param boolean $includeDeleted A flag indicating whether deleted records should be included |
|
730 | + * @return string |
|
731 | + * @throws Exception\InconsistentQuerySettingsException |
|
732 | + */ |
|
733 | + protected function getFrontendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $enableFieldsToBeIgnored, $includeDeleted) |
|
734 | + { |
|
735 | + $statement = ''; |
|
736 | + $tableName = $this->resolveTableNameAlias($tableNameOrAlias); |
|
737 | + if ($ignoreEnableFields && !$includeDeleted) { |
|
738 | + if (count($enableFieldsToBeIgnored)) { |
|
739 | + // array_combine() is necessary because of the way \TYPO3\CMS\Frontend\Page\PageRepository::enableFields() is implemented |
|
740 | + $statement .= $this->getPageRepository()->enableFields($tableName, -1, array_combine($enableFieldsToBeIgnored, $enableFieldsToBeIgnored)); |
|
741 | + } else { |
|
742 | + $statement .= $this->getPageRepository()->deleteClause($tableName); |
|
743 | + } |
|
744 | + } elseif (!$ignoreEnableFields && !$includeDeleted) { |
|
745 | + $statement .= $this->getPageRepository()->enableFields($tableName); |
|
746 | + } elseif (!$ignoreEnableFields && $includeDeleted) { |
|
747 | + throw new InconsistentQuerySettingsException('Query setting "ignoreEnableFields=false" can not be used together with "includeDeleted=true" in frontend context.', 1327678173); |
|
748 | + } |
|
749 | + return $this->replaceTableNameByAlias($tableName, $tableNameOrAlias, $statement); |
|
750 | + } |
|
751 | + |
|
752 | + /** |
|
753 | + * Returns constraint statement for backend context |
|
754 | + * |
|
755 | + * @param string $tableNameOrAlias |
|
756 | + * @param boolean $ignoreEnableFields A flag indicating whether the enable fields should be ignored |
|
757 | + * @param boolean $includeDeleted A flag indicating whether deleted records should be included |
|
758 | + * @return string |
|
759 | + */ |
|
760 | + protected function getBackendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $includeDeleted) |
|
761 | + { |
|
762 | + $tableName = $this->resolveTableNameAlias($tableNameOrAlias); |
|
763 | + $statement = ''; |
|
764 | + if (!$ignoreEnableFields) { |
|
765 | + $statement .= BackendUtility::BEenableFields($tableName); |
|
766 | + } |
|
767 | + |
|
768 | + // If the table is found to have "workspace" support, add the corresponding fields in the statement. |
|
769 | + if (Tca::table($tableName)->hasWorkspaceSupport()) { |
|
770 | + if ($this->getBackendUser()->workspace === 0) { |
|
771 | + $statement .= ' AND ' . $tableName . '.t3ver_state<=' . new VersionState(VersionState::DEFAULT_STATE); |
|
772 | + } else { |
|
773 | + // Show only records of live and of the current workspace |
|
774 | + // In case we are in a Versioning preview |
|
775 | + $statement .= ' AND (' . |
|
776 | + $tableName . '.t3ver_wsid=0 OR ' . |
|
777 | + $tableName . '.t3ver_wsid=' . (int)$this->getBackendUser()->workspace . |
|
778 | + ')'; |
|
779 | + } |
|
780 | + |
|
781 | + // Check if this segment make sense here or whether it should be in the "if" part when we have workspace = 0 |
|
782 | + $statement .= ' AND ' . $tableName . '.pid<>-1'; |
|
783 | + } |
|
784 | + |
|
785 | + if (!$includeDeleted) { |
|
786 | + $statement .= BackendUtility::deleteClause($tableName); |
|
787 | + } |
|
788 | + |
|
789 | + return $this->replaceTableNameByAlias($tableName, $tableNameOrAlias, $statement); |
|
790 | + } |
|
791 | + |
|
792 | + /** |
|
793 | + * Builds the language field statement |
|
794 | + * |
|
795 | + * @param string $tableNameOrAlias The database table name |
|
796 | + * @param array &$statementParts The query parts |
|
797 | + * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings |
|
798 | + * @return void |
|
799 | + * @throws Exception |
|
800 | + */ |
|
801 | + protected function addSysLanguageStatement($tableNameOrAlias, array &$statementParts, $querySettings) |
|
802 | + { |
|
803 | + $tableName = $this->resolveTableNameAlias($tableNameOrAlias); |
|
804 | + if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) { |
|
805 | + if (!empty($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])) { |
|
806 | + // Select all entries for the current language |
|
807 | + $additionalWhereClause = $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . ' IN (' . intval($querySettings->getLanguageUid()) . ',-1)'; |
|
808 | + // If any language is set -> get those entries which are not translated yet |
|
809 | + // They will be removed by t3lib_page::getRecordOverlay if not matching overlay mode |
|
810 | + if (isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']) |
|
811 | + && $querySettings->getLanguageUid() > 0 |
|
812 | + ) { |
|
813 | + $additionalWhereClause .= ' OR (' . $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=0' . |
|
814 | + ' AND ' . $tableNameOrAlias . '.uid NOT IN (SELECT ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] . |
|
815 | + ' FROM ' . $tableName . |
|
816 | + ' WHERE ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] . '>0' . |
|
817 | + ' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '>0'; |
|
818 | + |
|
819 | + // Add delete clause to ensure all entries are loaded |
|
820 | + if (isset($GLOBALS['TCA'][$tableName]['ctrl']['delete'])) { |
|
821 | + $additionalWhereClause .= ' AND ' . $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['delete'] . '=0'; |
|
822 | + } |
|
823 | + $additionalWhereClause .= '))'; |
|
824 | + } |
|
825 | + $statementParts['additionalWhereClause'][$tableNameOrAlias][] = '(' . $additionalWhereClause . ')'; |
|
826 | + } |
|
827 | + } |
|
828 | + } |
|
829 | + |
|
830 | + /** |
|
831 | + * Transforms orderings into SQL. |
|
832 | + * |
|
833 | + * @param array $orderings An array of orderings (Tx_Extbase_Persistence_QOM_Ordering) |
|
834 | + * @param SourceInterface $source The source |
|
835 | + * @param array &$statementParts The query parts |
|
836 | + * @return void |
|
837 | + * @throws Exception\UnsupportedOrderException |
|
838 | + */ |
|
839 | + protected function parseOrderings(array $orderings, SourceInterface $source, array &$statementParts) |
|
840 | + { |
|
841 | + foreach ($orderings as $fieldNameAndPath => $order) { |
|
842 | + switch ($order) { |
|
843 | + case QueryInterface::ORDER_ASCENDING: |
|
844 | + $order = 'ASC'; |
|
845 | + break; |
|
846 | + case QueryInterface::ORDER_DESCENDING: |
|
847 | + $order = 'DESC'; |
|
848 | + break; |
|
849 | + default: |
|
850 | + throw new UnsupportedOrderException('Unsupported order encountered.', 1456845126); |
|
851 | + } |
|
852 | + |
|
853 | + $tableName = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->query->getType()); |
|
854 | + $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $tableName); |
|
855 | + $statementParts['orderings'][] = sprintf('%s.%s %s', $tableName, $fieldName, $order); |
|
856 | + } |
|
857 | + } |
|
858 | + |
|
859 | + /** |
|
860 | + * Transforms limit and offset into SQL |
|
861 | + * |
|
862 | + * @param int $limit |
|
863 | + * @param int $offset |
|
864 | + * @param array &$statementParts |
|
865 | + * @return void |
|
866 | + */ |
|
867 | + protected function parseLimitAndOffset($limit, $offset, array &$statementParts) |
|
868 | + { |
|
869 | + if ($limit !== null && $offset !== null) { |
|
870 | + $statementParts['limit'] = intval($offset) . ', ' . intval($limit); |
|
871 | + } elseif ($limit !== null) { |
|
872 | + $statementParts['limit'] = intval($limit); |
|
873 | + } |
|
874 | + } |
|
875 | + |
|
876 | + /** |
|
877 | + * @param array $rows |
|
878 | + * @return array |
|
879 | + */ |
|
880 | + protected function getContentObjects(array $rows): array |
|
881 | + { |
|
882 | + $contentObjects = []; |
|
883 | + foreach ($rows as $row) { |
|
884 | + // Get language uid from querySettings. |
|
885 | + // Ensure the backend handling is not broken (fallback to Get parameter 'L' if needed) |
|
886 | + $overlaidRow = $this->doLanguageAndWorkspaceOverlay( |
|
887 | + $row, |
|
888 | + $this->query->getTypo3QuerySettings() |
|
889 | + ); |
|
890 | + |
|
891 | + $contentObjects[] = GeneralUtility::makeInstance( |
|
892 | + Content::class, |
|
893 | + $this->query->getType(), |
|
894 | + $overlaidRow |
|
895 | + ); |
|
896 | + } |
|
897 | + |
|
898 | + return $contentObjects; |
|
899 | + } |
|
900 | + |
|
901 | + /** |
|
902 | + * Performs workspace and language overlay on the given row array. The language and workspace id is automatically |
|
903 | + * detected (depending on FE or BE context). You can also explicitly set the language/workspace id. |
|
904 | + * |
|
905 | + * @param array $row |
|
906 | + * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings |
|
907 | + * @return array |
|
908 | + */ |
|
909 | + protected function doLanguageAndWorkspaceOverlay(array $row, $querySettings) |
|
910 | + { |
|
911 | + $tableName = $this->getTableName(); |
|
912 | + |
|
913 | + $pageRepository = $this->getPageRepository(); |
|
914 | + if (is_object($GLOBALS['TSFE'])) { |
|
915 | + $languageMode = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('language', 'legacyLanguageMode'); |
|
916 | + #if ($this->isBackendUserLogged() && $this->getBackendUser()->workspace !== 0) { |
|
917 | + # $pageRepository->versioningWorkspaceId = $this->getBackendUser()->workspace; |
|
918 | + #} |
|
919 | + } else { |
|
920 | + $languageMode = ''; |
|
921 | + $workspaceUid = $this->getBackendUser()->workspace; |
|
922 | + #$pageRepository->versioningWorkspaceId = $workspaceUid; |
|
923 | + #if ($this->getBackendUser()->workspace !== 0) { |
|
924 | + # $pageRepository->versioningPreview = 1; |
|
925 | + #} |
|
926 | + } |
|
927 | + |
|
928 | + // If current row is a translation select its parent |
|
929 | + if (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) |
|
930 | + && isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']) |
|
931 | + ) { |
|
932 | + if (isset($row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']]) |
|
933 | + && $row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] > 0 |
|
934 | + ) { |
|
935 | + $queryBuilder = $this->getQueryBuilder(); |
|
936 | + $row = $queryBuilder |
|
937 | + ->select($tableName . '.*') |
|
938 | + ->from($tableName) |
|
939 | + ->andWhere( |
|
940 | + $tableName . '.uid=' . (int)$row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']], |
|
941 | + $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . ' = 0' |
|
942 | + ) |
|
943 | + ->execute() |
|
944 | + ->fetch(); |
|
945 | + } |
|
946 | + } |
|
947 | + |
|
948 | + // Retrieve the original uid; Used for Workspaces! |
|
949 | + if (Typo3Mode::isBackendMode()) { |
|
950 | + $pageRepository->versionOL($tableName, $row, true, true); |
|
951 | + } else { |
|
952 | + \TYPO3\CMS\Backend\Utility\BackendUtility::workspaceOL($tableName, $row); |
|
953 | + } |
|
954 | + if (isset($row['_ORIG_uid'])) { |
|
955 | + $row['uid'] = $row['_ORIG_uid']; |
|
956 | + } |
|
957 | + |
|
958 | + // Special case for table "pages" |
|
959 | + if ($tableName == 'pages') { |
|
960 | + $row = $pageRepository->getPageOverlay($row, $querySettings->getLanguageUid()); |
|
961 | + } elseif (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) |
|
962 | + && $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== '' |
|
963 | + ) { |
|
964 | + if (in_array($row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']], array(-1, 0))) { |
|
965 | + $overlayMode = $languageMode === 'strict' ? 'hideNonTranslated' : ''; |
|
966 | + $row = $pageRepository->getRecordOverlay($tableName, $row, $querySettings->getLanguageUid(), $overlayMode); |
|
967 | + } |
|
968 | + } |
|
969 | + |
|
970 | + return $row; |
|
971 | + } |
|
972 | + |
|
973 | + /** |
|
974 | + * Return a resolved table name given a possible table name alias. |
|
975 | + * |
|
976 | + * @param string $tableNameOrAlias |
|
977 | + * @return string |
|
978 | + */ |
|
979 | + protected function resolveTableNameAlias($tableNameOrAlias) |
|
980 | + { |
|
981 | + $resolvedTableName = $tableNameOrAlias; |
|
982 | + if (!empty($this->tableNameAliases['aliases'][$tableNameOrAlias])) { |
|
983 | + $resolvedTableName = $this->tableNameAliases['aliases'][$tableNameOrAlias]; |
|
984 | + } |
|
985 | + return $resolvedTableName; |
|
986 | + } |
|
987 | + |
|
988 | + /** |
|
989 | + * Generate a unique table name alias for the given table name. |
|
990 | + * |
|
991 | + * @param string $tableName |
|
992 | + * @return string |
|
993 | + */ |
|
994 | + protected function generateAlias($tableName) |
|
995 | + { |
|
996 | + if (!isset($this->tableNameAliases['aliasIncrement'][$tableName])) { |
|
997 | + $this->tableNameAliases['aliasIncrement'][$tableName] = 0; |
|
998 | + } |
|
999 | + |
|
1000 | + $numberOfAliases = $this->tableNameAliases['aliasIncrement'][$tableName]; |
|
1001 | + $tableNameAlias = $tableName . $numberOfAliases; |
|
1002 | + |
|
1003 | + $this->tableNameAliases['aliasIncrement'][$tableName]++; |
|
1004 | + $this->tableNameAliases['aliases'][$tableNameAlias] = $tableName; |
|
1005 | + |
|
1006 | + return $tableNameAlias; |
|
1007 | + } |
|
1008 | + |
|
1009 | + /** |
|
1010 | + * Replace the table names by its table name alias within the given statement. |
|
1011 | + * |
|
1012 | + * @param string $tableName |
|
1013 | + * @param string $tableNameAlias |
|
1014 | + * @param string $statement |
|
1015 | + * @return string |
|
1016 | + */ |
|
1017 | + protected function replaceTableNameByAlias($tableName, $tableNameAlias, $statement) |
|
1018 | + { |
|
1019 | + if ($statement && $tableName !== $tableNameAlias) { |
|
1020 | + $statement = str_replace($tableName, $tableNameAlias, $statement); |
|
1021 | + } |
|
1022 | + return $statement; |
|
1023 | + } |
|
1024 | + |
|
1025 | + /** |
|
1026 | + * Returns an instance of the current Backend User. |
|
1027 | + * |
|
1028 | + * @return BackendUserAuthentication |
|
1029 | + */ |
|
1030 | + protected function getBackendUser() |
|
1031 | + { |
|
1032 | + return $GLOBALS['BE_USER']; |
|
1033 | + } |
|
1034 | + |
|
1035 | + /** |
|
1036 | + * Tell whether a Backend User is logged in. |
|
1037 | + * |
|
1038 | + * @return bool |
|
1039 | + */ |
|
1040 | + protected function isBackendUserLogged() |
|
1041 | + { |
|
1042 | + return is_object($GLOBALS['BE_USER']); |
|
1043 | + } |
|
1044 | + |
|
1045 | + /** |
|
1046 | + * @return PageRepository|object |
|
1047 | + */ |
|
1048 | + protected function getPageRepository() |
|
1049 | + { |
|
1050 | + if (!$this->pageRepository instanceof PageRepository) { |
|
1051 | + if (Typo3Mode::isFrontendMode() && is_object($GLOBALS['TSFE'])) { |
|
1052 | + $this->pageRepository = $GLOBALS['TSFE']->sys_page; |
|
1053 | + } else { |
|
1054 | + $this->pageRepository = GeneralUtility::makeInstance(PageRepository::class); |
|
1055 | + } |
|
1056 | + } |
|
1057 | + |
|
1058 | + return $this->pageRepository; |
|
1059 | + } |
|
1060 | + |
|
1061 | + /** |
|
1062 | + * @return FieldPathResolver|object |
|
1063 | + */ |
|
1064 | + protected function getFieldPathResolver() |
|
1065 | + { |
|
1066 | + return GeneralUtility::makeInstance(FieldPathResolver::class); |
|
1067 | + } |
|
1068 | + |
|
1069 | + /** |
|
1070 | + * @return object|Connection |
|
1071 | + */ |
|
1072 | + protected function getConnection(): Connection |
|
1073 | + { |
|
1074 | + /** @var ConnectionPool $connectionPool */ |
|
1075 | + return GeneralUtility::makeInstance(ConnectionPool::class) |
|
1076 | + ->getConnectionForTable($this->getTableName()); |
|
1077 | + } |
|
1078 | + |
|
1079 | + /** |
|
1080 | + * @return object|QueryBuilder |
|
1081 | + */ |
|
1082 | + protected function getQueryBuilder(): QueryBuilder |
|
1083 | + { |
|
1084 | + /** @var ConnectionPool $connectionPool */ |
|
1085 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
1086 | + return $connectionPool->getQueryBuilderForTable($this->getTableName()); |
|
1087 | + } |
|
1088 | + |
|
1089 | + /** |
|
1090 | + * @return string |
|
1091 | + */ |
|
1092 | + public function getTableName(): string |
|
1093 | + { |
|
1094 | + return $this->query->getSource()->getNodeTypeName(); // getSelectorName() |
|
1095 | + } |
|
1096 | 1096 | } |
@@ -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 | } |
@@ -42,621 +42,621 @@ |
||
42 | 42 | */ |
43 | 43 | class Query implements QueryInterface |
44 | 44 | { |
45 | - /** |
|
46 | - * An inner join. |
|
47 | - */ |
|
48 | - public const JCR_JOIN_TYPE_INNER = '{http://www.jcp.org/jcr/1.0}joinTypeInner'; |
|
49 | - |
|
50 | - /** |
|
51 | - * A left-outer join. |
|
52 | - */ |
|
53 | - public const JCR_JOIN_TYPE_LEFT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeLeftOuter'; |
|
54 | - |
|
55 | - /** |
|
56 | - * A right-outer join. |
|
57 | - */ |
|
58 | - public const JCR_JOIN_TYPE_RIGHT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeRightOuter'; |
|
59 | - |
|
60 | - /** |
|
61 | - * Charset of strings in QOM |
|
62 | - */ |
|
63 | - public const CHARSET = 'utf-8'; |
|
64 | - |
|
65 | - /** |
|
66 | - * @var string |
|
67 | - */ |
|
68 | - protected $sourceFieldName; |
|
69 | - |
|
70 | - /** |
|
71 | - * @var string |
|
72 | - */ |
|
73 | - protected $type; |
|
74 | - |
|
75 | - /** |
|
76 | - * @var PersistenceManagerInterface |
|
77 | - */ |
|
78 | - protected $persistenceManager; |
|
79 | - |
|
80 | - /** |
|
81 | - * @var QueryObjectModelFactory |
|
82 | - */ |
|
83 | - protected $qomFactory; |
|
84 | - |
|
85 | - /** |
|
86 | - * @var SourceInterface |
|
87 | - */ |
|
88 | - protected $source; |
|
89 | - |
|
90 | - /** |
|
91 | - * @var ConstraintInterface |
|
92 | - */ |
|
93 | - protected $constraint; |
|
94 | - |
|
95 | - /** |
|
96 | - * @var Statement |
|
97 | - */ |
|
98 | - protected $statement; |
|
99 | - |
|
100 | - /** |
|
101 | - * @var array |
|
102 | - */ |
|
103 | - protected $orderings = []; |
|
104 | - |
|
105 | - /** |
|
106 | - * @var int |
|
107 | - */ |
|
108 | - protected $limit; |
|
109 | - |
|
110 | - /** |
|
111 | - * @var int |
|
112 | - */ |
|
113 | - protected $offset; |
|
114 | - |
|
115 | - /** |
|
116 | - * Apply DISTINCT upon property. |
|
117 | - * |
|
118 | - * @var string |
|
119 | - */ |
|
120 | - protected $distinct; |
|
121 | - |
|
122 | - /** |
|
123 | - * The query settings. |
|
124 | - * |
|
125 | - * @var Typo3QuerySettings |
|
126 | - */ |
|
127 | - public Typo3QuerySettings $typo3QuerySettings; |
|
128 | - |
|
129 | - /** |
|
130 | - * Constructs a query object working on the given class name |
|
131 | - * |
|
132 | - * @param string $type |
|
133 | - */ |
|
134 | - public function __construct($type) |
|
135 | - { |
|
136 | - $this->type = $type; |
|
137 | - $this->persistenceManager = GeneralUtility::makeInstance(PersistenceManagerInterface::class); |
|
138 | - $this->qomFactory = GeneralUtility::makeInstance(QueryObjectModelFactory::class); |
|
139 | - } |
|
140 | - |
|
141 | - public function injectTypo3QuerySettings(Typo3QuerySettings $querySettings): void |
|
142 | - { |
|
143 | - $this->typo3QuerySettings = $querySettings; |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * Sets the Query Settings. These Query settings must match the settings expected by |
|
148 | - * the specific Storage Backend. |
|
149 | - * |
|
150 | - * @param QuerySettingsInterface $typo3QuerySettings The Query Settings |
|
151 | - * @return void |
|
152 | - */ |
|
153 | - public function setTypo3QuerySettings(QuerySettingsInterface $typo3QuerySettings) |
|
154 | - { |
|
155 | - $this->typo3QuerySettings = $typo3QuerySettings; |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * Returns the Query Settings. |
|
160 | - * |
|
161 | - * @throws \Exception |
|
162 | - * @return Typo3QuerySettings $querySettings The Query Settings |
|
163 | - * @api This method is not part of FLOW3 API |
|
164 | - */ |
|
165 | - public function getTypo3QuerySettings() |
|
166 | - { |
|
167 | - if (!$this->typo3QuerySettings instanceof QuerySettingsInterface) { |
|
168 | - throw new Exception('Tried to get the query settings without setting them before.', 1248689115); |
|
169 | - } |
|
170 | - |
|
171 | - // Apply possible settings to the query. |
|
172 | - if ($this->isBackendMode()) { |
|
173 | - /** @var BackendConfigurationManager $backendConfigurationManager */ |
|
174 | - $backendConfigurationManager = GeneralUtility::makeInstance(BackendConfigurationManager::class); |
|
175 | - $configuration = $backendConfigurationManager->getTypoScriptSetup(); |
|
176 | - $querySettings = array('respectSysLanguage'); |
|
177 | - foreach ($querySettings as $setting) { |
|
178 | - if (isset($configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting])) { |
|
179 | - $value = (bool)$configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting]; |
|
180 | - ObjectAccess::setProperty($this->typo3QuerySettings, $setting, $value); |
|
181 | - } |
|
182 | - } |
|
183 | - } |
|
184 | - |
|
185 | - return $this->typo3QuerySettings; |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Returns the type this query cares for. |
|
190 | - * |
|
191 | - * @return string |
|
192 | - * @api |
|
193 | - */ |
|
194 | - public function getType() |
|
195 | - { |
|
196 | - return $this->type; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Sets the source to fetch the result from |
|
201 | - * |
|
202 | - * @param SourceInterface $source |
|
203 | - */ |
|
204 | - public function setSource(SourceInterface $source) |
|
205 | - { |
|
206 | - $this->source = $source; |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * Returns the selectorn name or an empty string, if the source is not a selector |
|
211 | - * TODO This has to be checked at another place |
|
212 | - * |
|
213 | - * @return string The selector name |
|
214 | - */ |
|
215 | - protected function getSelectorName() |
|
216 | - { |
|
217 | - if ($this->getSource() instanceof SelectorInterface) { |
|
218 | - return $this->source->getSelectorName(); |
|
219 | - } else { |
|
220 | - return ''; |
|
221 | - } |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * Gets the node-tuple source for this query. |
|
226 | - * |
|
227 | - * @return SourceInterface the node-tuple source; non-null |
|
228 | - */ |
|
229 | - public function getSource() |
|
230 | - { |
|
231 | - if ($this->source === null) { |
|
232 | - $this->source = $this->qomFactory->selector($this->getType()); |
|
233 | - } |
|
234 | - return $this->source; |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * Executes the query against the database and returns the result |
|
239 | - * |
|
240 | - * @return QueryResultInterface|array The query result object or an array if $this->getQuerySettings()->getReturnRawQueryResult() is true |
|
241 | - * @api |
|
242 | - */ |
|
243 | - public function execute($returnRawQueryResult = false) |
|
244 | - { |
|
245 | - /** @var VidiDbBackend $backend */ |
|
246 | - $backend = GeneralUtility::makeInstance(VidiDbBackend::class, $this); |
|
247 | - return $backend->fetchResult(); |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Sets the property names to order the result by. Expected like this: |
|
252 | - * array( |
|
253 | - * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING, |
|
254 | - * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING |
|
255 | - * ) |
|
256 | - * where 'foo' and 'bar' are property names. |
|
257 | - * |
|
258 | - * @param array $orderings The property names to order by |
|
259 | - * @return QueryInterface |
|
260 | - * @api |
|
261 | - */ |
|
262 | - public function setOrderings(array $orderings) |
|
263 | - { |
|
264 | - $this->orderings = $orderings; |
|
265 | - return $this; |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * Returns the property names to order the result by. Like this: |
|
270 | - * array( |
|
271 | - * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING, |
|
272 | - * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING |
|
273 | - * ) |
|
274 | - * |
|
275 | - * @return array |
|
276 | - */ |
|
277 | - public function getOrderings() |
|
278 | - { |
|
279 | - return $this->orderings; |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * Sets the maximum size of the result set to limit. Returns $this to allow |
|
284 | - * for chaining (fluid interface) |
|
285 | - * |
|
286 | - * @param integer $limit |
|
287 | - * @throws \InvalidArgumentException |
|
288 | - * @return QueryInterface |
|
289 | - * @api |
|
290 | - */ |
|
291 | - public function setLimit($limit) |
|
292 | - { |
|
293 | - if (!is_int($limit) || $limit < 1) { |
|
294 | - throw new \InvalidArgumentException('The limit must be an integer >= 1', 1245071870); |
|
295 | - } |
|
296 | - $this->limit = $limit; |
|
297 | - return $this; |
|
298 | - } |
|
299 | - |
|
300 | - /** |
|
301 | - * Resets a previously set maximum size of the result set. Returns $this to allow |
|
302 | - * for chaining (fluid interface) |
|
303 | - * |
|
304 | - * @return QueryInterface |
|
305 | - * @api |
|
306 | - */ |
|
307 | - public function unsetLimit() |
|
308 | - { |
|
309 | - unset($this->limit); |
|
310 | - return $this; |
|
311 | - } |
|
312 | - |
|
313 | - /** |
|
314 | - * Returns the maximum size of the result set to limit. |
|
315 | - * |
|
316 | - * @return integer |
|
317 | - * @api |
|
318 | - */ |
|
319 | - public function getLimit() |
|
320 | - { |
|
321 | - return $this->limit; |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * Sets the start offset of the result set to offset. Returns $this to |
|
326 | - * allow for chaining (fluid interface) |
|
327 | - * |
|
328 | - * @param integer $offset |
|
329 | - * @throws \InvalidArgumentException |
|
330 | - * @return QueryInterface |
|
331 | - * @api |
|
332 | - */ |
|
333 | - public function setOffset($offset) |
|
334 | - { |
|
335 | - if (!is_int($offset) || $offset < 0) { |
|
336 | - throw new \InvalidArgumentException('The offset must be a positive integer', 1245071872); |
|
337 | - } |
|
338 | - $this->offset = $offset; |
|
339 | - return $this; |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * Returns the start offset of the result set. |
|
344 | - * |
|
345 | - * @return integer |
|
346 | - * @api |
|
347 | - */ |
|
348 | - public function getOffset() |
|
349 | - { |
|
350 | - return $this->offset; |
|
351 | - } |
|
352 | - |
|
353 | - /** |
|
354 | - * The constraint used to limit the result set. Returns $this to allow |
|
355 | - * for chaining (fluid interface) |
|
356 | - * |
|
357 | - * @param ConstraintInterface $constraint |
|
358 | - * @return QueryInterface |
|
359 | - * @api |
|
360 | - */ |
|
361 | - public function matching($constraint) |
|
362 | - { |
|
363 | - $this->constraint = $constraint; |
|
364 | - return $this; |
|
365 | - } |
|
366 | - |
|
367 | - /** |
|
368 | - * Gets the constraint for this query. |
|
369 | - * |
|
370 | - * @return ConstraintInterface the constraint, or null if none |
|
371 | - * @api |
|
372 | - */ |
|
373 | - public function getConstraint() |
|
374 | - { |
|
375 | - return $this->constraint; |
|
376 | - } |
|
377 | - |
|
378 | - /** |
|
379 | - * Performs a logical conjunction of the given constraints. The method takes one or more contraints and concatenates them with a boolean AND. |
|
380 | - * It also scepts a single array of constraints to be concatenated. |
|
381 | - * |
|
382 | - * @param mixed $constraint1 The first of multiple constraints or an array of constraints. |
|
383 | - * @throws InvalidNumberOfConstraintsException |
|
384 | - * @return AndInterface |
|
385 | - * @api |
|
386 | - */ |
|
387 | - public function logicalAnd($constraint1) |
|
388 | - { |
|
389 | - if (is_array($constraint1)) { |
|
390 | - $resultingConstraint = array_shift($constraint1); |
|
391 | - $constraints = $constraint1; |
|
392 | - } else { |
|
393 | - $constraints = func_get_args(); |
|
394 | - $resultingConstraint = array_shift($constraints); |
|
395 | - } |
|
396 | - if ($resultingConstraint === null) { |
|
397 | - throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289500); |
|
398 | - } |
|
399 | - foreach ($constraints as $constraint) { |
|
400 | - $resultingConstraint = $this->qomFactory->_and($resultingConstraint, $constraint); |
|
401 | - } |
|
402 | - return $resultingConstraint; |
|
403 | - } |
|
404 | - |
|
405 | - /** |
|
406 | - * Performs a logical disjunction of the two given constraints |
|
407 | - * |
|
408 | - * @param mixed $constraint1 The first of multiple constraints or an array of constraints. |
|
409 | - * @throws InvalidNumberOfConstraintsException |
|
410 | - * @return OrInterface |
|
411 | - * @api |
|
412 | - */ |
|
413 | - public function logicalOr($constraint1) |
|
414 | - { |
|
415 | - if (is_array($constraint1)) { |
|
416 | - $resultingConstraint = array_shift($constraint1); |
|
417 | - $constraints = $constraint1; |
|
418 | - } else { |
|
419 | - $constraints = func_get_args(); |
|
420 | - $resultingConstraint = array_shift($constraints); |
|
421 | - } |
|
422 | - if ($resultingConstraint === null) { |
|
423 | - throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289501); |
|
424 | - } |
|
425 | - foreach ($constraints as $constraint) { |
|
426 | - $resultingConstraint = $this->qomFactory->_or($resultingConstraint, $constraint); |
|
427 | - } |
|
428 | - return $resultingConstraint; |
|
429 | - } |
|
430 | - |
|
431 | - /** |
|
432 | - * Performs a logical negation of the given constraint |
|
433 | - * |
|
434 | - * @param ConstraintInterface $constraint Constraint to negate |
|
435 | - * @throws \RuntimeException |
|
436 | - * @return NotInterface |
|
437 | - * @api |
|
438 | - */ |
|
439 | - public function logicalNot(ConstraintInterface $constraint) |
|
440 | - { |
|
441 | - return $this->qomFactory->not($constraint); |
|
442 | - } |
|
443 | - |
|
444 | - /** |
|
445 | - * Returns an equals criterion used for matching objects against a query |
|
446 | - * |
|
447 | - * @param string $propertyName The name of the property to compare against |
|
448 | - * @param mixed $operand The value to compare with |
|
449 | - * @param boolean $caseSensitive Whether the equality test should be done case-sensitive |
|
450 | - * @return ComparisonInterface |
|
451 | - * @api |
|
452 | - */ |
|
453 | - public function equals($propertyName, $operand, $caseSensitive = true) |
|
454 | - { |
|
455 | - if (is_object($operand) || $caseSensitive) { |
|
456 | - $comparison = $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_EQUAL_TO, $operand); |
|
457 | - } else { |
|
458 | - $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)); |
|
459 | - } |
|
460 | - return $comparison; |
|
461 | - } |
|
462 | - |
|
463 | - /** |
|
464 | - * Returns a like criterion used for matching objects against a query |
|
465 | - * |
|
466 | - * @param string $propertyName The name of the property to compare against |
|
467 | - * @param mixed $operand The value to compare with |
|
468 | - * @param boolean $caseSensitive Whether the matching should be done case-sensitive |
|
469 | - * @return ComparisonInterface |
|
470 | - * @api |
|
471 | - */ |
|
472 | - public function like($propertyName, $operand, $caseSensitive = true) |
|
473 | - { |
|
474 | - return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LIKE, $operand); |
|
475 | - } |
|
476 | - |
|
477 | - /** |
|
478 | - * Returns a "contains" criterion used for matching objects against a query. |
|
479 | - * It matches if the multivalued property contains the given operand. |
|
480 | - * |
|
481 | - * @param string $propertyName The name of the (multivalued) property to compare against |
|
482 | - * @param mixed $operand The value to compare with |
|
483 | - * @return ComparisonInterface |
|
484 | - * @api |
|
485 | - */ |
|
486 | - public function contains($propertyName, $operand) |
|
487 | - { |
|
488 | - return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_CONTAINS, $operand); |
|
489 | - } |
|
490 | - |
|
491 | - /** |
|
492 | - * Returns an "in" criterion used for matching objects against a query. It |
|
493 | - * matches if the property's value is contained in the multivalued operand. |
|
494 | - * |
|
495 | - * @param string $propertyName The name of the property to compare against |
|
496 | - * @param mixed $operand The value to compare with, multivalued |
|
497 | - * @throws UnexpectedTypeException |
|
498 | - * @return ComparisonInterface |
|
499 | - * @api |
|
500 | - */ |
|
501 | - public function in($propertyName, $operand) |
|
502 | - { |
|
503 | - if (!is_array($operand) && !$operand instanceof \ArrayAccess && !$operand instanceof \Traversable) { |
|
504 | - throw new UnexpectedTypeException('The "in" operator must be given a mutlivalued operand (array, ArrayAccess, Traversable).', 1264678095); |
|
505 | - } |
|
506 | - return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_IN, $operand); |
|
507 | - } |
|
508 | - |
|
509 | - /** |
|
510 | - * Returns a less than criterion used for matching objects against a query |
|
511 | - * |
|
512 | - * @param string $propertyName The name of the property to compare against |
|
513 | - * @param mixed $operand The value to compare with |
|
514 | - * @return ComparisonInterface |
|
515 | - * @api |
|
516 | - */ |
|
517 | - public function lessThan($propertyName, $operand) |
|
518 | - { |
|
519 | - return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN, $operand); |
|
520 | - } |
|
521 | - |
|
522 | - /** |
|
523 | - * Returns a less or equal than criterion used for matching objects against a query |
|
524 | - * |
|
525 | - * @param string $propertyName The name of the property to compare against |
|
526 | - * @param mixed $operand The value to compare with |
|
527 | - * @return ComparisonInterface |
|
528 | - * @api |
|
529 | - */ |
|
530 | - public function lessThanOrEqual($propertyName, $operand) |
|
531 | - { |
|
532 | - return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO, $operand); |
|
533 | - } |
|
534 | - |
|
535 | - /** |
|
536 | - * Returns a greater than criterion used for matching objects against a query |
|
537 | - * |
|
538 | - * @param string $propertyName The name of the property to compare against |
|
539 | - * @param mixed $operand The value to compare with |
|
540 | - * @return ComparisonInterface |
|
541 | - * @api |
|
542 | - */ |
|
543 | - public function greaterThan($propertyName, $operand) |
|
544 | - { |
|
545 | - return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN, $operand); |
|
546 | - } |
|
547 | - |
|
548 | - /** |
|
549 | - * Returns a greater than or equal criterion used for matching objects against a query |
|
550 | - * |
|
551 | - * @param string $propertyName The name of the property to compare against |
|
552 | - * @param mixed $operand The value to compare with |
|
553 | - * @return ComparisonInterface |
|
554 | - * @api |
|
555 | - */ |
|
556 | - public function greaterThanOrEqual($propertyName, $operand) |
|
557 | - { |
|
558 | - return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO, $operand); |
|
559 | - } |
|
560 | - |
|
561 | - /** |
|
562 | - * Returns the query result count. |
|
563 | - * |
|
564 | - * @return integer The query result count |
|
565 | - * @api |
|
566 | - */ |
|
567 | - public function count() |
|
568 | - { |
|
569 | - /** @var VidiDbBackend $backend */ |
|
570 | - $backend = GeneralUtility::makeInstance(VidiDbBackend::class, $this); |
|
571 | - return $backend->countResult(); |
|
572 | - } |
|
573 | - |
|
574 | - /** |
|
575 | - * Returns an "isEmpty" criterion used for matching objects against a query. |
|
576 | - * It matches if the multivalued property contains no values or is null. |
|
577 | - * |
|
578 | - * @param string $propertyName The name of the multivalued property to compare against |
|
579 | - * @throws NotImplementedException |
|
580 | - * @throws InvalidQueryException if used on a single-valued property |
|
581 | - * @api |
|
582 | - */ |
|
583 | - public function isEmpty($propertyName) |
|
584 | - { |
|
585 | - throw new NotImplementedException(__METHOD__); |
|
586 | - } |
|
587 | - |
|
588 | - /** |
|
589 | - * @return string |
|
590 | - */ |
|
591 | - public function getDistinct() |
|
592 | - { |
|
593 | - return $this->distinct; |
|
594 | - } |
|
595 | - |
|
596 | - /** |
|
597 | - * @param string $distinct |
|
598 | - * @return $this |
|
599 | - */ |
|
600 | - public function setDistinct($distinct) |
|
601 | - { |
|
602 | - $this->distinct = $distinct; |
|
603 | - return $this; |
|
604 | - } |
|
605 | - |
|
606 | - /** |
|
607 | - * Sets the statement of this query. If you use this, you will lose the abstraction from a concrete storage |
|
608 | - * backend (database). |
|
609 | - * |
|
610 | - * @param string|\TYPO3\CMS\Core\Database\PreparedStatement $statement The statement |
|
611 | - * @param array $parameters An array of parameters. These will be bound to placeholders '?' in the $statement. |
|
612 | - * @return QueryInterface |
|
613 | - */ |
|
614 | - public function statement($statement, array $parameters = array()) |
|
615 | - { |
|
616 | - $this->statement = $this->qomFactory->statement($statement, $parameters); |
|
617 | - return $this; |
|
618 | - } |
|
619 | - |
|
620 | - /** |
|
621 | - * Returns the statement of this query. |
|
622 | - * |
|
623 | - * @return Statement |
|
624 | - */ |
|
625 | - public function getStatement() |
|
626 | - { |
|
627 | - return $this->statement; |
|
628 | - } |
|
629 | - |
|
630 | - protected function isBackendMode(): bool |
|
631 | - { |
|
632 | - return Typo3Mode::isBackendMode(); |
|
633 | - } |
|
634 | - |
|
635 | - /** |
|
636 | - * @return string |
|
637 | - */ |
|
638 | - public function getSourceFieldName() |
|
639 | - { |
|
640 | - return $this->sourceFieldName; |
|
641 | - } |
|
642 | - |
|
643 | - /** |
|
644 | - * @param string $sourceFieldName |
|
645 | - * @return $this |
|
646 | - */ |
|
647 | - public function setSourceFieldName($sourceFieldName) |
|
648 | - { |
|
649 | - $this->sourceFieldName = $sourceFieldName; |
|
650 | - return $this; |
|
651 | - } |
|
652 | - |
|
653 | - public function setQuerySettings(QuerySettingsInterface $querySettings) |
|
654 | - { |
|
655 | - $this->typo3QuerySettings = $querySettings; |
|
656 | - } |
|
657 | - |
|
658 | - public function getQuerySettings() |
|
659 | - { |
|
660 | - return $this->typo3QuerySettings; |
|
661 | - } |
|
45 | + /** |
|
46 | + * An inner join. |
|
47 | + */ |
|
48 | + public const JCR_JOIN_TYPE_INNER = '{http://www.jcp.org/jcr/1.0}joinTypeInner'; |
|
49 | + |
|
50 | + /** |
|
51 | + * A left-outer join. |
|
52 | + */ |
|
53 | + public const JCR_JOIN_TYPE_LEFT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeLeftOuter'; |
|
54 | + |
|
55 | + /** |
|
56 | + * A right-outer join. |
|
57 | + */ |
|
58 | + public const JCR_JOIN_TYPE_RIGHT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeRightOuter'; |
|
59 | + |
|
60 | + /** |
|
61 | + * Charset of strings in QOM |
|
62 | + */ |
|
63 | + public const CHARSET = 'utf-8'; |
|
64 | + |
|
65 | + /** |
|
66 | + * @var string |
|
67 | + */ |
|
68 | + protected $sourceFieldName; |
|
69 | + |
|
70 | + /** |
|
71 | + * @var string |
|
72 | + */ |
|
73 | + protected $type; |
|
74 | + |
|
75 | + /** |
|
76 | + * @var PersistenceManagerInterface |
|
77 | + */ |
|
78 | + protected $persistenceManager; |
|
79 | + |
|
80 | + /** |
|
81 | + * @var QueryObjectModelFactory |
|
82 | + */ |
|
83 | + protected $qomFactory; |
|
84 | + |
|
85 | + /** |
|
86 | + * @var SourceInterface |
|
87 | + */ |
|
88 | + protected $source; |
|
89 | + |
|
90 | + /** |
|
91 | + * @var ConstraintInterface |
|
92 | + */ |
|
93 | + protected $constraint; |
|
94 | + |
|
95 | + /** |
|
96 | + * @var Statement |
|
97 | + */ |
|
98 | + protected $statement; |
|
99 | + |
|
100 | + /** |
|
101 | + * @var array |
|
102 | + */ |
|
103 | + protected $orderings = []; |
|
104 | + |
|
105 | + /** |
|
106 | + * @var int |
|
107 | + */ |
|
108 | + protected $limit; |
|
109 | + |
|
110 | + /** |
|
111 | + * @var int |
|
112 | + */ |
|
113 | + protected $offset; |
|
114 | + |
|
115 | + /** |
|
116 | + * Apply DISTINCT upon property. |
|
117 | + * |
|
118 | + * @var string |
|
119 | + */ |
|
120 | + protected $distinct; |
|
121 | + |
|
122 | + /** |
|
123 | + * The query settings. |
|
124 | + * |
|
125 | + * @var Typo3QuerySettings |
|
126 | + */ |
|
127 | + public Typo3QuerySettings $typo3QuerySettings; |
|
128 | + |
|
129 | + /** |
|
130 | + * Constructs a query object working on the given class name |
|
131 | + * |
|
132 | + * @param string $type |
|
133 | + */ |
|
134 | + public function __construct($type) |
|
135 | + { |
|
136 | + $this->type = $type; |
|
137 | + $this->persistenceManager = GeneralUtility::makeInstance(PersistenceManagerInterface::class); |
|
138 | + $this->qomFactory = GeneralUtility::makeInstance(QueryObjectModelFactory::class); |
|
139 | + } |
|
140 | + |
|
141 | + public function injectTypo3QuerySettings(Typo3QuerySettings $querySettings): void |
|
142 | + { |
|
143 | + $this->typo3QuerySettings = $querySettings; |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * Sets the Query Settings. These Query settings must match the settings expected by |
|
148 | + * the specific Storage Backend. |
|
149 | + * |
|
150 | + * @param QuerySettingsInterface $typo3QuerySettings The Query Settings |
|
151 | + * @return void |
|
152 | + */ |
|
153 | + public function setTypo3QuerySettings(QuerySettingsInterface $typo3QuerySettings) |
|
154 | + { |
|
155 | + $this->typo3QuerySettings = $typo3QuerySettings; |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * Returns the Query Settings. |
|
160 | + * |
|
161 | + * @throws \Exception |
|
162 | + * @return Typo3QuerySettings $querySettings The Query Settings |
|
163 | + * @api This method is not part of FLOW3 API |
|
164 | + */ |
|
165 | + public function getTypo3QuerySettings() |
|
166 | + { |
|
167 | + if (!$this->typo3QuerySettings instanceof QuerySettingsInterface) { |
|
168 | + throw new Exception('Tried to get the query settings without setting them before.', 1248689115); |
|
169 | + } |
|
170 | + |
|
171 | + // Apply possible settings to the query. |
|
172 | + if ($this->isBackendMode()) { |
|
173 | + /** @var BackendConfigurationManager $backendConfigurationManager */ |
|
174 | + $backendConfigurationManager = GeneralUtility::makeInstance(BackendConfigurationManager::class); |
|
175 | + $configuration = $backendConfigurationManager->getTypoScriptSetup(); |
|
176 | + $querySettings = array('respectSysLanguage'); |
|
177 | + foreach ($querySettings as $setting) { |
|
178 | + if (isset($configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting])) { |
|
179 | + $value = (bool)$configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting]; |
|
180 | + ObjectAccess::setProperty($this->typo3QuerySettings, $setting, $value); |
|
181 | + } |
|
182 | + } |
|
183 | + } |
|
184 | + |
|
185 | + return $this->typo3QuerySettings; |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Returns the type this query cares for. |
|
190 | + * |
|
191 | + * @return string |
|
192 | + * @api |
|
193 | + */ |
|
194 | + public function getType() |
|
195 | + { |
|
196 | + return $this->type; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Sets the source to fetch the result from |
|
201 | + * |
|
202 | + * @param SourceInterface $source |
|
203 | + */ |
|
204 | + public function setSource(SourceInterface $source) |
|
205 | + { |
|
206 | + $this->source = $source; |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * Returns the selectorn name or an empty string, if the source is not a selector |
|
211 | + * TODO This has to be checked at another place |
|
212 | + * |
|
213 | + * @return string The selector name |
|
214 | + */ |
|
215 | + protected function getSelectorName() |
|
216 | + { |
|
217 | + if ($this->getSource() instanceof SelectorInterface) { |
|
218 | + return $this->source->getSelectorName(); |
|
219 | + } else { |
|
220 | + return ''; |
|
221 | + } |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * Gets the node-tuple source for this query. |
|
226 | + * |
|
227 | + * @return SourceInterface the node-tuple source; non-null |
|
228 | + */ |
|
229 | + public function getSource() |
|
230 | + { |
|
231 | + if ($this->source === null) { |
|
232 | + $this->source = $this->qomFactory->selector($this->getType()); |
|
233 | + } |
|
234 | + return $this->source; |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * Executes the query against the database and returns the result |
|
239 | + * |
|
240 | + * @return QueryResultInterface|array The query result object or an array if $this->getQuerySettings()->getReturnRawQueryResult() is true |
|
241 | + * @api |
|
242 | + */ |
|
243 | + public function execute($returnRawQueryResult = false) |
|
244 | + { |
|
245 | + /** @var VidiDbBackend $backend */ |
|
246 | + $backend = GeneralUtility::makeInstance(VidiDbBackend::class, $this); |
|
247 | + return $backend->fetchResult(); |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Sets the property names to order the result by. Expected like this: |
|
252 | + * array( |
|
253 | + * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING, |
|
254 | + * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING |
|
255 | + * ) |
|
256 | + * where 'foo' and 'bar' are property names. |
|
257 | + * |
|
258 | + * @param array $orderings The property names to order by |
|
259 | + * @return QueryInterface |
|
260 | + * @api |
|
261 | + */ |
|
262 | + public function setOrderings(array $orderings) |
|
263 | + { |
|
264 | + $this->orderings = $orderings; |
|
265 | + return $this; |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * Returns the property names to order the result by. Like this: |
|
270 | + * array( |
|
271 | + * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING, |
|
272 | + * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING |
|
273 | + * ) |
|
274 | + * |
|
275 | + * @return array |
|
276 | + */ |
|
277 | + public function getOrderings() |
|
278 | + { |
|
279 | + return $this->orderings; |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * Sets the maximum size of the result set to limit. Returns $this to allow |
|
284 | + * for chaining (fluid interface) |
|
285 | + * |
|
286 | + * @param integer $limit |
|
287 | + * @throws \InvalidArgumentException |
|
288 | + * @return QueryInterface |
|
289 | + * @api |
|
290 | + */ |
|
291 | + public function setLimit($limit) |
|
292 | + { |
|
293 | + if (!is_int($limit) || $limit < 1) { |
|
294 | + throw new \InvalidArgumentException('The limit must be an integer >= 1', 1245071870); |
|
295 | + } |
|
296 | + $this->limit = $limit; |
|
297 | + return $this; |
|
298 | + } |
|
299 | + |
|
300 | + /** |
|
301 | + * Resets a previously set maximum size of the result set. Returns $this to allow |
|
302 | + * for chaining (fluid interface) |
|
303 | + * |
|
304 | + * @return QueryInterface |
|
305 | + * @api |
|
306 | + */ |
|
307 | + public function unsetLimit() |
|
308 | + { |
|
309 | + unset($this->limit); |
|
310 | + return $this; |
|
311 | + } |
|
312 | + |
|
313 | + /** |
|
314 | + * Returns the maximum size of the result set to limit. |
|
315 | + * |
|
316 | + * @return integer |
|
317 | + * @api |
|
318 | + */ |
|
319 | + public function getLimit() |
|
320 | + { |
|
321 | + return $this->limit; |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * Sets the start offset of the result set to offset. Returns $this to |
|
326 | + * allow for chaining (fluid interface) |
|
327 | + * |
|
328 | + * @param integer $offset |
|
329 | + * @throws \InvalidArgumentException |
|
330 | + * @return QueryInterface |
|
331 | + * @api |
|
332 | + */ |
|
333 | + public function setOffset($offset) |
|
334 | + { |
|
335 | + if (!is_int($offset) || $offset < 0) { |
|
336 | + throw new \InvalidArgumentException('The offset must be a positive integer', 1245071872); |
|
337 | + } |
|
338 | + $this->offset = $offset; |
|
339 | + return $this; |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * Returns the start offset of the result set. |
|
344 | + * |
|
345 | + * @return integer |
|
346 | + * @api |
|
347 | + */ |
|
348 | + public function getOffset() |
|
349 | + { |
|
350 | + return $this->offset; |
|
351 | + } |
|
352 | + |
|
353 | + /** |
|
354 | + * The constraint used to limit the result set. Returns $this to allow |
|
355 | + * for chaining (fluid interface) |
|
356 | + * |
|
357 | + * @param ConstraintInterface $constraint |
|
358 | + * @return QueryInterface |
|
359 | + * @api |
|
360 | + */ |
|
361 | + public function matching($constraint) |
|
362 | + { |
|
363 | + $this->constraint = $constraint; |
|
364 | + return $this; |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * Gets the constraint for this query. |
|
369 | + * |
|
370 | + * @return ConstraintInterface the constraint, or null if none |
|
371 | + * @api |
|
372 | + */ |
|
373 | + public function getConstraint() |
|
374 | + { |
|
375 | + return $this->constraint; |
|
376 | + } |
|
377 | + |
|
378 | + /** |
|
379 | + * Performs a logical conjunction of the given constraints. The method takes one or more contraints and concatenates them with a boolean AND. |
|
380 | + * It also scepts a single array of constraints to be concatenated. |
|
381 | + * |
|
382 | + * @param mixed $constraint1 The first of multiple constraints or an array of constraints. |
|
383 | + * @throws InvalidNumberOfConstraintsException |
|
384 | + * @return AndInterface |
|
385 | + * @api |
|
386 | + */ |
|
387 | + public function logicalAnd($constraint1) |
|
388 | + { |
|
389 | + if (is_array($constraint1)) { |
|
390 | + $resultingConstraint = array_shift($constraint1); |
|
391 | + $constraints = $constraint1; |
|
392 | + } else { |
|
393 | + $constraints = func_get_args(); |
|
394 | + $resultingConstraint = array_shift($constraints); |
|
395 | + } |
|
396 | + if ($resultingConstraint === null) { |
|
397 | + throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289500); |
|
398 | + } |
|
399 | + foreach ($constraints as $constraint) { |
|
400 | + $resultingConstraint = $this->qomFactory->_and($resultingConstraint, $constraint); |
|
401 | + } |
|
402 | + return $resultingConstraint; |
|
403 | + } |
|
404 | + |
|
405 | + /** |
|
406 | + * Performs a logical disjunction of the two given constraints |
|
407 | + * |
|
408 | + * @param mixed $constraint1 The first of multiple constraints or an array of constraints. |
|
409 | + * @throws InvalidNumberOfConstraintsException |
|
410 | + * @return OrInterface |
|
411 | + * @api |
|
412 | + */ |
|
413 | + public function logicalOr($constraint1) |
|
414 | + { |
|
415 | + if (is_array($constraint1)) { |
|
416 | + $resultingConstraint = array_shift($constraint1); |
|
417 | + $constraints = $constraint1; |
|
418 | + } else { |
|
419 | + $constraints = func_get_args(); |
|
420 | + $resultingConstraint = array_shift($constraints); |
|
421 | + } |
|
422 | + if ($resultingConstraint === null) { |
|
423 | + throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289501); |
|
424 | + } |
|
425 | + foreach ($constraints as $constraint) { |
|
426 | + $resultingConstraint = $this->qomFactory->_or($resultingConstraint, $constraint); |
|
427 | + } |
|
428 | + return $resultingConstraint; |
|
429 | + } |
|
430 | + |
|
431 | + /** |
|
432 | + * Performs a logical negation of the given constraint |
|
433 | + * |
|
434 | + * @param ConstraintInterface $constraint Constraint to negate |
|
435 | + * @throws \RuntimeException |
|
436 | + * @return NotInterface |
|
437 | + * @api |
|
438 | + */ |
|
439 | + public function logicalNot(ConstraintInterface $constraint) |
|
440 | + { |
|
441 | + return $this->qomFactory->not($constraint); |
|
442 | + } |
|
443 | + |
|
444 | + /** |
|
445 | + * Returns an equals criterion used for matching objects against a query |
|
446 | + * |
|
447 | + * @param string $propertyName The name of the property to compare against |
|
448 | + * @param mixed $operand The value to compare with |
|
449 | + * @param boolean $caseSensitive Whether the equality test should be done case-sensitive |
|
450 | + * @return ComparisonInterface |
|
451 | + * @api |
|
452 | + */ |
|
453 | + public function equals($propertyName, $operand, $caseSensitive = true) |
|
454 | + { |
|
455 | + if (is_object($operand) || $caseSensitive) { |
|
456 | + $comparison = $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_EQUAL_TO, $operand); |
|
457 | + } else { |
|
458 | + $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)); |
|
459 | + } |
|
460 | + return $comparison; |
|
461 | + } |
|
462 | + |
|
463 | + /** |
|
464 | + * Returns a like criterion used for matching objects against a query |
|
465 | + * |
|
466 | + * @param string $propertyName The name of the property to compare against |
|
467 | + * @param mixed $operand The value to compare with |
|
468 | + * @param boolean $caseSensitive Whether the matching should be done case-sensitive |
|
469 | + * @return ComparisonInterface |
|
470 | + * @api |
|
471 | + */ |
|
472 | + public function like($propertyName, $operand, $caseSensitive = true) |
|
473 | + { |
|
474 | + return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LIKE, $operand); |
|
475 | + } |
|
476 | + |
|
477 | + /** |
|
478 | + * Returns a "contains" criterion used for matching objects against a query. |
|
479 | + * It matches if the multivalued property contains the given operand. |
|
480 | + * |
|
481 | + * @param string $propertyName The name of the (multivalued) property to compare against |
|
482 | + * @param mixed $operand The value to compare with |
|
483 | + * @return ComparisonInterface |
|
484 | + * @api |
|
485 | + */ |
|
486 | + public function contains($propertyName, $operand) |
|
487 | + { |
|
488 | + return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_CONTAINS, $operand); |
|
489 | + } |
|
490 | + |
|
491 | + /** |
|
492 | + * Returns an "in" criterion used for matching objects against a query. It |
|
493 | + * matches if the property's value is contained in the multivalued operand. |
|
494 | + * |
|
495 | + * @param string $propertyName The name of the property to compare against |
|
496 | + * @param mixed $operand The value to compare with, multivalued |
|
497 | + * @throws UnexpectedTypeException |
|
498 | + * @return ComparisonInterface |
|
499 | + * @api |
|
500 | + */ |
|
501 | + public function in($propertyName, $operand) |
|
502 | + { |
|
503 | + if (!is_array($operand) && !$operand instanceof \ArrayAccess && !$operand instanceof \Traversable) { |
|
504 | + throw new UnexpectedTypeException('The "in" operator must be given a mutlivalued operand (array, ArrayAccess, Traversable).', 1264678095); |
|
505 | + } |
|
506 | + return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_IN, $operand); |
|
507 | + } |
|
508 | + |
|
509 | + /** |
|
510 | + * Returns a less than criterion used for matching objects against a query |
|
511 | + * |
|
512 | + * @param string $propertyName The name of the property to compare against |
|
513 | + * @param mixed $operand The value to compare with |
|
514 | + * @return ComparisonInterface |
|
515 | + * @api |
|
516 | + */ |
|
517 | + public function lessThan($propertyName, $operand) |
|
518 | + { |
|
519 | + return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN, $operand); |
|
520 | + } |
|
521 | + |
|
522 | + /** |
|
523 | + * Returns a less or equal than criterion used for matching objects against a query |
|
524 | + * |
|
525 | + * @param string $propertyName The name of the property to compare against |
|
526 | + * @param mixed $operand The value to compare with |
|
527 | + * @return ComparisonInterface |
|
528 | + * @api |
|
529 | + */ |
|
530 | + public function lessThanOrEqual($propertyName, $operand) |
|
531 | + { |
|
532 | + return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO, $operand); |
|
533 | + } |
|
534 | + |
|
535 | + /** |
|
536 | + * Returns a greater than criterion used for matching objects against a query |
|
537 | + * |
|
538 | + * @param string $propertyName The name of the property to compare against |
|
539 | + * @param mixed $operand The value to compare with |
|
540 | + * @return ComparisonInterface |
|
541 | + * @api |
|
542 | + */ |
|
543 | + public function greaterThan($propertyName, $operand) |
|
544 | + { |
|
545 | + return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN, $operand); |
|
546 | + } |
|
547 | + |
|
548 | + /** |
|
549 | + * Returns a greater than or equal criterion used for matching objects against a query |
|
550 | + * |
|
551 | + * @param string $propertyName The name of the property to compare against |
|
552 | + * @param mixed $operand The value to compare with |
|
553 | + * @return ComparisonInterface |
|
554 | + * @api |
|
555 | + */ |
|
556 | + public function greaterThanOrEqual($propertyName, $operand) |
|
557 | + { |
|
558 | + return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO, $operand); |
|
559 | + } |
|
560 | + |
|
561 | + /** |
|
562 | + * Returns the query result count. |
|
563 | + * |
|
564 | + * @return integer The query result count |
|
565 | + * @api |
|
566 | + */ |
|
567 | + public function count() |
|
568 | + { |
|
569 | + /** @var VidiDbBackend $backend */ |
|
570 | + $backend = GeneralUtility::makeInstance(VidiDbBackend::class, $this); |
|
571 | + return $backend->countResult(); |
|
572 | + } |
|
573 | + |
|
574 | + /** |
|
575 | + * Returns an "isEmpty" criterion used for matching objects against a query. |
|
576 | + * It matches if the multivalued property contains no values or is null. |
|
577 | + * |
|
578 | + * @param string $propertyName The name of the multivalued property to compare against |
|
579 | + * @throws NotImplementedException |
|
580 | + * @throws InvalidQueryException if used on a single-valued property |
|
581 | + * @api |
|
582 | + */ |
|
583 | + public function isEmpty($propertyName) |
|
584 | + { |
|
585 | + throw new NotImplementedException(__METHOD__); |
|
586 | + } |
|
587 | + |
|
588 | + /** |
|
589 | + * @return string |
|
590 | + */ |
|
591 | + public function getDistinct() |
|
592 | + { |
|
593 | + return $this->distinct; |
|
594 | + } |
|
595 | + |
|
596 | + /** |
|
597 | + * @param string $distinct |
|
598 | + * @return $this |
|
599 | + */ |
|
600 | + public function setDistinct($distinct) |
|
601 | + { |
|
602 | + $this->distinct = $distinct; |
|
603 | + return $this; |
|
604 | + } |
|
605 | + |
|
606 | + /** |
|
607 | + * Sets the statement of this query. If you use this, you will lose the abstraction from a concrete storage |
|
608 | + * backend (database). |
|
609 | + * |
|
610 | + * @param string|\TYPO3\CMS\Core\Database\PreparedStatement $statement The statement |
|
611 | + * @param array $parameters An array of parameters. These will be bound to placeholders '?' in the $statement. |
|
612 | + * @return QueryInterface |
|
613 | + */ |
|
614 | + public function statement($statement, array $parameters = array()) |
|
615 | + { |
|
616 | + $this->statement = $this->qomFactory->statement($statement, $parameters); |
|
617 | + return $this; |
|
618 | + } |
|
619 | + |
|
620 | + /** |
|
621 | + * Returns the statement of this query. |
|
622 | + * |
|
623 | + * @return Statement |
|
624 | + */ |
|
625 | + public function getStatement() |
|
626 | + { |
|
627 | + return $this->statement; |
|
628 | + } |
|
629 | + |
|
630 | + protected function isBackendMode(): bool |
|
631 | + { |
|
632 | + return Typo3Mode::isBackendMode(); |
|
633 | + } |
|
634 | + |
|
635 | + /** |
|
636 | + * @return string |
|
637 | + */ |
|
638 | + public function getSourceFieldName() |
|
639 | + { |
|
640 | + return $this->sourceFieldName; |
|
641 | + } |
|
642 | + |
|
643 | + /** |
|
644 | + * @param string $sourceFieldName |
|
645 | + * @return $this |
|
646 | + */ |
|
647 | + public function setSourceFieldName($sourceFieldName) |
|
648 | + { |
|
649 | + $this->sourceFieldName = $sourceFieldName; |
|
650 | + return $this; |
|
651 | + } |
|
652 | + |
|
653 | + public function setQuerySettings(QuerySettingsInterface $querySettings) |
|
654 | + { |
|
655 | + $this->typo3QuerySettings = $querySettings; |
|
656 | + } |
|
657 | + |
|
658 | + public function getQuerySettings() |
|
659 | + { |
|
660 | + return $this->typo3QuerySettings; |
|
661 | + } |
|
662 | 662 | } |
@@ -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 = ''; |
@@ -1,9 +1,9 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | $EM_CONF[$_EXTKEY] = [ |
4 | - 'title' => 'Versatile and Interactive Display - List Component', |
|
5 | - 'description' => 'Generic listing of records with versatile ways of interacting with the data, e.g. advanced filter, inline editing, mass editing, ... Veni, vidi, vici!', |
|
6 | - 'author' => 'Fabien Udriot', |
|
7 | - 'author_email' => '[email protected]', |
|
8 | - 'state' => 'stable', |
|
4 | + 'title' => 'Versatile and Interactive Display - List Component', |
|
5 | + 'description' => 'Generic listing of records with versatile ways of interacting with the data, e.g. advanced filter, inline editing, mass editing, ... Veni, vidi, vici!', |
|
6 | + 'author' => 'Fabien Udriot', |
|
7 | + 'author_email' => '[email protected]', |
|
8 | + 'state' => 'stable', |
|
9 | 9 | ]; |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | */ |
194 | 194 | protected function getExistingMainConfiguration(): array |
195 | 195 | { |
196 | - $moduleSignature = $this->computeMainModule() . '_' . $this->getInternalModuleSignature(); |
|
196 | + $moduleSignature = $this->computeMainModule().'_'.$this->getInternalModuleSignature(); |
|
197 | 197 | return $GLOBALS['TBE_MODULES']['_configuration'][$moduleSignature] ?? []; |
198 | 198 | } |
199 | 199 | |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | ExtensionUtility::registerModule( |
316 | 316 | 'Vidi', |
317 | 317 | $this->computeMainModule(), |
318 | - $this->dataType . '_' . $this->moduleKey, |
|
318 | + $this->dataType.'_'.$this->moduleKey, |
|
319 | 319 | $this->position, |
320 | 320 | [ |
321 | 321 | ContentController::class => 'index, list, delete, update, edit, copy, move, localize, sort, copyClipboard, moveClipboard', |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | */ |
379 | 379 | public function getParameterPrefix(): string |
380 | 380 | { |
381 | - return 'tx_vidi_' . strtolower($this->getSignature()); |
|
381 | + return 'tx_vidi_'.strtolower($this->getSignature()); |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | /** |
@@ -1031,10 +1031,10 @@ discard block |
||
1031 | 1031 | if ($dataType === null) { |
1032 | 1032 | $dataType = $this->dataType; |
1033 | 1033 | } |
1034 | - $subModuleName = $dataType . '_' . $this->moduleKey; |
|
1034 | + $subModuleName = $dataType.'_'.$this->moduleKey; |
|
1035 | 1035 | |
1036 | 1036 | $mainModule = $this->mainModule ?: self::DEFAULT_MAIN_MODULE; |
1037 | - return $mainModule . '_Vidi' . GeneralUtility::underscoredToUpperCamelCase($subModuleName); |
|
1037 | + return $mainModule.'_Vidi'.GeneralUtility::underscoredToUpperCamelCase($subModuleName); |
|
1038 | 1038 | } |
1039 | 1039 | |
1040 | 1040 | } |
@@ -35,996 +35,996 @@ |
||
35 | 35 | */ |
36 | 36 | class ModuleLoader |
37 | 37 | { |
38 | - /** |
|
39 | - * Define the default main module |
|
40 | - */ |
|
41 | - public const DEFAULT_MAIN_MODULE = 'content'; |
|
42 | - |
|
43 | - /** |
|
44 | - * Define the default pid |
|
45 | - */ |
|
46 | - public const DEFAULT_PID = 0; |
|
47 | - |
|
48 | - /** |
|
49 | - * The type of data being listed (which corresponds to a table name in TCA) |
|
50 | - * |
|
51 | - * @var string |
|
52 | - */ |
|
53 | - protected $dataType; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var string |
|
57 | - */ |
|
58 | - protected $defaultPid; |
|
59 | - |
|
60 | - /** |
|
61 | - * @var bool |
|
62 | - */ |
|
63 | - protected $isPidIgnored = false; |
|
64 | - |
|
65 | - /** |
|
66 | - * @var bool |
|
67 | - */ |
|
68 | - protected $showPageTree = false; |
|
69 | - |
|
70 | - /** |
|
71 | - * @var bool |
|
72 | - */ |
|
73 | - protected $isShown = true; |
|
74 | - |
|
75 | - /** |
|
76 | - * @var string |
|
77 | - */ |
|
78 | - protected $access; |
|
79 | - |
|
80 | - /** |
|
81 | - * @var string |
|
82 | - */ |
|
83 | - protected $mainModule; |
|
84 | - |
|
85 | - /** |
|
86 | - * @var string |
|
87 | - */ |
|
88 | - protected $position = ''; |
|
89 | - |
|
90 | - /** |
|
91 | - * @var string |
|
92 | - */ |
|
93 | - protected $icon; |
|
94 | - |
|
95 | - /** |
|
96 | - * @var string |
|
97 | - */ |
|
98 | - protected $moduleLanguageFile; |
|
99 | - |
|
100 | - /** |
|
101 | - * The module key such as m1, m2. |
|
102 | - * |
|
103 | - * @var string |
|
104 | - */ |
|
105 | - protected $moduleKey = 'm1'; |
|
106 | - |
|
107 | - /** |
|
108 | - * @var string[] |
|
109 | - */ |
|
110 | - protected $additionalJavaScriptFiles = []; |
|
111 | - |
|
112 | - /** |
|
113 | - * @var string[] |
|
114 | - */ |
|
115 | - protected $additionalStyleSheetFiles = []; |
|
116 | - |
|
117 | - /** |
|
118 | - * @var array |
|
119 | - */ |
|
120 | - protected $components = []; |
|
121 | - |
|
122 | - /** |
|
123 | - * @param string $dataType |
|
124 | - */ |
|
125 | - public function __construct($dataType = null) |
|
126 | - { |
|
127 | - $this->dataType = $dataType; |
|
128 | - |
|
129 | - // Initialize components |
|
130 | - $this->components = [ |
|
131 | - ModulePosition::DOC_HEADER => [ |
|
132 | - ModulePosition::TOP => [ |
|
133 | - ModulePosition::LEFT => [], |
|
134 | - ModulePosition::RIGHT => [ |
|
135 | - ToolButton::class, |
|
136 | - ], |
|
137 | - ], |
|
138 | - ModulePosition::BOTTOM => [ |
|
139 | - ModulePosition::LEFT => [ |
|
140 | - NewButton::class, |
|
141 | - BackViewHelper::class, |
|
142 | - ], |
|
143 | - ModulePosition::RIGHT => [], |
|
144 | - ], |
|
145 | - ], |
|
146 | - ModulePosition::GRID => [ |
|
147 | - ModulePosition::TOP => [ |
|
148 | - RelationsCheck::class, |
|
149 | - #\Fab\Vidi\View\Tab\DataTypeTab::class, |
|
150 | - ], |
|
151 | - ModulePosition::BUTTONS => [ |
|
152 | - EditButton::class, |
|
153 | - DeleteButton::class, |
|
154 | - ], |
|
155 | - ModulePosition::BOTTOM => [], |
|
156 | - ], |
|
157 | - ModulePosition::MENU_MASS_ACTION => [ |
|
158 | - ExportXlsMenuItem::class, |
|
159 | - ExportXmlMenuItem::class, |
|
160 | - ExportCsvMenuItem::class, |
|
161 | - DividerMenuItem::class, |
|
162 | - MassDeleteMenuItem::class, |
|
163 | - #\Fab\Vidi\View\MenuItem\MassEditMenuItem::class, |
|
164 | - ], |
|
165 | - ]; |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Tell whether a module is already registered. |
|
170 | - * |
|
171 | - * @param string $dataType |
|
172 | - * @return bool |
|
173 | - */ |
|
174 | - public function isRegistered($dataType): bool |
|
175 | - { |
|
176 | - $internalModuleSignature = $this->getInternalModuleSignature($dataType); |
|
177 | - return !empty($GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]); |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * @return array |
|
182 | - */ |
|
183 | - protected function getExistingInternalConfiguration(): array |
|
184 | - { |
|
185 | - $internalModuleSignature = $this->getInternalModuleSignature(); |
|
186 | - return $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature] ?? []; |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * @return array |
|
191 | - */ |
|
192 | - protected function getExistingMainConfiguration(): array |
|
193 | - { |
|
194 | - $moduleSignature = $this->computeMainModule() . '_' . $this->getInternalModuleSignature(); |
|
195 | - return $GLOBALS['TBE_MODULES']['_configuration'][$moduleSignature] ?? []; |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * @return string |
|
200 | - */ |
|
201 | - protected function computeMainModule(): string |
|
202 | - { |
|
203 | - $existingConfiguration = $this->getExistingInternalConfiguration(); |
|
204 | - |
|
205 | - if ($this->mainModule !== null) { |
|
206 | - $mainModule = $this->mainModule; |
|
207 | - } elseif (!empty($existingConfiguration['mainModule'])) { // existing configuration may override. |
|
208 | - $mainModule = $existingConfiguration['mainModule']; |
|
209 | - } else { |
|
210 | - $mainModule = self::DEFAULT_MAIN_MODULE; //default value. |
|
211 | - } |
|
212 | - return $mainModule; |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * @return string |
|
217 | - */ |
|
218 | - protected function computeDefaultPid(): string |
|
219 | - { |
|
220 | - $existingConfiguration = $this->getExistingInternalConfiguration(); |
|
221 | - |
|
222 | - if ($this->defaultPid !== null) { |
|
223 | - $defaultPid = $this->defaultPid; |
|
224 | - } elseif (!empty($existingConfiguration['defaultPid'])) { // existing configuration may override. |
|
225 | - $defaultPid = $existingConfiguration['defaultPid']; |
|
226 | - } else { |
|
227 | - $defaultPid = self::DEFAULT_PID; //default value. |
|
228 | - } |
|
229 | - return $defaultPid; |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * @return array |
|
234 | - */ |
|
235 | - protected function computeAdditionalJavaScriptFiles(): array |
|
236 | - { |
|
237 | - $additionalJavaScriptFiles = $this->additionalJavaScriptFiles; |
|
238 | - |
|
239 | - // Possible merge of existing javascript files. |
|
240 | - $existingConfiguration = $this->getExistingInternalConfiguration(); |
|
241 | - if (!empty($existingConfiguration['additionalJavaScriptFiles'])) { |
|
242 | - $additionalJavaScriptFiles = array_merge($additionalJavaScriptFiles, $existingConfiguration['additionalJavaScriptFiles']); |
|
243 | - } |
|
244 | - |
|
245 | - return $additionalJavaScriptFiles; |
|
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * @return array |
|
250 | - */ |
|
251 | - protected function computeAdditionalStyleSheetFiles(): array |
|
252 | - { |
|
253 | - $additionalStyleSheetFiles = $this->additionalStyleSheetFiles; |
|
254 | - |
|
255 | - // Possible merge of existing style sheets. |
|
256 | - $existingConfiguration = $this->getExistingInternalConfiguration(); |
|
257 | - if (!empty($existingConfiguration['additionalStyleSheetFiles'])) { |
|
258 | - $additionalStyleSheetFiles = array_merge($additionalStyleSheetFiles, $existingConfiguration['additionalStyleSheetFiles']); |
|
259 | - } |
|
260 | - |
|
261 | - return $additionalStyleSheetFiles; |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * @return array |
|
266 | - */ |
|
267 | - protected function computeComponents(): array |
|
268 | - { |
|
269 | - // We override the config in any case. See if we need more than that. |
|
270 | - return $this->components; |
|
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * Register the module in two places: core + vidi internal. |
|
275 | - * |
|
276 | - * @return $this |
|
277 | - */ |
|
278 | - public function register(): self |
|
279 | - { |
|
280 | - // Internal Vidi module registration. |
|
281 | - $configuration = []; |
|
282 | - $configuration['dataType'] = $this->dataType; |
|
283 | - $configuration['mainModule'] = $this->computeMainModule(); |
|
284 | - $configuration['defaultPid'] = $this->computeDefaultPid(); |
|
285 | - $configuration['additionalJavaScriptFiles'] = $this->computeAdditionalJavaScriptFiles(); |
|
286 | - $configuration['additionalStyleSheetFiles'] = $this->computeAdditionalStyleSheetFiles(); |
|
287 | - $configuration['components'] = $this->computeComponents(); |
|
288 | - $configuration['isPidIgnored'] = $this->isPidIgnored; |
|
289 | - |
|
290 | - $internalModuleSignature = $this->getInternalModuleSignature(); |
|
291 | - $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature] = $configuration; |
|
292 | - |
|
293 | - // Core module registration. |
|
294 | - // Register and displays module in the BE only if told, default is "true". |
|
295 | - if ($this->isShown) { |
|
296 | - $moduleConfiguration = []; |
|
297 | - #$moduleConfiguration['routeTarget'] = \Fab\Vidi\Controller\ContentController::class . '::mainAction', // what to do here? |
|
298 | - $moduleConfiguration['access'] = $this->getAccess(); |
|
299 | - $moduleConfiguration['labels'] = $this->getModuleLanguageFile(); |
|
300 | - $icon = $this->getIcon(); |
|
301 | - if ($icon) { |
|
302 | - $moduleConfiguration['icon'] = $icon; |
|
303 | - } |
|
304 | - |
|
305 | - if ($this->showPageTree) { |
|
306 | - $moduleConfiguration['navigationComponentId'] = 'TYPO3/CMS/Backend/PageTree/PageTreeElement'; |
|
307 | - $moduleConfiguration['inheritNavigationComponentFromMainModule'] = true; |
|
308 | - } else { |
|
309 | - $moduleConfiguration['inheritNavigationComponentFromMainModule'] = true; |
|
310 | - } |
|
311 | - |
|
312 | - ExtensionUtility::registerModule( |
|
313 | - 'Vidi', |
|
314 | - $this->computeMainModule(), |
|
315 | - $this->dataType . '_' . $this->moduleKey, |
|
316 | - $this->position, |
|
317 | - [ |
|
318 | - ContentController::class => 'index, list, delete, update, edit, copy, move, localize, sort, copyClipboard, moveClipboard', |
|
319 | - ToolController::class => 'welcome, work', |
|
320 | - FacetController::class => 'autoSuggest, autoSuggests', |
|
321 | - SelectionController::class => 'edit, update, create, delete, list, show', |
|
322 | - UserPreferencesController::class => 'save', |
|
323 | - ClipboardController::class => 'save, flush, show', |
|
324 | - ], |
|
325 | - $moduleConfiguration |
|
326 | - ); |
|
327 | - } |
|
328 | - return $this; |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * Return the module code for a BE module. |
|
333 | - * |
|
334 | - * @return string |
|
335 | - */ |
|
336 | - public function getSignature(): string |
|
337 | - { |
|
338 | - $signature = GeneralUtility::_GP(Parameter::MODULE); |
|
339 | - $trimmedSignature = trim($signature, '/'); |
|
340 | - return str_replace(['/', 'module_'], ['_', ''], $trimmedSignature); |
|
341 | - } |
|
342 | - |
|
343 | - /** |
|
344 | - * Returns the current pid. |
|
345 | - * |
|
346 | - * @return int |
|
347 | - */ |
|
348 | - public function getCurrentPid(): int |
|
349 | - { |
|
350 | - return GeneralUtility::_GET(Parameter::PID) > 0 ? (int)GeneralUtility::_GET(Parameter::PID) : 0; |
|
351 | - } |
|
352 | - |
|
353 | - /** |
|
354 | - * Return the module URL. |
|
355 | - * |
|
356 | - * @param array $additionalParameters |
|
357 | - * @return string |
|
358 | - */ |
|
359 | - public function getModuleUrl(array $additionalParameters = []): string |
|
360 | - { |
|
361 | - $moduleCode = $this->getSignature(); |
|
362 | - |
|
363 | - // And don't forget the pid! |
|
364 | - if (GeneralUtility::_GET(Parameter::PID)) { |
|
365 | - $additionalParameters[Parameter::PID] = GeneralUtility::_GET(Parameter::PID); |
|
366 | - } |
|
367 | - |
|
368 | - return BackendUtility::getModuleUrl($moduleCode, $additionalParameters); |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * Return the parameter prefix for a BE module. |
|
373 | - * |
|
374 | - * @return string |
|
375 | - */ |
|
376 | - public function getParameterPrefix(): string |
|
377 | - { |
|
378 | - return 'tx_vidi_' . strtolower($this->getSignature()); |
|
379 | - } |
|
380 | - |
|
381 | - /** |
|
382 | - * Return a configuration key or the entire module configuration array if not key is given. |
|
383 | - * |
|
384 | - * @param string $key |
|
385 | - * @return mixed |
|
386 | - */ |
|
387 | - public function getModuleConfiguration($key = '') |
|
388 | - { |
|
389 | - $vidiModuleCode = $this->getSignature(); |
|
390 | - |
|
391 | - // Module code must exist |
|
392 | - if (empty($GLOBALS['TBE_MODULES_EXT']['vidi'][$vidiModuleCode])) { |
|
393 | - $message = sprintf('Invalid or not existing module code "%s"', $vidiModuleCode); |
|
394 | - throw new InvalidKeyInArrayException($message, 1375092053); |
|
395 | - } |
|
396 | - |
|
397 | - $result = $GLOBALS['TBE_MODULES_EXT']['vidi'][$vidiModuleCode]; |
|
398 | - |
|
399 | - if (!empty($key)) { |
|
400 | - if (isset($result[$key])) { |
|
401 | - $result = $result[$key]; |
|
402 | - } else { |
|
403 | - // key must exist |
|
404 | - $message = sprintf('Invalid key configuration "%s"', $key); |
|
405 | - throw new InvalidKeyInArrayException($message, 1375092054); |
|
406 | - } |
|
407 | - } |
|
408 | - return $result; |
|
409 | - } |
|
410 | - |
|
411 | - /** |
|
412 | - * @param string $icon |
|
413 | - * @return $this |
|
414 | - */ |
|
415 | - public function setIcon($icon): self |
|
416 | - { |
|
417 | - $this->icon = $icon; |
|
418 | - return $this; |
|
419 | - } |
|
420 | - |
|
421 | - /** |
|
422 | - * @return string |
|
423 | - */ |
|
424 | - protected function getIcon(): string |
|
425 | - { |
|
426 | - $moduleConfiguration = $this->getExistingMainConfiguration(); |
|
427 | - |
|
428 | - if ($this->icon) { |
|
429 | - $icon = $this->icon; |
|
430 | - } else { |
|
431 | - $icon = $moduleConfiguration['icon'] ?? ''; |
|
432 | - } |
|
433 | - |
|
434 | - return $icon; |
|
435 | - } |
|
436 | - |
|
437 | - /** |
|
438 | - * @param string $mainModule |
|
439 | - * @return $this |
|
440 | - */ |
|
441 | - public function setMainModule($mainModule): self |
|
442 | - { |
|
443 | - $this->mainModule = $mainModule; |
|
444 | - return $this; |
|
445 | - } |
|
446 | - |
|
447 | - /** |
|
448 | - * @return string |
|
449 | - */ |
|
450 | - public function getMainModule(): string |
|
451 | - { |
|
452 | - if ($this->mainModule === null) { |
|
453 | - $this->mainModule = $this->getModuleConfiguration('mainModule'); |
|
454 | - } |
|
455 | - return $this->mainModule; |
|
456 | - } |
|
457 | - |
|
458 | - /** |
|
459 | - * @param string $moduleLanguageFile |
|
460 | - * @return $this |
|
461 | - */ |
|
462 | - public function setModuleLanguageFile($moduleLanguageFile): self |
|
463 | - { |
|
464 | - $this->moduleLanguageFile = $moduleLanguageFile; |
|
465 | - return $this; |
|
466 | - } |
|
467 | - |
|
468 | - /** |
|
469 | - * @param string $component |
|
470 | - * @return $this |
|
471 | - */ |
|
472 | - public function removeComponentFromDocHeader(string $component): self |
|
473 | - { |
|
474 | - foreach ($this->components[ModulePosition::DOC_HEADER] as $verticalPosition => $docHeaders) { |
|
475 | - foreach ($docHeaders as $horizontalPosition => $docHeader) { |
|
476 | - $index = array_search($component, $docHeader, true); |
|
477 | - if ($index !== false) { |
|
478 | - // $verticalPosition: top or bottom |
|
479 | - // $horizontalPosition: left or right |
|
480 | - unset($this->components[ModulePosition::DOC_HEADER][$verticalPosition][$horizontalPosition][$index]); |
|
481 | - } |
|
482 | - } |
|
483 | - } |
|
484 | - return $this; |
|
485 | - } |
|
486 | - |
|
487 | - /** |
|
488 | - * @param bool $isPidIgnored |
|
489 | - * @return $this |
|
490 | - */ |
|
491 | - public function ignorePid(bool $isPidIgnored): self |
|
492 | - { |
|
493 | - $this->isPidIgnored = $isPidIgnored; |
|
494 | - return $this; |
|
495 | - } |
|
496 | - |
|
497 | - /** |
|
498 | - * @return bool |
|
499 | - */ |
|
500 | - public function isPidIgnored(): bool |
|
501 | - { |
|
502 | - return $this->getModuleConfiguration('isPidIgnored'); |
|
503 | - } |
|
504 | - |
|
505 | - /** |
|
506 | - * @param string $component |
|
507 | - * @return bool |
|
508 | - */ |
|
509 | - public function hasComponentInDocHeader(string $component): bool |
|
510 | - { |
|
511 | - foreach ($this->getModuleConfiguration('components')[ModulePosition::DOC_HEADER] as $verticalPosition => $docHeaders) { |
|
512 | - foreach ($docHeaders as $horizontalPosition => $docHeader) { |
|
513 | - $index = array_search($component, $docHeader, true); |
|
514 | - if ($index !== false) { |
|
515 | - return true; |
|
516 | - } |
|
517 | - } |
|
518 | - } |
|
519 | - return false; |
|
520 | - } |
|
521 | - |
|
522 | - /** |
|
523 | - * @return string |
|
524 | - */ |
|
525 | - protected function getModuleLanguageFile(): string |
|
526 | - { |
|
527 | - $moduleConfiguration = $this->getExistingMainConfiguration(); |
|
528 | - |
|
529 | - if ($this->moduleLanguageFile) { |
|
530 | - $moduleLanguageFile = $this->moduleLanguageFile; |
|
531 | - } elseif ($moduleConfiguration['labels']) { // existing configuration may override. |
|
532 | - $moduleLanguageFile = $moduleConfiguration['labels']; |
|
533 | - } else { |
|
534 | - $moduleLanguageFile = ''; //default value. |
|
535 | - } |
|
536 | - |
|
537 | - return $moduleLanguageFile; |
|
538 | - } |
|
539 | - |
|
540 | - /** |
|
541 | - * @param string $position |
|
542 | - * @return $this |
|
543 | - */ |
|
544 | - public function setPosition($position): self |
|
545 | - { |
|
546 | - $this->position = $position; |
|
547 | - return $this; |
|
548 | - } |
|
549 | - |
|
550 | - /** |
|
551 | - * @return string |
|
552 | - */ |
|
553 | - public function getPosition(): string |
|
554 | - { |
|
555 | - return $this->position; |
|
556 | - } |
|
557 | - |
|
558 | - /** |
|
559 | - * @param array $files |
|
560 | - * @return $this |
|
561 | - */ |
|
562 | - public function addJavaScriptFiles(array $files): self |
|
563 | - { |
|
564 | - foreach ($files as $file) { |
|
565 | - $this->additionalJavaScriptFiles[] = $file; |
|
566 | - } |
|
567 | - return $this; |
|
568 | - } |
|
569 | - |
|
570 | - /** |
|
571 | - * @param string $fileNameAndPath |
|
572 | - * @return $this |
|
573 | - */ |
|
574 | - public function addJavaScriptFile($fileNameAndPath): self |
|
575 | - { |
|
576 | - $this->additionalJavaScriptFiles[] = $fileNameAndPath; |
|
577 | - return $this; |
|
578 | - } |
|
579 | - |
|
580 | - /** |
|
581 | - * @param array $files |
|
582 | - * @return $this |
|
583 | - */ |
|
584 | - public function addStyleSheetFiles(array $files): self |
|
585 | - { |
|
586 | - foreach ($files as $file) { |
|
587 | - $this->additionalStyleSheetFiles[] = $file; |
|
588 | - } |
|
589 | - return $this; |
|
590 | - } |
|
591 | - |
|
592 | - /** |
|
593 | - * @param string $fileNameAndPath |
|
594 | - * @return $this |
|
595 | - */ |
|
596 | - public function addStyleSheetFile($fileNameAndPath): self |
|
597 | - { |
|
598 | - $this->additionalStyleSheetFiles[] = $fileNameAndPath; |
|
599 | - return $this; |
|
600 | - } |
|
601 | - |
|
602 | - /** |
|
603 | - * @return string |
|
604 | - */ |
|
605 | - public function getDataType(): string |
|
606 | - { |
|
607 | - if ($this->dataType === null) { |
|
608 | - $this->dataType = $this->getModuleConfiguration('dataType'); |
|
609 | - } |
|
610 | - return $this->dataType; |
|
611 | - } |
|
612 | - |
|
613 | - /** |
|
614 | - * @return array |
|
615 | - */ |
|
616 | - public function getDataTypes(): array |
|
617 | - { |
|
618 | - $dataTypes = []; |
|
619 | - foreach ($GLOBALS['TBE_MODULES_EXT']['vidi'] as $module) { |
|
620 | - $dataTypes[] = $module['dataType']; |
|
621 | - } |
|
622 | - return $dataTypes; |
|
623 | - } |
|
624 | - |
|
625 | - /** |
|
626 | - * @param string $dataType |
|
627 | - * @return $this |
|
628 | - */ |
|
629 | - public function setDataType($dataType): self |
|
630 | - { |
|
631 | - $this->dataType = $dataType; |
|
632 | - return $this; |
|
633 | - } |
|
634 | - |
|
635 | - /** |
|
636 | - * @return int |
|
637 | - */ |
|
638 | - public function getDefaultPid(): int |
|
639 | - { |
|
640 | - if (empty($this->defaultPid)) { |
|
641 | - $this->defaultPid = $this->getModuleConfiguration('defaultPid'); |
|
642 | - } |
|
643 | - return (int)$this->defaultPid; |
|
644 | - } |
|
645 | - |
|
646 | - /** |
|
647 | - * @param string $defaultPid |
|
648 | - * @return $this |
|
649 | - */ |
|
650 | - public function setDefaultPid($defaultPid): self |
|
651 | - { |
|
652 | - $this->defaultPid = $defaultPid; |
|
653 | - return $this; |
|
654 | - } |
|
655 | - |
|
656 | - /** |
|
657 | - * @param bool $isPageTreeShown |
|
658 | - * @return $this |
|
659 | - */ |
|
660 | - public function showPageTree($isPageTreeShown): self |
|
661 | - { |
|
662 | - $this->showPageTree = $isPageTreeShown; |
|
663 | - return $this; |
|
664 | - } |
|
665 | - |
|
666 | - /** |
|
667 | - * @param string $isShown |
|
668 | - * @return $this |
|
669 | - */ |
|
670 | - public function isShown($isShown): self |
|
671 | - { |
|
672 | - $this->isShown = $isShown; |
|
673 | - return $this; |
|
674 | - } |
|
675 | - |
|
676 | - /** |
|
677 | - * @return $array |
|
678 | - */ |
|
679 | - public function getDocHeaderTopLeftComponents() |
|
680 | - { |
|
681 | - $configuration = $this->getModuleConfiguration(); |
|
682 | - return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT]; |
|
683 | - } |
|
684 | - |
|
685 | - /** |
|
686 | - * @param array $components |
|
687 | - * @return $this |
|
688 | - */ |
|
689 | - public function setDocHeaderTopLeftComponents(array $components): self |
|
690 | - { |
|
691 | - $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT] = $components; |
|
692 | - return $this; |
|
693 | - } |
|
694 | - |
|
695 | - /** |
|
696 | - * @param string|array $components |
|
697 | - * @return $this |
|
698 | - */ |
|
699 | - public function addDocHeaderTopLeftComponents($components): self |
|
700 | - { |
|
701 | - if (is_string($components)) { |
|
702 | - $components = [$components]; |
|
703 | - } |
|
704 | - $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT]; |
|
705 | - $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT] = array_merge($currentComponents, $components); |
|
706 | - return $this; |
|
707 | - } |
|
708 | - |
|
709 | - /** |
|
710 | - * @return $array |
|
711 | - */ |
|
712 | - public function getDocHeaderTopRightComponents() |
|
713 | - { |
|
714 | - $configuration = $this->getModuleConfiguration(); |
|
715 | - return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT]; |
|
716 | - } |
|
717 | - |
|
718 | - /** |
|
719 | - * @param array $components |
|
720 | - * @return $this |
|
721 | - */ |
|
722 | - public function setDocHeaderTopRightComponents(array $components): self |
|
723 | - { |
|
724 | - $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT] = $components; |
|
725 | - return $this; |
|
726 | - } |
|
727 | - |
|
728 | - /** |
|
729 | - * @param string|array $components |
|
730 | - * @return $this |
|
731 | - */ |
|
732 | - public function addDocHeaderTopRightComponents($components): self |
|
733 | - { |
|
734 | - if (is_string($components)) { |
|
735 | - $components = [$components]; |
|
736 | - } |
|
737 | - $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT]; |
|
738 | - $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT] = array_merge($currentComponents, $components); |
|
739 | - return $this; |
|
740 | - } |
|
741 | - |
|
742 | - /** |
|
743 | - * @return $array |
|
744 | - */ |
|
745 | - public function getDocHeaderBottomLeftComponents() |
|
746 | - { |
|
747 | - $configuration = $this->getModuleConfiguration(); |
|
748 | - return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT]; |
|
749 | - } |
|
750 | - |
|
751 | - /** |
|
752 | - * @param array $components |
|
753 | - * @return $this |
|
754 | - */ |
|
755 | - public function setDocHeaderBottomLeftComponents(array $components): self |
|
756 | - { |
|
757 | - $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT] = $components; |
|
758 | - return $this; |
|
759 | - } |
|
760 | - |
|
761 | - /** |
|
762 | - * @param string|array $components |
|
763 | - * @return $this |
|
764 | - */ |
|
765 | - public function addDocHeaderBottomLeftComponents($components): self |
|
766 | - { |
|
767 | - if (is_string($components)) { |
|
768 | - $components = [$components]; |
|
769 | - } |
|
770 | - $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT]; |
|
771 | - $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT] = array_merge($currentComponents, $components); |
|
772 | - return $this; |
|
773 | - } |
|
774 | - |
|
775 | - /** |
|
776 | - * @return $array |
|
777 | - */ |
|
778 | - public function getDocHeaderBottomRightComponents() |
|
779 | - { |
|
780 | - $configuration = $this->getModuleConfiguration(); |
|
781 | - return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT]; |
|
782 | - } |
|
783 | - |
|
784 | - /** |
|
785 | - * @param array $components |
|
786 | - * @return $this |
|
787 | - */ |
|
788 | - public function setDocHeaderBottomRightComponents(array $components): self |
|
789 | - { |
|
790 | - $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT] = $components; |
|
791 | - return $this; |
|
792 | - } |
|
793 | - |
|
794 | - /** |
|
795 | - * @param string|array $components |
|
796 | - * @return $this |
|
797 | - */ |
|
798 | - public function addDocHeaderBottomRightComponents($components): self |
|
799 | - { |
|
800 | - if (is_string($components)) { |
|
801 | - $components = [$components]; |
|
802 | - } |
|
803 | - $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT]; |
|
804 | - $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT] = array_merge($currentComponents, $components); |
|
805 | - return $this; |
|
806 | - } |
|
807 | - |
|
808 | - /** |
|
809 | - * @return $array |
|
810 | - */ |
|
811 | - public function getGridTopComponents() |
|
812 | - { |
|
813 | - $configuration = $this->getModuleConfiguration(); |
|
814 | - return $configuration['components'][ModulePosition::GRID][ModulePosition::TOP]; |
|
815 | - } |
|
816 | - |
|
817 | - /** |
|
818 | - * @param array $components |
|
819 | - * @return $this |
|
820 | - */ |
|
821 | - public function setGridTopComponents(array $components): self |
|
822 | - { |
|
823 | - $this->components[ModulePosition::GRID][ModulePosition::TOP] = $components; |
|
824 | - return $this; |
|
825 | - } |
|
826 | - |
|
827 | - /** |
|
828 | - * @param string|array $components |
|
829 | - * @return $this |
|
830 | - */ |
|
831 | - public function addGridTopComponents($components): self |
|
832 | - { |
|
833 | - if (is_string($components)) { |
|
834 | - $components = [$components]; |
|
835 | - } |
|
836 | - $currentComponents = $this->components[ModulePosition::GRID][ModulePosition::TOP]; |
|
837 | - $this->components[ModulePosition::GRID][ModulePosition::TOP] = array_merge($currentComponents, $components); |
|
838 | - return $this; |
|
839 | - } |
|
840 | - |
|
841 | - /** |
|
842 | - * @return mixed $array |
|
843 | - */ |
|
844 | - public function getGridBottomComponents() |
|
845 | - { |
|
846 | - $configuration = $this->getModuleConfiguration(); |
|
847 | - return $configuration['components'][ModulePosition::GRID][ModulePosition::BOTTOM]; |
|
848 | - } |
|
849 | - |
|
850 | - /** |
|
851 | - * @param array $components |
|
852 | - * @return $this |
|
853 | - */ |
|
854 | - public function setGridBottomComponents(array $components): self |
|
855 | - { |
|
856 | - $this->components[ModulePosition::GRID][ModulePosition::BOTTOM] = $components; |
|
857 | - return $this; |
|
858 | - } |
|
859 | - |
|
860 | - /** |
|
861 | - * @param string|array $components |
|
862 | - * @return $this |
|
863 | - */ |
|
864 | - public function addGridBottomComponents($components): self |
|
865 | - { |
|
866 | - if (is_string($components)) { |
|
867 | - $components = [$components]; |
|
868 | - } |
|
869 | - $currentComponents = $this->components[ModulePosition::GRID][ModulePosition::BOTTOM]; |
|
870 | - $this->components[ModulePosition::GRID][ModulePosition::BOTTOM] = array_merge($currentComponents, $components); |
|
871 | - return $this; |
|
872 | - } |
|
873 | - |
|
874 | - /** |
|
875 | - * @return $array |
|
876 | - */ |
|
877 | - public function getGridButtonsComponents() |
|
878 | - { |
|
879 | - $configuration = $this->getModuleConfiguration(); |
|
880 | - return $configuration['components'][ModulePosition::GRID][ModulePosition::BUTTONS]; |
|
881 | - } |
|
882 | - |
|
883 | - /** |
|
884 | - * @param array $components |
|
885 | - * @return $this |
|
886 | - */ |
|
887 | - public function setGridButtonsComponents(array $components): self |
|
888 | - { |
|
889 | - $this->components[ModulePosition::GRID][ModulePosition::BUTTONS] = $components; |
|
890 | - return $this; |
|
891 | - } |
|
892 | - |
|
893 | - /** |
|
894 | - * @param string|array $components |
|
895 | - * @return $this |
|
896 | - */ |
|
897 | - public function addGridButtonsComponents($components): self |
|
898 | - { |
|
899 | - if (is_string($components)) { |
|
900 | - $components = [$components]; |
|
901 | - } |
|
902 | - $currentComponents = $this->components[ModulePosition::GRID][ModulePosition::BUTTONS]; |
|
903 | - $this->components[ModulePosition::GRID][ModulePosition::BUTTONS] = array_merge($components, $currentComponents); |
|
904 | - return $this; |
|
905 | - } |
|
906 | - |
|
907 | - /** |
|
908 | - * @return $array |
|
909 | - */ |
|
910 | - public function getMenuMassActionComponents() |
|
911 | - { |
|
912 | - $configuration = $this->getModuleConfiguration(); |
|
913 | - return $configuration['components'][ModulePosition::MENU_MASS_ACTION]; |
|
914 | - } |
|
915 | - |
|
916 | - /** |
|
917 | - * @param array $components |
|
918 | - * @return $this |
|
919 | - */ |
|
920 | - public function setMenuMassActionComponents(array $components): self |
|
921 | - { |
|
922 | - $this->components[ModulePosition::MENU_MASS_ACTION] = $components; |
|
923 | - return $this; |
|
924 | - } |
|
925 | - |
|
926 | - /** |
|
927 | - * @param string|array $components |
|
928 | - * @return $this |
|
929 | - */ |
|
930 | - public function addMenuMassActionComponents($components): self |
|
931 | - { |
|
932 | - if (is_string($components)) { |
|
933 | - $components = [$components]; |
|
934 | - } |
|
935 | - $currentComponents = $this->components[ModulePosition::MENU_MASS_ACTION]; |
|
936 | - $this->components[ModulePosition::MENU_MASS_ACTION] = array_merge($components, $currentComponents); |
|
937 | - return $this; |
|
938 | - } |
|
939 | - |
|
940 | - /** |
|
941 | - * @return string |
|
942 | - */ |
|
943 | - protected function getAccess(): string |
|
944 | - { |
|
945 | - $moduleConfiguration = $this->getExistingMainConfiguration(); |
|
946 | - |
|
947 | - if ($this->access !== null) { |
|
948 | - $access = $this->access; |
|
949 | - } elseif (!empty($moduleConfiguration['access'])) { // existing configuration may override. |
|
950 | - $access = $moduleConfiguration['access']; |
|
951 | - } else { |
|
952 | - $access = Access::USER; //default value. |
|
953 | - } |
|
954 | - return $access; |
|
955 | - } |
|
956 | - |
|
957 | - /** |
|
958 | - * @param string $access |
|
959 | - * @return $this |
|
960 | - */ |
|
961 | - public function setAccess($access): self |
|
962 | - { |
|
963 | - $this->access = $access; |
|
964 | - return $this; |
|
965 | - } |
|
966 | - |
|
967 | - /** |
|
968 | - * @return \string[] |
|
969 | - */ |
|
970 | - public function getAdditionalJavaScriptFiles(): array |
|
971 | - { |
|
972 | - if (empty($this->additionalJavaScriptFiles)) { |
|
973 | - $this->additionalJavaScriptFiles = $this->getModuleConfiguration('additionalJavaScriptFiles'); |
|
974 | - } |
|
975 | - return $this->additionalJavaScriptFiles; |
|
976 | - } |
|
977 | - |
|
978 | - /** |
|
979 | - * @return \string[] |
|
980 | - */ |
|
981 | - public function getAdditionalStyleSheetFiles(): array |
|
982 | - { |
|
983 | - if (empty($this->additionalStyleSheetFiles)) { |
|
984 | - $this->additionalStyleSheetFiles = $this->getModuleConfiguration('additionalStyleSheetFiles'); |
|
985 | - } |
|
986 | - return $this->additionalStyleSheetFiles; |
|
987 | - } |
|
988 | - |
|
989 | - /** |
|
990 | - * @return array |
|
991 | - */ |
|
992 | - public function getComponents(): array |
|
993 | - { |
|
994 | - return $this->components; |
|
995 | - } |
|
996 | - |
|
997 | - /** |
|
998 | - * @param string $pluginName |
|
999 | - * @return bool |
|
1000 | - */ |
|
1001 | - public function hasPlugin($pluginName = ''): bool |
|
1002 | - { |
|
1003 | - $parameterPrefix = $this->getParameterPrefix(); |
|
1004 | - $parameters = GeneralUtility::_GET($parameterPrefix); |
|
1005 | - |
|
1006 | - $hasPlugin = !empty($parameters['plugins']) && is_array($parameters['plugins']); |
|
1007 | - if ($hasPlugin && $pluginName) { |
|
1008 | - $hasPlugin = in_array($pluginName, $parameters['plugins']); |
|
1009 | - } |
|
1010 | - return $hasPlugin; |
|
1011 | - } |
|
1012 | - |
|
1013 | - /** |
|
1014 | - * Compute the internal module code |
|
1015 | - * |
|
1016 | - * @param null|string $dataType |
|
1017 | - * @return string |
|
1018 | - */ |
|
1019 | - protected function getInternalModuleSignature($dataType = null): string |
|
1020 | - { |
|
1021 | - // Else we forge the module signature |
|
1022 | - if ($dataType === null) { |
|
1023 | - $dataType = $this->dataType; |
|
1024 | - } |
|
1025 | - $subModuleName = $dataType . '_' . $this->moduleKey; |
|
1026 | - |
|
1027 | - $mainModule = $this->mainModule ?: self::DEFAULT_MAIN_MODULE; |
|
1028 | - return $mainModule . '_Vidi' . GeneralUtility::underscoredToUpperCamelCase($subModuleName); |
|
1029 | - } |
|
38 | + /** |
|
39 | + * Define the default main module |
|
40 | + */ |
|
41 | + public const DEFAULT_MAIN_MODULE = 'content'; |
|
42 | + |
|
43 | + /** |
|
44 | + * Define the default pid |
|
45 | + */ |
|
46 | + public const DEFAULT_PID = 0; |
|
47 | + |
|
48 | + /** |
|
49 | + * The type of data being listed (which corresponds to a table name in TCA) |
|
50 | + * |
|
51 | + * @var string |
|
52 | + */ |
|
53 | + protected $dataType; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var string |
|
57 | + */ |
|
58 | + protected $defaultPid; |
|
59 | + |
|
60 | + /** |
|
61 | + * @var bool |
|
62 | + */ |
|
63 | + protected $isPidIgnored = false; |
|
64 | + |
|
65 | + /** |
|
66 | + * @var bool |
|
67 | + */ |
|
68 | + protected $showPageTree = false; |
|
69 | + |
|
70 | + /** |
|
71 | + * @var bool |
|
72 | + */ |
|
73 | + protected $isShown = true; |
|
74 | + |
|
75 | + /** |
|
76 | + * @var string |
|
77 | + */ |
|
78 | + protected $access; |
|
79 | + |
|
80 | + /** |
|
81 | + * @var string |
|
82 | + */ |
|
83 | + protected $mainModule; |
|
84 | + |
|
85 | + /** |
|
86 | + * @var string |
|
87 | + */ |
|
88 | + protected $position = ''; |
|
89 | + |
|
90 | + /** |
|
91 | + * @var string |
|
92 | + */ |
|
93 | + protected $icon; |
|
94 | + |
|
95 | + /** |
|
96 | + * @var string |
|
97 | + */ |
|
98 | + protected $moduleLanguageFile; |
|
99 | + |
|
100 | + /** |
|
101 | + * The module key such as m1, m2. |
|
102 | + * |
|
103 | + * @var string |
|
104 | + */ |
|
105 | + protected $moduleKey = 'm1'; |
|
106 | + |
|
107 | + /** |
|
108 | + * @var string[] |
|
109 | + */ |
|
110 | + protected $additionalJavaScriptFiles = []; |
|
111 | + |
|
112 | + /** |
|
113 | + * @var string[] |
|
114 | + */ |
|
115 | + protected $additionalStyleSheetFiles = []; |
|
116 | + |
|
117 | + /** |
|
118 | + * @var array |
|
119 | + */ |
|
120 | + protected $components = []; |
|
121 | + |
|
122 | + /** |
|
123 | + * @param string $dataType |
|
124 | + */ |
|
125 | + public function __construct($dataType = null) |
|
126 | + { |
|
127 | + $this->dataType = $dataType; |
|
128 | + |
|
129 | + // Initialize components |
|
130 | + $this->components = [ |
|
131 | + ModulePosition::DOC_HEADER => [ |
|
132 | + ModulePosition::TOP => [ |
|
133 | + ModulePosition::LEFT => [], |
|
134 | + ModulePosition::RIGHT => [ |
|
135 | + ToolButton::class, |
|
136 | + ], |
|
137 | + ], |
|
138 | + ModulePosition::BOTTOM => [ |
|
139 | + ModulePosition::LEFT => [ |
|
140 | + NewButton::class, |
|
141 | + BackViewHelper::class, |
|
142 | + ], |
|
143 | + ModulePosition::RIGHT => [], |
|
144 | + ], |
|
145 | + ], |
|
146 | + ModulePosition::GRID => [ |
|
147 | + ModulePosition::TOP => [ |
|
148 | + RelationsCheck::class, |
|
149 | + #\Fab\Vidi\View\Tab\DataTypeTab::class, |
|
150 | + ], |
|
151 | + ModulePosition::BUTTONS => [ |
|
152 | + EditButton::class, |
|
153 | + DeleteButton::class, |
|
154 | + ], |
|
155 | + ModulePosition::BOTTOM => [], |
|
156 | + ], |
|
157 | + ModulePosition::MENU_MASS_ACTION => [ |
|
158 | + ExportXlsMenuItem::class, |
|
159 | + ExportXmlMenuItem::class, |
|
160 | + ExportCsvMenuItem::class, |
|
161 | + DividerMenuItem::class, |
|
162 | + MassDeleteMenuItem::class, |
|
163 | + #\Fab\Vidi\View\MenuItem\MassEditMenuItem::class, |
|
164 | + ], |
|
165 | + ]; |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Tell whether a module is already registered. |
|
170 | + * |
|
171 | + * @param string $dataType |
|
172 | + * @return bool |
|
173 | + */ |
|
174 | + public function isRegistered($dataType): bool |
|
175 | + { |
|
176 | + $internalModuleSignature = $this->getInternalModuleSignature($dataType); |
|
177 | + return !empty($GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]); |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * @return array |
|
182 | + */ |
|
183 | + protected function getExistingInternalConfiguration(): array |
|
184 | + { |
|
185 | + $internalModuleSignature = $this->getInternalModuleSignature(); |
|
186 | + return $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature] ?? []; |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * @return array |
|
191 | + */ |
|
192 | + protected function getExistingMainConfiguration(): array |
|
193 | + { |
|
194 | + $moduleSignature = $this->computeMainModule() . '_' . $this->getInternalModuleSignature(); |
|
195 | + return $GLOBALS['TBE_MODULES']['_configuration'][$moduleSignature] ?? []; |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * @return string |
|
200 | + */ |
|
201 | + protected function computeMainModule(): string |
|
202 | + { |
|
203 | + $existingConfiguration = $this->getExistingInternalConfiguration(); |
|
204 | + |
|
205 | + if ($this->mainModule !== null) { |
|
206 | + $mainModule = $this->mainModule; |
|
207 | + } elseif (!empty($existingConfiguration['mainModule'])) { // existing configuration may override. |
|
208 | + $mainModule = $existingConfiguration['mainModule']; |
|
209 | + } else { |
|
210 | + $mainModule = self::DEFAULT_MAIN_MODULE; //default value. |
|
211 | + } |
|
212 | + return $mainModule; |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * @return string |
|
217 | + */ |
|
218 | + protected function computeDefaultPid(): string |
|
219 | + { |
|
220 | + $existingConfiguration = $this->getExistingInternalConfiguration(); |
|
221 | + |
|
222 | + if ($this->defaultPid !== null) { |
|
223 | + $defaultPid = $this->defaultPid; |
|
224 | + } elseif (!empty($existingConfiguration['defaultPid'])) { // existing configuration may override. |
|
225 | + $defaultPid = $existingConfiguration['defaultPid']; |
|
226 | + } else { |
|
227 | + $defaultPid = self::DEFAULT_PID; //default value. |
|
228 | + } |
|
229 | + return $defaultPid; |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * @return array |
|
234 | + */ |
|
235 | + protected function computeAdditionalJavaScriptFiles(): array |
|
236 | + { |
|
237 | + $additionalJavaScriptFiles = $this->additionalJavaScriptFiles; |
|
238 | + |
|
239 | + // Possible merge of existing javascript files. |
|
240 | + $existingConfiguration = $this->getExistingInternalConfiguration(); |
|
241 | + if (!empty($existingConfiguration['additionalJavaScriptFiles'])) { |
|
242 | + $additionalJavaScriptFiles = array_merge($additionalJavaScriptFiles, $existingConfiguration['additionalJavaScriptFiles']); |
|
243 | + } |
|
244 | + |
|
245 | + return $additionalJavaScriptFiles; |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * @return array |
|
250 | + */ |
|
251 | + protected function computeAdditionalStyleSheetFiles(): array |
|
252 | + { |
|
253 | + $additionalStyleSheetFiles = $this->additionalStyleSheetFiles; |
|
254 | + |
|
255 | + // Possible merge of existing style sheets. |
|
256 | + $existingConfiguration = $this->getExistingInternalConfiguration(); |
|
257 | + if (!empty($existingConfiguration['additionalStyleSheetFiles'])) { |
|
258 | + $additionalStyleSheetFiles = array_merge($additionalStyleSheetFiles, $existingConfiguration['additionalStyleSheetFiles']); |
|
259 | + } |
|
260 | + |
|
261 | + return $additionalStyleSheetFiles; |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * @return array |
|
266 | + */ |
|
267 | + protected function computeComponents(): array |
|
268 | + { |
|
269 | + // We override the config in any case. See if we need more than that. |
|
270 | + return $this->components; |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * Register the module in two places: core + vidi internal. |
|
275 | + * |
|
276 | + * @return $this |
|
277 | + */ |
|
278 | + public function register(): self |
|
279 | + { |
|
280 | + // Internal Vidi module registration. |
|
281 | + $configuration = []; |
|
282 | + $configuration['dataType'] = $this->dataType; |
|
283 | + $configuration['mainModule'] = $this->computeMainModule(); |
|
284 | + $configuration['defaultPid'] = $this->computeDefaultPid(); |
|
285 | + $configuration['additionalJavaScriptFiles'] = $this->computeAdditionalJavaScriptFiles(); |
|
286 | + $configuration['additionalStyleSheetFiles'] = $this->computeAdditionalStyleSheetFiles(); |
|
287 | + $configuration['components'] = $this->computeComponents(); |
|
288 | + $configuration['isPidIgnored'] = $this->isPidIgnored; |
|
289 | + |
|
290 | + $internalModuleSignature = $this->getInternalModuleSignature(); |
|
291 | + $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature] = $configuration; |
|
292 | + |
|
293 | + // Core module registration. |
|
294 | + // Register and displays module in the BE only if told, default is "true". |
|
295 | + if ($this->isShown) { |
|
296 | + $moduleConfiguration = []; |
|
297 | + #$moduleConfiguration['routeTarget'] = \Fab\Vidi\Controller\ContentController::class . '::mainAction', // what to do here? |
|
298 | + $moduleConfiguration['access'] = $this->getAccess(); |
|
299 | + $moduleConfiguration['labels'] = $this->getModuleLanguageFile(); |
|
300 | + $icon = $this->getIcon(); |
|
301 | + if ($icon) { |
|
302 | + $moduleConfiguration['icon'] = $icon; |
|
303 | + } |
|
304 | + |
|
305 | + if ($this->showPageTree) { |
|
306 | + $moduleConfiguration['navigationComponentId'] = 'TYPO3/CMS/Backend/PageTree/PageTreeElement'; |
|
307 | + $moduleConfiguration['inheritNavigationComponentFromMainModule'] = true; |
|
308 | + } else { |
|
309 | + $moduleConfiguration['inheritNavigationComponentFromMainModule'] = true; |
|
310 | + } |
|
311 | + |
|
312 | + ExtensionUtility::registerModule( |
|
313 | + 'Vidi', |
|
314 | + $this->computeMainModule(), |
|
315 | + $this->dataType . '_' . $this->moduleKey, |
|
316 | + $this->position, |
|
317 | + [ |
|
318 | + ContentController::class => 'index, list, delete, update, edit, copy, move, localize, sort, copyClipboard, moveClipboard', |
|
319 | + ToolController::class => 'welcome, work', |
|
320 | + FacetController::class => 'autoSuggest, autoSuggests', |
|
321 | + SelectionController::class => 'edit, update, create, delete, list, show', |
|
322 | + UserPreferencesController::class => 'save', |
|
323 | + ClipboardController::class => 'save, flush, show', |
|
324 | + ], |
|
325 | + $moduleConfiguration |
|
326 | + ); |
|
327 | + } |
|
328 | + return $this; |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * Return the module code for a BE module. |
|
333 | + * |
|
334 | + * @return string |
|
335 | + */ |
|
336 | + public function getSignature(): string |
|
337 | + { |
|
338 | + $signature = GeneralUtility::_GP(Parameter::MODULE); |
|
339 | + $trimmedSignature = trim($signature, '/'); |
|
340 | + return str_replace(['/', 'module_'], ['_', ''], $trimmedSignature); |
|
341 | + } |
|
342 | + |
|
343 | + /** |
|
344 | + * Returns the current pid. |
|
345 | + * |
|
346 | + * @return int |
|
347 | + */ |
|
348 | + public function getCurrentPid(): int |
|
349 | + { |
|
350 | + return GeneralUtility::_GET(Parameter::PID) > 0 ? (int)GeneralUtility::_GET(Parameter::PID) : 0; |
|
351 | + } |
|
352 | + |
|
353 | + /** |
|
354 | + * Return the module URL. |
|
355 | + * |
|
356 | + * @param array $additionalParameters |
|
357 | + * @return string |
|
358 | + */ |
|
359 | + public function getModuleUrl(array $additionalParameters = []): string |
|
360 | + { |
|
361 | + $moduleCode = $this->getSignature(); |
|
362 | + |
|
363 | + // And don't forget the pid! |
|
364 | + if (GeneralUtility::_GET(Parameter::PID)) { |
|
365 | + $additionalParameters[Parameter::PID] = GeneralUtility::_GET(Parameter::PID); |
|
366 | + } |
|
367 | + |
|
368 | + return BackendUtility::getModuleUrl($moduleCode, $additionalParameters); |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * Return the parameter prefix for a BE module. |
|
373 | + * |
|
374 | + * @return string |
|
375 | + */ |
|
376 | + public function getParameterPrefix(): string |
|
377 | + { |
|
378 | + return 'tx_vidi_' . strtolower($this->getSignature()); |
|
379 | + } |
|
380 | + |
|
381 | + /** |
|
382 | + * Return a configuration key or the entire module configuration array if not key is given. |
|
383 | + * |
|
384 | + * @param string $key |
|
385 | + * @return mixed |
|
386 | + */ |
|
387 | + public function getModuleConfiguration($key = '') |
|
388 | + { |
|
389 | + $vidiModuleCode = $this->getSignature(); |
|
390 | + |
|
391 | + // Module code must exist |
|
392 | + if (empty($GLOBALS['TBE_MODULES_EXT']['vidi'][$vidiModuleCode])) { |
|
393 | + $message = sprintf('Invalid or not existing module code "%s"', $vidiModuleCode); |
|
394 | + throw new InvalidKeyInArrayException($message, 1375092053); |
|
395 | + } |
|
396 | + |
|
397 | + $result = $GLOBALS['TBE_MODULES_EXT']['vidi'][$vidiModuleCode]; |
|
398 | + |
|
399 | + if (!empty($key)) { |
|
400 | + if (isset($result[$key])) { |
|
401 | + $result = $result[$key]; |
|
402 | + } else { |
|
403 | + // key must exist |
|
404 | + $message = sprintf('Invalid key configuration "%s"', $key); |
|
405 | + throw new InvalidKeyInArrayException($message, 1375092054); |
|
406 | + } |
|
407 | + } |
|
408 | + return $result; |
|
409 | + } |
|
410 | + |
|
411 | + /** |
|
412 | + * @param string $icon |
|
413 | + * @return $this |
|
414 | + */ |
|
415 | + public function setIcon($icon): self |
|
416 | + { |
|
417 | + $this->icon = $icon; |
|
418 | + return $this; |
|
419 | + } |
|
420 | + |
|
421 | + /** |
|
422 | + * @return string |
|
423 | + */ |
|
424 | + protected function getIcon(): string |
|
425 | + { |
|
426 | + $moduleConfiguration = $this->getExistingMainConfiguration(); |
|
427 | + |
|
428 | + if ($this->icon) { |
|
429 | + $icon = $this->icon; |
|
430 | + } else { |
|
431 | + $icon = $moduleConfiguration['icon'] ?? ''; |
|
432 | + } |
|
433 | + |
|
434 | + return $icon; |
|
435 | + } |
|
436 | + |
|
437 | + /** |
|
438 | + * @param string $mainModule |
|
439 | + * @return $this |
|
440 | + */ |
|
441 | + public function setMainModule($mainModule): self |
|
442 | + { |
|
443 | + $this->mainModule = $mainModule; |
|
444 | + return $this; |
|
445 | + } |
|
446 | + |
|
447 | + /** |
|
448 | + * @return string |
|
449 | + */ |
|
450 | + public function getMainModule(): string |
|
451 | + { |
|
452 | + if ($this->mainModule === null) { |
|
453 | + $this->mainModule = $this->getModuleConfiguration('mainModule'); |
|
454 | + } |
|
455 | + return $this->mainModule; |
|
456 | + } |
|
457 | + |
|
458 | + /** |
|
459 | + * @param string $moduleLanguageFile |
|
460 | + * @return $this |
|
461 | + */ |
|
462 | + public function setModuleLanguageFile($moduleLanguageFile): self |
|
463 | + { |
|
464 | + $this->moduleLanguageFile = $moduleLanguageFile; |
|
465 | + return $this; |
|
466 | + } |
|
467 | + |
|
468 | + /** |
|
469 | + * @param string $component |
|
470 | + * @return $this |
|
471 | + */ |
|
472 | + public function removeComponentFromDocHeader(string $component): self |
|
473 | + { |
|
474 | + foreach ($this->components[ModulePosition::DOC_HEADER] as $verticalPosition => $docHeaders) { |
|
475 | + foreach ($docHeaders as $horizontalPosition => $docHeader) { |
|
476 | + $index = array_search($component, $docHeader, true); |
|
477 | + if ($index !== false) { |
|
478 | + // $verticalPosition: top or bottom |
|
479 | + // $horizontalPosition: left or right |
|
480 | + unset($this->components[ModulePosition::DOC_HEADER][$verticalPosition][$horizontalPosition][$index]); |
|
481 | + } |
|
482 | + } |
|
483 | + } |
|
484 | + return $this; |
|
485 | + } |
|
486 | + |
|
487 | + /** |
|
488 | + * @param bool $isPidIgnored |
|
489 | + * @return $this |
|
490 | + */ |
|
491 | + public function ignorePid(bool $isPidIgnored): self |
|
492 | + { |
|
493 | + $this->isPidIgnored = $isPidIgnored; |
|
494 | + return $this; |
|
495 | + } |
|
496 | + |
|
497 | + /** |
|
498 | + * @return bool |
|
499 | + */ |
|
500 | + public function isPidIgnored(): bool |
|
501 | + { |
|
502 | + return $this->getModuleConfiguration('isPidIgnored'); |
|
503 | + } |
|
504 | + |
|
505 | + /** |
|
506 | + * @param string $component |
|
507 | + * @return bool |
|
508 | + */ |
|
509 | + public function hasComponentInDocHeader(string $component): bool |
|
510 | + { |
|
511 | + foreach ($this->getModuleConfiguration('components')[ModulePosition::DOC_HEADER] as $verticalPosition => $docHeaders) { |
|
512 | + foreach ($docHeaders as $horizontalPosition => $docHeader) { |
|
513 | + $index = array_search($component, $docHeader, true); |
|
514 | + if ($index !== false) { |
|
515 | + return true; |
|
516 | + } |
|
517 | + } |
|
518 | + } |
|
519 | + return false; |
|
520 | + } |
|
521 | + |
|
522 | + /** |
|
523 | + * @return string |
|
524 | + */ |
|
525 | + protected function getModuleLanguageFile(): string |
|
526 | + { |
|
527 | + $moduleConfiguration = $this->getExistingMainConfiguration(); |
|
528 | + |
|
529 | + if ($this->moduleLanguageFile) { |
|
530 | + $moduleLanguageFile = $this->moduleLanguageFile; |
|
531 | + } elseif ($moduleConfiguration['labels']) { // existing configuration may override. |
|
532 | + $moduleLanguageFile = $moduleConfiguration['labels']; |
|
533 | + } else { |
|
534 | + $moduleLanguageFile = ''; //default value. |
|
535 | + } |
|
536 | + |
|
537 | + return $moduleLanguageFile; |
|
538 | + } |
|
539 | + |
|
540 | + /** |
|
541 | + * @param string $position |
|
542 | + * @return $this |
|
543 | + */ |
|
544 | + public function setPosition($position): self |
|
545 | + { |
|
546 | + $this->position = $position; |
|
547 | + return $this; |
|
548 | + } |
|
549 | + |
|
550 | + /** |
|
551 | + * @return string |
|
552 | + */ |
|
553 | + public function getPosition(): string |
|
554 | + { |
|
555 | + return $this->position; |
|
556 | + } |
|
557 | + |
|
558 | + /** |
|
559 | + * @param array $files |
|
560 | + * @return $this |
|
561 | + */ |
|
562 | + public function addJavaScriptFiles(array $files): self |
|
563 | + { |
|
564 | + foreach ($files as $file) { |
|
565 | + $this->additionalJavaScriptFiles[] = $file; |
|
566 | + } |
|
567 | + return $this; |
|
568 | + } |
|
569 | + |
|
570 | + /** |
|
571 | + * @param string $fileNameAndPath |
|
572 | + * @return $this |
|
573 | + */ |
|
574 | + public function addJavaScriptFile($fileNameAndPath): self |
|
575 | + { |
|
576 | + $this->additionalJavaScriptFiles[] = $fileNameAndPath; |
|
577 | + return $this; |
|
578 | + } |
|
579 | + |
|
580 | + /** |
|
581 | + * @param array $files |
|
582 | + * @return $this |
|
583 | + */ |
|
584 | + public function addStyleSheetFiles(array $files): self |
|
585 | + { |
|
586 | + foreach ($files as $file) { |
|
587 | + $this->additionalStyleSheetFiles[] = $file; |
|
588 | + } |
|
589 | + return $this; |
|
590 | + } |
|
591 | + |
|
592 | + /** |
|
593 | + * @param string $fileNameAndPath |
|
594 | + * @return $this |
|
595 | + */ |
|
596 | + public function addStyleSheetFile($fileNameAndPath): self |
|
597 | + { |
|
598 | + $this->additionalStyleSheetFiles[] = $fileNameAndPath; |
|
599 | + return $this; |
|
600 | + } |
|
601 | + |
|
602 | + /** |
|
603 | + * @return string |
|
604 | + */ |
|
605 | + public function getDataType(): string |
|
606 | + { |
|
607 | + if ($this->dataType === null) { |
|
608 | + $this->dataType = $this->getModuleConfiguration('dataType'); |
|
609 | + } |
|
610 | + return $this->dataType; |
|
611 | + } |
|
612 | + |
|
613 | + /** |
|
614 | + * @return array |
|
615 | + */ |
|
616 | + public function getDataTypes(): array |
|
617 | + { |
|
618 | + $dataTypes = []; |
|
619 | + foreach ($GLOBALS['TBE_MODULES_EXT']['vidi'] as $module) { |
|
620 | + $dataTypes[] = $module['dataType']; |
|
621 | + } |
|
622 | + return $dataTypes; |
|
623 | + } |
|
624 | + |
|
625 | + /** |
|
626 | + * @param string $dataType |
|
627 | + * @return $this |
|
628 | + */ |
|
629 | + public function setDataType($dataType): self |
|
630 | + { |
|
631 | + $this->dataType = $dataType; |
|
632 | + return $this; |
|
633 | + } |
|
634 | + |
|
635 | + /** |
|
636 | + * @return int |
|
637 | + */ |
|
638 | + public function getDefaultPid(): int |
|
639 | + { |
|
640 | + if (empty($this->defaultPid)) { |
|
641 | + $this->defaultPid = $this->getModuleConfiguration('defaultPid'); |
|
642 | + } |
|
643 | + return (int)$this->defaultPid; |
|
644 | + } |
|
645 | + |
|
646 | + /** |
|
647 | + * @param string $defaultPid |
|
648 | + * @return $this |
|
649 | + */ |
|
650 | + public function setDefaultPid($defaultPid): self |
|
651 | + { |
|
652 | + $this->defaultPid = $defaultPid; |
|
653 | + return $this; |
|
654 | + } |
|
655 | + |
|
656 | + /** |
|
657 | + * @param bool $isPageTreeShown |
|
658 | + * @return $this |
|
659 | + */ |
|
660 | + public function showPageTree($isPageTreeShown): self |
|
661 | + { |
|
662 | + $this->showPageTree = $isPageTreeShown; |
|
663 | + return $this; |
|
664 | + } |
|
665 | + |
|
666 | + /** |
|
667 | + * @param string $isShown |
|
668 | + * @return $this |
|
669 | + */ |
|
670 | + public function isShown($isShown): self |
|
671 | + { |
|
672 | + $this->isShown = $isShown; |
|
673 | + return $this; |
|
674 | + } |
|
675 | + |
|
676 | + /** |
|
677 | + * @return $array |
|
678 | + */ |
|
679 | + public function getDocHeaderTopLeftComponents() |
|
680 | + { |
|
681 | + $configuration = $this->getModuleConfiguration(); |
|
682 | + return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT]; |
|
683 | + } |
|
684 | + |
|
685 | + /** |
|
686 | + * @param array $components |
|
687 | + * @return $this |
|
688 | + */ |
|
689 | + public function setDocHeaderTopLeftComponents(array $components): self |
|
690 | + { |
|
691 | + $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT] = $components; |
|
692 | + return $this; |
|
693 | + } |
|
694 | + |
|
695 | + /** |
|
696 | + * @param string|array $components |
|
697 | + * @return $this |
|
698 | + */ |
|
699 | + public function addDocHeaderTopLeftComponents($components): self |
|
700 | + { |
|
701 | + if (is_string($components)) { |
|
702 | + $components = [$components]; |
|
703 | + } |
|
704 | + $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT]; |
|
705 | + $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT] = array_merge($currentComponents, $components); |
|
706 | + return $this; |
|
707 | + } |
|
708 | + |
|
709 | + /** |
|
710 | + * @return $array |
|
711 | + */ |
|
712 | + public function getDocHeaderTopRightComponents() |
|
713 | + { |
|
714 | + $configuration = $this->getModuleConfiguration(); |
|
715 | + return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT]; |
|
716 | + } |
|
717 | + |
|
718 | + /** |
|
719 | + * @param array $components |
|
720 | + * @return $this |
|
721 | + */ |
|
722 | + public function setDocHeaderTopRightComponents(array $components): self |
|
723 | + { |
|
724 | + $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT] = $components; |
|
725 | + return $this; |
|
726 | + } |
|
727 | + |
|
728 | + /** |
|
729 | + * @param string|array $components |
|
730 | + * @return $this |
|
731 | + */ |
|
732 | + public function addDocHeaderTopRightComponents($components): self |
|
733 | + { |
|
734 | + if (is_string($components)) { |
|
735 | + $components = [$components]; |
|
736 | + } |
|
737 | + $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT]; |
|
738 | + $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT] = array_merge($currentComponents, $components); |
|
739 | + return $this; |
|
740 | + } |
|
741 | + |
|
742 | + /** |
|
743 | + * @return $array |
|
744 | + */ |
|
745 | + public function getDocHeaderBottomLeftComponents() |
|
746 | + { |
|
747 | + $configuration = $this->getModuleConfiguration(); |
|
748 | + return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT]; |
|
749 | + } |
|
750 | + |
|
751 | + /** |
|
752 | + * @param array $components |
|
753 | + * @return $this |
|
754 | + */ |
|
755 | + public function setDocHeaderBottomLeftComponents(array $components): self |
|
756 | + { |
|
757 | + $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT] = $components; |
|
758 | + return $this; |
|
759 | + } |
|
760 | + |
|
761 | + /** |
|
762 | + * @param string|array $components |
|
763 | + * @return $this |
|
764 | + */ |
|
765 | + public function addDocHeaderBottomLeftComponents($components): self |
|
766 | + { |
|
767 | + if (is_string($components)) { |
|
768 | + $components = [$components]; |
|
769 | + } |
|
770 | + $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT]; |
|
771 | + $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT] = array_merge($currentComponents, $components); |
|
772 | + return $this; |
|
773 | + } |
|
774 | + |
|
775 | + /** |
|
776 | + * @return $array |
|
777 | + */ |
|
778 | + public function getDocHeaderBottomRightComponents() |
|
779 | + { |
|
780 | + $configuration = $this->getModuleConfiguration(); |
|
781 | + return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT]; |
|
782 | + } |
|
783 | + |
|
784 | + /** |
|
785 | + * @param array $components |
|
786 | + * @return $this |
|
787 | + */ |
|
788 | + public function setDocHeaderBottomRightComponents(array $components): self |
|
789 | + { |
|
790 | + $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT] = $components; |
|
791 | + return $this; |
|
792 | + } |
|
793 | + |
|
794 | + /** |
|
795 | + * @param string|array $components |
|
796 | + * @return $this |
|
797 | + */ |
|
798 | + public function addDocHeaderBottomRightComponents($components): self |
|
799 | + { |
|
800 | + if (is_string($components)) { |
|
801 | + $components = [$components]; |
|
802 | + } |
|
803 | + $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT]; |
|
804 | + $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT] = array_merge($currentComponents, $components); |
|
805 | + return $this; |
|
806 | + } |
|
807 | + |
|
808 | + /** |
|
809 | + * @return $array |
|
810 | + */ |
|
811 | + public function getGridTopComponents() |
|
812 | + { |
|
813 | + $configuration = $this->getModuleConfiguration(); |
|
814 | + return $configuration['components'][ModulePosition::GRID][ModulePosition::TOP]; |
|
815 | + } |
|
816 | + |
|
817 | + /** |
|
818 | + * @param array $components |
|
819 | + * @return $this |
|
820 | + */ |
|
821 | + public function setGridTopComponents(array $components): self |
|
822 | + { |
|
823 | + $this->components[ModulePosition::GRID][ModulePosition::TOP] = $components; |
|
824 | + return $this; |
|
825 | + } |
|
826 | + |
|
827 | + /** |
|
828 | + * @param string|array $components |
|
829 | + * @return $this |
|
830 | + */ |
|
831 | + public function addGridTopComponents($components): self |
|
832 | + { |
|
833 | + if (is_string($components)) { |
|
834 | + $components = [$components]; |
|
835 | + } |
|
836 | + $currentComponents = $this->components[ModulePosition::GRID][ModulePosition::TOP]; |
|
837 | + $this->components[ModulePosition::GRID][ModulePosition::TOP] = array_merge($currentComponents, $components); |
|
838 | + return $this; |
|
839 | + } |
|
840 | + |
|
841 | + /** |
|
842 | + * @return mixed $array |
|
843 | + */ |
|
844 | + public function getGridBottomComponents() |
|
845 | + { |
|
846 | + $configuration = $this->getModuleConfiguration(); |
|
847 | + return $configuration['components'][ModulePosition::GRID][ModulePosition::BOTTOM]; |
|
848 | + } |
|
849 | + |
|
850 | + /** |
|
851 | + * @param array $components |
|
852 | + * @return $this |
|
853 | + */ |
|
854 | + public function setGridBottomComponents(array $components): self |
|
855 | + { |
|
856 | + $this->components[ModulePosition::GRID][ModulePosition::BOTTOM] = $components; |
|
857 | + return $this; |
|
858 | + } |
|
859 | + |
|
860 | + /** |
|
861 | + * @param string|array $components |
|
862 | + * @return $this |
|
863 | + */ |
|
864 | + public function addGridBottomComponents($components): self |
|
865 | + { |
|
866 | + if (is_string($components)) { |
|
867 | + $components = [$components]; |
|
868 | + } |
|
869 | + $currentComponents = $this->components[ModulePosition::GRID][ModulePosition::BOTTOM]; |
|
870 | + $this->components[ModulePosition::GRID][ModulePosition::BOTTOM] = array_merge($currentComponents, $components); |
|
871 | + return $this; |
|
872 | + } |
|
873 | + |
|
874 | + /** |
|
875 | + * @return $array |
|
876 | + */ |
|
877 | + public function getGridButtonsComponents() |
|
878 | + { |
|
879 | + $configuration = $this->getModuleConfiguration(); |
|
880 | + return $configuration['components'][ModulePosition::GRID][ModulePosition::BUTTONS]; |
|
881 | + } |
|
882 | + |
|
883 | + /** |
|
884 | + * @param array $components |
|
885 | + * @return $this |
|
886 | + */ |
|
887 | + public function setGridButtonsComponents(array $components): self |
|
888 | + { |
|
889 | + $this->components[ModulePosition::GRID][ModulePosition::BUTTONS] = $components; |
|
890 | + return $this; |
|
891 | + } |
|
892 | + |
|
893 | + /** |
|
894 | + * @param string|array $components |
|
895 | + * @return $this |
|
896 | + */ |
|
897 | + public function addGridButtonsComponents($components): self |
|
898 | + { |
|
899 | + if (is_string($components)) { |
|
900 | + $components = [$components]; |
|
901 | + } |
|
902 | + $currentComponents = $this->components[ModulePosition::GRID][ModulePosition::BUTTONS]; |
|
903 | + $this->components[ModulePosition::GRID][ModulePosition::BUTTONS] = array_merge($components, $currentComponents); |
|
904 | + return $this; |
|
905 | + } |
|
906 | + |
|
907 | + /** |
|
908 | + * @return $array |
|
909 | + */ |
|
910 | + public function getMenuMassActionComponents() |
|
911 | + { |
|
912 | + $configuration = $this->getModuleConfiguration(); |
|
913 | + return $configuration['components'][ModulePosition::MENU_MASS_ACTION]; |
|
914 | + } |
|
915 | + |
|
916 | + /** |
|
917 | + * @param array $components |
|
918 | + * @return $this |
|
919 | + */ |
|
920 | + public function setMenuMassActionComponents(array $components): self |
|
921 | + { |
|
922 | + $this->components[ModulePosition::MENU_MASS_ACTION] = $components; |
|
923 | + return $this; |
|
924 | + } |
|
925 | + |
|
926 | + /** |
|
927 | + * @param string|array $components |
|
928 | + * @return $this |
|
929 | + */ |
|
930 | + public function addMenuMassActionComponents($components): self |
|
931 | + { |
|
932 | + if (is_string($components)) { |
|
933 | + $components = [$components]; |
|
934 | + } |
|
935 | + $currentComponents = $this->components[ModulePosition::MENU_MASS_ACTION]; |
|
936 | + $this->components[ModulePosition::MENU_MASS_ACTION] = array_merge($components, $currentComponents); |
|
937 | + return $this; |
|
938 | + } |
|
939 | + |
|
940 | + /** |
|
941 | + * @return string |
|
942 | + */ |
|
943 | + protected function getAccess(): string |
|
944 | + { |
|
945 | + $moduleConfiguration = $this->getExistingMainConfiguration(); |
|
946 | + |
|
947 | + if ($this->access !== null) { |
|
948 | + $access = $this->access; |
|
949 | + } elseif (!empty($moduleConfiguration['access'])) { // existing configuration may override. |
|
950 | + $access = $moduleConfiguration['access']; |
|
951 | + } else { |
|
952 | + $access = Access::USER; //default value. |
|
953 | + } |
|
954 | + return $access; |
|
955 | + } |
|
956 | + |
|
957 | + /** |
|
958 | + * @param string $access |
|
959 | + * @return $this |
|
960 | + */ |
|
961 | + public function setAccess($access): self |
|
962 | + { |
|
963 | + $this->access = $access; |
|
964 | + return $this; |
|
965 | + } |
|
966 | + |
|
967 | + /** |
|
968 | + * @return \string[] |
|
969 | + */ |
|
970 | + public function getAdditionalJavaScriptFiles(): array |
|
971 | + { |
|
972 | + if (empty($this->additionalJavaScriptFiles)) { |
|
973 | + $this->additionalJavaScriptFiles = $this->getModuleConfiguration('additionalJavaScriptFiles'); |
|
974 | + } |
|
975 | + return $this->additionalJavaScriptFiles; |
|
976 | + } |
|
977 | + |
|
978 | + /** |
|
979 | + * @return \string[] |
|
980 | + */ |
|
981 | + public function getAdditionalStyleSheetFiles(): array |
|
982 | + { |
|
983 | + if (empty($this->additionalStyleSheetFiles)) { |
|
984 | + $this->additionalStyleSheetFiles = $this->getModuleConfiguration('additionalStyleSheetFiles'); |
|
985 | + } |
|
986 | + return $this->additionalStyleSheetFiles; |
|
987 | + } |
|
988 | + |
|
989 | + /** |
|
990 | + * @return array |
|
991 | + */ |
|
992 | + public function getComponents(): array |
|
993 | + { |
|
994 | + return $this->components; |
|
995 | + } |
|
996 | + |
|
997 | + /** |
|
998 | + * @param string $pluginName |
|
999 | + * @return bool |
|
1000 | + */ |
|
1001 | + public function hasPlugin($pluginName = ''): bool |
|
1002 | + { |
|
1003 | + $parameterPrefix = $this->getParameterPrefix(); |
|
1004 | + $parameters = GeneralUtility::_GET($parameterPrefix); |
|
1005 | + |
|
1006 | + $hasPlugin = !empty($parameters['plugins']) && is_array($parameters['plugins']); |
|
1007 | + if ($hasPlugin && $pluginName) { |
|
1008 | + $hasPlugin = in_array($pluginName, $parameters['plugins']); |
|
1009 | + } |
|
1010 | + return $hasPlugin; |
|
1011 | + } |
|
1012 | + |
|
1013 | + /** |
|
1014 | + * Compute the internal module code |
|
1015 | + * |
|
1016 | + * @param null|string $dataType |
|
1017 | + * @return string |
|
1018 | + */ |
|
1019 | + protected function getInternalModuleSignature($dataType = null): string |
|
1020 | + { |
|
1021 | + // Else we forge the module signature |
|
1022 | + if ($dataType === null) { |
|
1023 | + $dataType = $this->dataType; |
|
1024 | + } |
|
1025 | + $subModuleName = $dataType . '_' . $this->moduleKey; |
|
1026 | + |
|
1027 | + $mainModule = $this->mainModule ?: self::DEFAULT_MAIN_MODULE; |
|
1028 | + return $mainModule . '_Vidi' . GeneralUtility::underscoredToUpperCamelCase($subModuleName); |
|
1029 | + } |
|
1030 | 1030 | } |
@@ -44,7 +44,7 @@ |
||
44 | 44 | ->setDataAttributes([ |
45 | 45 | 'toggle' => 'tooltip', |
46 | 46 | ]) |
47 | - ->setTitle($this->getLabelService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:' . $label)) |
|
47 | + ->setTitle($this->getLabelService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:'.$label)) |
|
48 | 48 | ->setIcon($this->getIconFactory()->getIcon($spriteName, Icon::SIZE_SMALL)) |
49 | 49 | ->render(); |
50 | 50 | } |
@@ -21,80 +21,80 @@ |
||
21 | 21 | */ |
22 | 22 | class VisibilityRenderer extends ColumnRendererAbstract |
23 | 23 | { |
24 | - /** |
|
25 | - * Render visibility for the Grid. |
|
26 | - * |
|
27 | - * @return string |
|
28 | - */ |
|
29 | - public function render() |
|
30 | - { |
|
31 | - $output = ''; |
|
32 | - $hiddenField = Tca::table()->getHiddenField(); |
|
24 | + /** |
|
25 | + * Render visibility for the Grid. |
|
26 | + * |
|
27 | + * @return string |
|
28 | + */ |
|
29 | + public function render() |
|
30 | + { |
|
31 | + $output = ''; |
|
32 | + $hiddenField = Tca::table()->getHiddenField(); |
|
33 | 33 | |
34 | - if ($hiddenField) { |
|
35 | - $spriteName = $this->object[$hiddenField] ? 'actions-edit-unhide' : 'actions-edit-hide'; |
|
34 | + if ($hiddenField) { |
|
35 | + $spriteName = $this->object[$hiddenField] ? 'actions-edit-unhide' : 'actions-edit-hide'; |
|
36 | 36 | |
37 | - $label = $this->object[$hiddenField] ? 'unHide' : 'hide'; |
|
37 | + $label = $this->object[$hiddenField] ? 'unHide' : 'hide'; |
|
38 | 38 | |
39 | - $output = $this->makeLinkButton() |
|
40 | - ->setHref($this->getEditUri($this->object)) |
|
41 | - ->setClasses('btn-visibility-toggle') |
|
42 | - ->setDataAttributes([ |
|
43 | - 'toggle' => 'tooltip', |
|
44 | - ]) |
|
45 | - ->setTitle($this->getLabelService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:' . $label)) |
|
46 | - ->setIcon($this->getIconFactory()->getIcon($spriteName, Icon::SIZE_SMALL)) |
|
47 | - ->render(); |
|
48 | - } |
|
49 | - return $output; |
|
50 | - } |
|
39 | + $output = $this->makeLinkButton() |
|
40 | + ->setHref($this->getEditUri($this->object)) |
|
41 | + ->setClasses('btn-visibility-toggle') |
|
42 | + ->setDataAttributes([ |
|
43 | + 'toggle' => 'tooltip', |
|
44 | + ]) |
|
45 | + ->setTitle($this->getLabelService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:' . $label)) |
|
46 | + ->setIcon($this->getIconFactory()->getIcon($spriteName, Icon::SIZE_SMALL)) |
|
47 | + ->render(); |
|
48 | + } |
|
49 | + return $output; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @param Content $object |
|
54 | - * @return string |
|
55 | - */ |
|
56 | - protected function getEditUri(Content $object) |
|
57 | - { |
|
58 | - $hiddenField = Tca::table()->getHiddenField(); |
|
52 | + /** |
|
53 | + * @param Content $object |
|
54 | + * @return string |
|
55 | + */ |
|
56 | + protected function getEditUri(Content $object) |
|
57 | + { |
|
58 | + $hiddenField = Tca::table()->getHiddenField(); |
|
59 | 59 | |
60 | - $additionalParameters = array( |
|
61 | - $this->getModuleLoader()->getParameterPrefix() => [ |
|
62 | - 'controller' => 'Content', |
|
63 | - 'action' => 'update', |
|
64 | - 'format' => 'json', |
|
65 | - 'fieldNameAndPath' => Tca::table()->getHiddenField(), |
|
66 | - 'matches' => [ |
|
67 | - 'uid' => $object->getUid(), |
|
68 | - ], |
|
69 | - 'content' => [$hiddenField => (int)!$this->object[$hiddenField]], |
|
70 | - ], |
|
71 | - ); |
|
60 | + $additionalParameters = array( |
|
61 | + $this->getModuleLoader()->getParameterPrefix() => [ |
|
62 | + 'controller' => 'Content', |
|
63 | + 'action' => 'update', |
|
64 | + 'format' => 'json', |
|
65 | + 'fieldNameAndPath' => Tca::table()->getHiddenField(), |
|
66 | + 'matches' => [ |
|
67 | + 'uid' => $object->getUid(), |
|
68 | + ], |
|
69 | + 'content' => [$hiddenField => (int)!$this->object[$hiddenField]], |
|
70 | + ], |
|
71 | + ); |
|
72 | 72 | |
73 | - return $this->getModuleLoader()->getModuleUrl($additionalParameters); |
|
74 | - } |
|
73 | + return $this->getModuleLoader()->getModuleUrl($additionalParameters); |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * @return LinkButton |
|
78 | - */ |
|
79 | - protected function makeLinkButton() |
|
80 | - { |
|
81 | - return GeneralUtility::makeInstance(LinkButton::class); |
|
82 | - } |
|
76 | + /** |
|
77 | + * @return LinkButton |
|
78 | + */ |
|
79 | + protected function makeLinkButton() |
|
80 | + { |
|
81 | + return GeneralUtility::makeInstance(LinkButton::class); |
|
82 | + } |
|
83 | 83 | |
84 | 84 | |
85 | - /** |
|
86 | - * @return IconFactory |
|
87 | - */ |
|
88 | - protected function getIconFactory() |
|
89 | - { |
|
90 | - return GeneralUtility::makeInstance(IconFactory::class); |
|
91 | - } |
|
85 | + /** |
|
86 | + * @return IconFactory |
|
87 | + */ |
|
88 | + protected function getIconFactory() |
|
89 | + { |
|
90 | + return GeneralUtility::makeInstance(IconFactory::class); |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * @return LanguageService |
|
95 | - */ |
|
96 | - protected function getLabelService() |
|
97 | - { |
|
98 | - return $GLOBALS['LANG']; |
|
99 | - } |
|
93 | + /** |
|
94 | + * @return LanguageService |
|
95 | + */ |
|
96 | + protected function getLabelService() |
|
97 | + { |
|
98 | + return $GLOBALS['LANG']; |
|
99 | + } |
|
100 | 100 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | $this->tableName = $tableName; |
70 | 70 | |
71 | 71 | if (empty($GLOBALS['TCA'][$this->tableName])) { |
72 | - throw new InvalidKeyInArrayException('No TCA existence for table name: ' . $this->tableName, 1356945108); |
|
72 | + throw new InvalidKeyInArrayException('No TCA existence for table name: '.$this->tableName, 1356945108); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | $this->tca = $GLOBALS['TCA'][$this->tableName]['grid'] ?? []; |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | { |
172 | 172 | $fields = array_keys($this->getFields()); |
173 | 173 | if (empty($fields[$position])) { |
174 | - throw new InvalidKeyInArrayException('No field exist for position: ' . $position, 1356945119); |
|
174 | + throw new InvalidKeyInArrayException('No field exist for position: '.$position, 1356945119); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | return (string)$fields[$position]; |
@@ -687,7 +687,7 @@ discard block |
||
687 | 687 | $facet = GeneralUtility::makeInstance(StandardFacet::class, $facetName, $label); |
688 | 688 | |
689 | 689 | if (!$facet instanceof StandardFacet) { |
690 | - throw new \RuntimeException('I could not instantiate a facet for facet name "' . $facetName . '""', 1445856345); |
|
690 | + throw new \RuntimeException('I could not instantiate a facet for facet name "'.$facetName.'""', 1445856345); |
|
691 | 691 | } |
692 | 692 | return $facet; |
693 | 693 | } |
@@ -23,695 +23,695 @@ |
||
23 | 23 | */ |
24 | 24 | class GridService extends AbstractTca |
25 | 25 | { |
26 | - /** |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $tca; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - protected $tableName; |
|
35 | - |
|
36 | - /** |
|
37 | - * All fields available in the Grid. |
|
38 | - * |
|
39 | - * @var array |
|
40 | - */ |
|
41 | - protected $fields; |
|
42 | - |
|
43 | - /** |
|
44 | - * All fields regardless whether they have been excluded or not. |
|
45 | - * |
|
46 | - * @var array |
|
47 | - */ |
|
48 | - protected $allFields; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var array |
|
52 | - */ |
|
53 | - protected $instances; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var array |
|
57 | - */ |
|
58 | - protected $facets; |
|
59 | - |
|
60 | - /** |
|
61 | - * __construct |
|
62 | - * |
|
63 | - * @param string $tableName |
|
64 | - */ |
|
65 | - public function __construct($tableName) |
|
66 | - { |
|
67 | - $this->tableName = $tableName; |
|
68 | - |
|
69 | - if (empty($GLOBALS['TCA'][$this->tableName])) { |
|
70 | - throw new InvalidKeyInArrayException('No TCA existence for table name: ' . $this->tableName, 1356945108); |
|
71 | - } |
|
72 | - |
|
73 | - $this->tca = $GLOBALS['TCA'][$this->tableName]['grid'] ?? []; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Returns an array containing column names. |
|
78 | - * |
|
79 | - * @return array |
|
80 | - */ |
|
81 | - public function getFieldNames(): array |
|
82 | - { |
|
83 | - $fields = $this->getFields(); |
|
84 | - return array_keys($fields) ?: []; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Returns an array containing column names. |
|
89 | - * |
|
90 | - * @return array |
|
91 | - */ |
|
92 | - public function getAllFieldNames(): array |
|
93 | - { |
|
94 | - $allFields = $this->getAllFields(); |
|
95 | - return array_keys($allFields); |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Get the label key. |
|
100 | - * |
|
101 | - * @param string $fieldNameAndPath |
|
102 | - * @return string |
|
103 | - */ |
|
104 | - public function getLabelKey($fieldNameAndPath): string |
|
105 | - { |
|
106 | - $field = $this->getField($fieldNameAndPath); |
|
107 | - |
|
108 | - // First option is to get the label from the Grid TCA. |
|
109 | - $rawLabel = ''; |
|
110 | - if (isset($field['label'])) { |
|
111 | - $rawLabel = $field['label']; |
|
112 | - } |
|
113 | - |
|
114 | - // Second option is to fetch the label from the Column Renderer object. |
|
115 | - if (!$rawLabel && $this->hasRenderers($fieldNameAndPath)) { |
|
116 | - $renderers = $this->getRenderers($fieldNameAndPath); |
|
117 | - /** @var $renderer ColumnRendererInterface */ |
|
118 | - foreach ($renderers as $renderer) { |
|
119 | - if (isset($renderer['label'])) { |
|
120 | - $rawLabel = $renderer['label']; |
|
121 | - break; |
|
122 | - } |
|
123 | - } |
|
124 | - } |
|
125 | - return $rawLabel; |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Get the translation of a label given a column name. |
|
130 | - * |
|
131 | - * @param string $fieldNameAndPath |
|
132 | - * @return string |
|
133 | - */ |
|
134 | - public function getLabel($fieldNameAndPath) |
|
135 | - { |
|
136 | - $label = ''; |
|
137 | - if ($this->hasLabel($fieldNameAndPath)) { |
|
138 | - $labelKey = $this->getLabelKey($fieldNameAndPath); |
|
139 | - try { |
|
140 | - $label = $this->getLanguageService()->sL($labelKey); |
|
141 | - } catch (\InvalidArgumentException $e) { |
|
142 | - } |
|
143 | - if (empty($label)) { |
|
144 | - $label = $labelKey; |
|
145 | - } |
|
146 | - } else { |
|
147 | - // Important to notice the label can contains a path, e.g. metadata.categories and must be resolved. |
|
148 | - $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->tableName); |
|
149 | - $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $this->tableName); |
|
150 | - $table = Tca::table($dataType); |
|
151 | - |
|
152 | - if ($table->hasField($fieldName) && $table->field($fieldName)->hasLabel()) { |
|
153 | - $label = $table->field($fieldName)->getLabel(); |
|
154 | - } |
|
155 | - } |
|
156 | - |
|
157 | - return $label; |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * Returns the field name given its position. |
|
162 | - * |
|
163 | - * @param string $position the position of the field in the grid |
|
164 | - * @return string |
|
165 | - */ |
|
166 | - public function getFieldNameByPosition($position): string |
|
167 | - { |
|
168 | - $fields = array_keys($this->getFields()); |
|
169 | - if (empty($fields[$position])) { |
|
170 | - throw new InvalidKeyInArrayException('No field exist for position: ' . $position, 1356945119); |
|
171 | - } |
|
172 | - |
|
173 | - return (string)$fields[$position]; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Returns a field name. |
|
178 | - * |
|
179 | - * @param string $fieldName |
|
180 | - * @return array |
|
181 | - */ |
|
182 | - public function getField($fieldName): array |
|
183 | - { |
|
184 | - $fields = $this->getFields(); |
|
185 | - return $fields[$fieldName] ?: []; |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Returns an array containing column names for the Grid. |
|
190 | - * |
|
191 | - * @return array |
|
192 | - */ |
|
193 | - public function getFields(): array |
|
194 | - { |
|
195 | - // Cache this operation since it can take some time. |
|
196 | - if ($this->fields === null) { |
|
197 | - // Fetch all available fields first. |
|
198 | - $fields = $this->getAllFields(); |
|
199 | - |
|
200 | - if ($this->isBackendMode()) { |
|
201 | - // Then remove the not allowed. |
|
202 | - $fields = $this->filterByIncludedFields($fields); |
|
203 | - $fields = $this->filterByBackendUser($fields); |
|
204 | - $fields = $this->filterByExcludedFields($fields); |
|
205 | - } |
|
206 | - |
|
207 | - $this->fields = $fields; |
|
208 | - } |
|
209 | - |
|
210 | - return $this->fields; |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * Remove fields according to Grid configuration. |
|
215 | - * |
|
216 | - * @param $fields |
|
217 | - * @return array |
|
218 | - */ |
|
219 | - protected function filterByIncludedFields($fields): array |
|
220 | - { |
|
221 | - $filteredFields = $fields; |
|
222 | - $includedFields = $this->getIncludedFields(); |
|
223 | - if (count($includedFields) > 0) { |
|
224 | - $filteredFields = []; |
|
225 | - foreach ($fields as $fieldNameAndPath => $configuration) { |
|
226 | - if (in_array($fieldNameAndPath, $includedFields, true) || !Tca::table($this->tableName)->hasField($fieldNameAndPath)) { |
|
227 | - $filteredFields[$fieldNameAndPath] = $configuration; |
|
228 | - } |
|
229 | - } |
|
230 | - } |
|
231 | - return $filteredFields; |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * Remove fields according to BE User permission. |
|
236 | - * |
|
237 | - * @param $fields |
|
238 | - * @return array |
|
239 | - */ |
|
240 | - protected function filterByBackendUser($fields): array |
|
241 | - { |
|
242 | - if (!$this->getBackendUser()->isAdmin()) { |
|
243 | - foreach ($fields as $fieldName => $field) { |
|
244 | - if (Tca::table($this->tableName)->hasField($fieldName) && !Tca::table($this->tableName)->field($fieldName)->hasAccess()) { |
|
245 | - unset($fields[$fieldName]); |
|
246 | - } |
|
247 | - } |
|
248 | - } |
|
249 | - return $fields; |
|
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * Remove fields according to Grid configuration. |
|
254 | - * |
|
255 | - * @param $fields |
|
256 | - * @return array |
|
257 | - */ |
|
258 | - protected function filterByExcludedFields($fields): array |
|
259 | - { |
|
260 | - // Unset excluded fields. |
|
261 | - foreach ($this->getExcludedFields() as $excludedField) { |
|
262 | - if (isset($fields[$excludedField])) { |
|
263 | - unset($fields[$excludedField]); |
|
264 | - } |
|
265 | - } |
|
266 | - |
|
267 | - return $fields; |
|
268 | - } |
|
269 | - |
|
270 | - /** |
|
271 | - * Returns an array containing column names for the Grid. |
|
272 | - * |
|
273 | - * @return array |
|
274 | - */ |
|
275 | - public function getAllFields(): array |
|
276 | - { |
|
277 | - // Cache this operation since it can take some time. |
|
278 | - if ($this->allFields === null) { |
|
279 | - $fields = isset($this->tca['columns']) && is_array($this->tca['columns']) ? $this->tca['columns'] : []; |
|
280 | - $gridFieldNames = array_keys($fields); |
|
281 | - |
|
282 | - // Fetch all fields of the TCA and merge it back to the fields configured for Grid. |
|
283 | - $tableFieldNames = Tca::table($this->tableName)->getFields(); |
|
284 | - |
|
285 | - // Just remove system fields from the Grid. |
|
286 | - foreach ($tableFieldNames as $key => $fieldName) { |
|
287 | - if (in_array($fieldName, Tca::getSystemFields())) { |
|
288 | - unset($tableFieldNames[$key]); |
|
289 | - } |
|
290 | - } |
|
291 | - |
|
292 | - $additionalFields = array_diff($tableFieldNames, $gridFieldNames); |
|
293 | - |
|
294 | - if (!empty($additionalFields)) { |
|
295 | - // Pop out last element of the key |
|
296 | - // Idea is to place new un-configured columns in between. By default, they will be hidden. |
|
297 | - end($fields); |
|
298 | - $lastColumnKey = key($fields); |
|
299 | - $lastColumn = array_pop($fields); |
|
300 | - |
|
301 | - // Feed up the grid fields with un configured elements |
|
302 | - foreach ($additionalFields as $additionalField) { |
|
303 | - $fields[$additionalField] = array( |
|
304 | - 'visible' => false |
|
305 | - ); |
|
306 | - |
|
307 | - // Try to guess the format of the field. |
|
308 | - $fieldType = Tca::table($this->tableName)->field($additionalField)->getType(); |
|
309 | - if ($fieldType === FieldType::DATE) { |
|
310 | - $fields[$additionalField]['format'] = 'Fab\Vidi\Formatter\Date'; |
|
311 | - } elseif ($fieldType === FieldType::DATETIME) { |
|
312 | - $fields[$additionalField]['format'] = 'Fab\Vidi\Formatter\Datetime'; |
|
313 | - } |
|
314 | - } |
|
315 | - $fields[$lastColumnKey] = $lastColumn; |
|
316 | - } |
|
317 | - |
|
318 | - $this->allFields = $fields; |
|
319 | - } |
|
320 | - |
|
321 | - return $this->allFields; |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * Tell whether the field exists in the grid or not. |
|
326 | - * |
|
327 | - * @param string $fieldName |
|
328 | - * @return bool |
|
329 | - */ |
|
330 | - public function hasField($fieldName): bool |
|
331 | - { |
|
332 | - $fields = $this->getFields(); |
|
333 | - return isset($fields[$fieldName]); |
|
334 | - } |
|
335 | - |
|
336 | - /** |
|
337 | - * Tell whether the facet exists in the grid or not. |
|
338 | - * |
|
339 | - * @param string $facetName |
|
340 | - * @return bool |
|
341 | - */ |
|
342 | - public function hasFacet($facetName): bool |
|
343 | - { |
|
344 | - $facets = $this->getFacets(); |
|
345 | - return isset($facets[$facetName]); |
|
346 | - } |
|
347 | - |
|
348 | - /** |
|
349 | - * Returns an array containing facets fields. |
|
350 | - * |
|
351 | - * @return FacetInterface[] |
|
352 | - */ |
|
353 | - public function getFacets(): array |
|
354 | - { |
|
355 | - if ($this->facets === null) { |
|
356 | - $this->facets = []; |
|
357 | - |
|
358 | - if (is_array($this->tca['facets'])) { |
|
359 | - foreach ($this->tca['facets'] as $key => $facetNameOrArray) { |
|
360 | - if (is_array($facetNameOrArray)) { |
|
361 | - $name = $facetNameOrArray['name'] ?? ''; |
|
362 | - |
|
363 | - $label = isset($facetNameOrArray['label']) |
|
364 | - ? $this->getLanguageService()->sL($facetNameOrArray['label']) |
|
365 | - : ''; |
|
366 | - |
|
367 | - $suggestions = $facetNameOrArray['suggestions'] ?? []; |
|
368 | - $configuration = $facetNameOrArray['configuration'] ?? []; |
|
369 | - |
|
370 | - /** @var FacetInterface $facetObject */ |
|
371 | - $facetObject = GeneralUtility::makeInstance($key, $name, $label, $suggestions, $configuration); |
|
372 | - $this->facets[$facetObject->getName()] = $facetObject; |
|
373 | - } else { |
|
374 | - $this->facets[$facetNameOrArray] = $this->instantiateStandardFacet($facetNameOrArray); |
|
375 | - } |
|
376 | - } |
|
377 | - } |
|
378 | - } |
|
379 | - return $this->facets; |
|
380 | - } |
|
381 | - |
|
382 | - /** |
|
383 | - * Returns the "sortable" value of the column. |
|
384 | - * |
|
385 | - * @param string $fieldName |
|
386 | - * @return int|string |
|
387 | - */ |
|
388 | - public function isSortable($fieldName) |
|
389 | - { |
|
390 | - $defaultValue = true; |
|
391 | - $hasSortableField = Tca::table($this->tableName)->hasSortableField(); |
|
392 | - if ($hasSortableField) { |
|
393 | - $isSortable = false; |
|
394 | - } else { |
|
395 | - $isSortable = $this->get($fieldName, 'sortable', $defaultValue); |
|
396 | - } |
|
397 | - return $isSortable; |
|
398 | - } |
|
399 | - |
|
400 | - /** |
|
401 | - * Returns the "canBeHidden" value of the column. |
|
402 | - * |
|
403 | - * @param string $fieldName |
|
404 | - * @return bool |
|
405 | - */ |
|
406 | - public function canBeHidden($fieldName): bool |
|
407 | - { |
|
408 | - $defaultValue = true; |
|
409 | - return $this->get($fieldName, 'canBeHidden', $defaultValue); |
|
410 | - } |
|
411 | - |
|
412 | - /** |
|
413 | - * Returns the "width" value of the column. |
|
414 | - * |
|
415 | - * @param string $fieldName |
|
416 | - * @return int|string |
|
417 | - */ |
|
418 | - public function getWidth($fieldName) |
|
419 | - { |
|
420 | - $defaultValue = 'auto'; |
|
421 | - return $this->get($fieldName, 'width', $defaultValue); |
|
422 | - } |
|
423 | - |
|
424 | - /** |
|
425 | - * Returns the "visible" value of the column. |
|
426 | - * |
|
427 | - * @param string $fieldName |
|
428 | - * @return bool |
|
429 | - */ |
|
430 | - public function isVisible($fieldName): bool |
|
431 | - { |
|
432 | - $defaultValue = true; |
|
433 | - return $this->get($fieldName, 'visible', $defaultValue); |
|
434 | - } |
|
435 | - |
|
436 | - /** |
|
437 | - * Returns the "editable" value of the column. |
|
438 | - * |
|
439 | - * @param string $columnName |
|
440 | - * @return bool |
|
441 | - */ |
|
442 | - public function isEditable($columnName): bool |
|
443 | - { |
|
444 | - $defaultValue = false; |
|
445 | - return $this->get($columnName, 'editable', $defaultValue); |
|
446 | - } |
|
447 | - |
|
448 | - /** |
|
449 | - * Returns the "localized" value of the column. |
|
450 | - * |
|
451 | - * @param string $columnName |
|
452 | - * @return bool |
|
453 | - */ |
|
454 | - public function isLocalized($columnName): bool |
|
455 | - { |
|
456 | - $defaultValue = true; |
|
457 | - return $this->get($columnName, 'localized', $defaultValue); |
|
458 | - } |
|
459 | - |
|
460 | - /** |
|
461 | - * |
|
462 | - * Returns the "html" value of the column. |
|
463 | - * |
|
464 | - * @param string $fieldName |
|
465 | - * @return string |
|
466 | - */ |
|
467 | - public function getHeader($fieldName): string |
|
468 | - { |
|
469 | - $defaultValue = ''; |
|
470 | - return $this->get($fieldName, 'html', $defaultValue); |
|
471 | - } |
|
472 | - |
|
473 | - /** |
|
474 | - * Fetch a possible from a Grid Renderer. If no value is found, returns null |
|
475 | - * |
|
476 | - * @param string $fieldName |
|
477 | - * @param string $key |
|
478 | - * @param mixed $defaultValue |
|
479 | - * @return null|mixed |
|
480 | - */ |
|
481 | - public function get($fieldName, $key, $defaultValue = null) |
|
482 | - { |
|
483 | - $value = $defaultValue; |
|
484 | - |
|
485 | - $field = $this->getField($fieldName); |
|
486 | - if (isset($field[$key])) { |
|
487 | - $value = $field[$key]; |
|
488 | - } elseif ($this->hasRenderers($fieldName)) { |
|
489 | - $renderers = $this->getRenderers($fieldName); |
|
490 | - foreach ($renderers as $rendererConfiguration) { |
|
491 | - if (isset($rendererConfiguration[$key])) { |
|
492 | - $value = $rendererConfiguration[$key]; |
|
493 | - } |
|
494 | - } |
|
495 | - } |
|
496 | - return $value; |
|
497 | - } |
|
498 | - |
|
499 | - /** |
|
500 | - * Returns whether the column has a renderer. |
|
501 | - * |
|
502 | - * @param string $fieldName |
|
503 | - * @return bool |
|
504 | - */ |
|
505 | - public function hasRenderers($fieldName): bool |
|
506 | - { |
|
507 | - $field = $this->getField($fieldName); |
|
508 | - return empty($field['renderer']) && empty($field['renderers']) ? false : true; |
|
509 | - } |
|
510 | - |
|
511 | - /** |
|
512 | - * Returns a renderer. |
|
513 | - * |
|
514 | - * @param string $fieldName |
|
515 | - * @return array |
|
516 | - */ |
|
517 | - public function getRenderers($fieldName): array |
|
518 | - { |
|
519 | - $field = $this->getField($fieldName); |
|
520 | - $renderers = []; |
|
521 | - if (!empty($field['renderer'])) { |
|
522 | - $renderers = $this->convertRendererToArray($field['renderer'], $field); |
|
523 | - } elseif (!empty($field['renderers']) && is_array($field['renderers'])) { |
|
524 | - foreach ($field['renderers'] as $renderer) { |
|
525 | - $rendererNameAndConfiguration = $this->convertRendererToArray($renderer, $field); |
|
526 | - $renderers = array_merge($renderers, $rendererNameAndConfiguration); |
|
527 | - } |
|
528 | - } |
|
529 | - |
|
530 | - return $renderers; |
|
531 | - } |
|
532 | - |
|
533 | - /** |
|
534 | - * @param string $renderer |
|
535 | - * @return array |
|
536 | - */ |
|
537 | - protected function convertRendererToArray($renderer, array $field): array |
|
538 | - { |
|
539 | - $result = []; |
|
540 | - if (is_string($renderer)) { |
|
541 | - $configuration = empty($field['rendererConfiguration']) |
|
542 | - ? [] |
|
543 | - : $field['rendererConfiguration']; |
|
544 | - |
|
545 | - /** @var ColumnRendererInterface $rendererObject */ |
|
546 | - $rendererObject = GeneralUtility::makeInstance($renderer); |
|
547 | - |
|
548 | - $result[$renderer] = array_merge($rendererObject->getConfiguration(), $configuration); |
|
549 | - // TODO: throw alert message because this is not compatible anymore as of TYPO3 8.7.7 |
|
550 | - } elseif ($renderer instanceof ColumnRendererInterface) { |
|
551 | - /** @var ColumnRendererInterface $renderer */ |
|
552 | - $result[get_class($renderer)] = $renderer->getConfiguration(); |
|
553 | - } |
|
554 | - return $result; |
|
555 | - } |
|
556 | - |
|
557 | - /** |
|
558 | - * Returns the class names applied to a cell |
|
559 | - * |
|
560 | - * @param string $fieldName |
|
561 | - * @return bool |
|
562 | - */ |
|
563 | - public function getClass($fieldName): bool |
|
564 | - { |
|
565 | - $field = $this->getField($fieldName); |
|
566 | - return isset($field['class']) ? $field['class'] : ''; |
|
567 | - } |
|
568 | - |
|
569 | - /** |
|
570 | - * Returns whether the column has a label. |
|
571 | - * |
|
572 | - * @param string $fieldNameAndPath |
|
573 | - * @return bool |
|
574 | - */ |
|
575 | - public function hasLabel($fieldNameAndPath): bool |
|
576 | - { |
|
577 | - $field = $this->getField($fieldNameAndPath); |
|
578 | - |
|
579 | - $hasLabel = empty($field['label']) ? false : true; |
|
580 | - |
|
581 | - if (!$hasLabel && $this->hasRenderers($fieldNameAndPath)) { |
|
582 | - $renderers = $this->getRenderers($fieldNameAndPath); |
|
583 | - /** @var $renderer ColumnRendererInterface */ |
|
584 | - foreach ($renderers as $renderer) { |
|
585 | - if (isset($renderer['label'])) { |
|
586 | - $hasLabel = true; |
|
587 | - break; |
|
588 | - } |
|
589 | - } |
|
590 | - } |
|
591 | - return $hasLabel; |
|
592 | - } |
|
593 | - |
|
594 | - /** |
|
595 | - * @return array |
|
596 | - */ |
|
597 | - public function getTca(): array |
|
598 | - { |
|
599 | - return $this->tca; |
|
600 | - } |
|
601 | - |
|
602 | - /** |
|
603 | - * @return array |
|
604 | - */ |
|
605 | - public function getIncludedFields(): array |
|
606 | - { |
|
607 | - return empty($this->tca['included_fields']) ? [] : GeneralUtility::trimExplode(',', $this->tca['included_fields'], true); |
|
608 | - } |
|
609 | - |
|
610 | - /** |
|
611 | - * Return excluded fields from configuration + preferences. |
|
612 | - * |
|
613 | - * @return array |
|
614 | - */ |
|
615 | - public function getExcludedFields(): array |
|
616 | - { |
|
617 | - $configurationFields = $this->getExcludedFieldsFromConfiguration(); |
|
618 | - $preferencesFields = $this->getExcludedFieldsFromPreferences(); |
|
619 | - |
|
620 | - return array_merge($configurationFields, $preferencesFields); |
|
621 | - } |
|
622 | - |
|
623 | - /** |
|
624 | - * Fetch excluded fields from configuration. |
|
625 | - * |
|
626 | - * @return array |
|
627 | - */ |
|
628 | - protected function getExcludedFieldsFromConfiguration(): array |
|
629 | - { |
|
630 | - $excludedFields = []; |
|
631 | - if (!empty($this->tca['excluded_fields'])) { |
|
632 | - $excludedFields = GeneralUtility::trimExplode(',', $this->tca['excluded_fields'], true); |
|
633 | - } elseif (!empty($this->tca['export']['excluded_fields'])) { // only for export for legacy reason. |
|
634 | - $excludedFields = GeneralUtility::trimExplode(',', $this->tca['export']['excluded_fields'], true); |
|
635 | - } |
|
636 | - return $excludedFields; |
|
637 | - } |
|
638 | - |
|
639 | - /** |
|
640 | - * Fetch excluded fields from preferences. |
|
641 | - * |
|
642 | - * @return array |
|
643 | - */ |
|
644 | - protected function getExcludedFieldsFromPreferences(): array |
|
645 | - { |
|
646 | - $excludedFields = $this->getModulePreferences()->get(ConfigurablePart::EXCLUDED_FIELDS, $this->tableName); |
|
647 | - return is_array($excludedFields) ? $excludedFields : []; |
|
648 | - } |
|
649 | - |
|
650 | - /** |
|
651 | - * @return bool |
|
652 | - */ |
|
653 | - public function areFilesIncludedInExport(): bool |
|
654 | - { |
|
655 | - $isIncluded = true; |
|
656 | - |
|
657 | - if (isset($this->tca['export']['include_files'])) { |
|
658 | - $isIncluded = (bool)$this->tca['export']['include_files']; |
|
659 | - } |
|
660 | - return $isIncluded; |
|
661 | - } |
|
662 | - |
|
663 | - /** |
|
664 | - * Returns a "facet" service instance. |
|
665 | - * |
|
666 | - * @param string|FacetInterface $facetName |
|
667 | - * @return StandardFacet |
|
668 | - */ |
|
669 | - protected function instantiateStandardFacet($facetName): StandardFacet |
|
670 | - { |
|
671 | - $label = $this->getLabel($facetName); |
|
672 | - |
|
673 | - /** @var StandardFacet $facetName */ |
|
674 | - $facet = GeneralUtility::makeInstance(StandardFacet::class, $facetName, $label); |
|
675 | - |
|
676 | - if (!$facet instanceof StandardFacet) { |
|
677 | - throw new \RuntimeException('I could not instantiate a facet for facet name "' . $facetName . '""', 1445856345); |
|
678 | - } |
|
679 | - return $facet; |
|
680 | - } |
|
681 | - |
|
682 | - /** |
|
683 | - * Returns a "facet" service instance. |
|
684 | - * |
|
685 | - * @param string|FacetInterface $facetName |
|
686 | - * @return FacetInterface |
|
687 | - */ |
|
688 | - public function facet($facetName = ''): FacetInterface |
|
689 | - { |
|
690 | - $facets = $this->getFacets(); |
|
691 | - return $facets[$facetName]; |
|
692 | - } |
|
693 | - |
|
694 | - /** |
|
695 | - * @return FieldPathResolver|object |
|
696 | - */ |
|
697 | - protected function getFieldPathResolver() |
|
698 | - { |
|
699 | - return GeneralUtility::makeInstance(FieldPathResolver::class); |
|
700 | - } |
|
701 | - |
|
702 | - /** |
|
703 | - * @return ModulePreferences|object |
|
704 | - */ |
|
705 | - protected function getModulePreferences() |
|
706 | - { |
|
707 | - return GeneralUtility::makeInstance(ModulePreferences::class); |
|
708 | - } |
|
709 | - |
|
710 | - /** |
|
711 | - * @return LanguageService|object |
|
712 | - */ |
|
713 | - protected function getLanguageService() |
|
714 | - { |
|
715 | - return GeneralUtility::makeInstance(LanguageService::class); |
|
716 | - } |
|
26 | + /** |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $tca; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + protected $tableName; |
|
35 | + |
|
36 | + /** |
|
37 | + * All fields available in the Grid. |
|
38 | + * |
|
39 | + * @var array |
|
40 | + */ |
|
41 | + protected $fields; |
|
42 | + |
|
43 | + /** |
|
44 | + * All fields regardless whether they have been excluded or not. |
|
45 | + * |
|
46 | + * @var array |
|
47 | + */ |
|
48 | + protected $allFields; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var array |
|
52 | + */ |
|
53 | + protected $instances; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var array |
|
57 | + */ |
|
58 | + protected $facets; |
|
59 | + |
|
60 | + /** |
|
61 | + * __construct |
|
62 | + * |
|
63 | + * @param string $tableName |
|
64 | + */ |
|
65 | + public function __construct($tableName) |
|
66 | + { |
|
67 | + $this->tableName = $tableName; |
|
68 | + |
|
69 | + if (empty($GLOBALS['TCA'][$this->tableName])) { |
|
70 | + throw new InvalidKeyInArrayException('No TCA existence for table name: ' . $this->tableName, 1356945108); |
|
71 | + } |
|
72 | + |
|
73 | + $this->tca = $GLOBALS['TCA'][$this->tableName]['grid'] ?? []; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Returns an array containing column names. |
|
78 | + * |
|
79 | + * @return array |
|
80 | + */ |
|
81 | + public function getFieldNames(): array |
|
82 | + { |
|
83 | + $fields = $this->getFields(); |
|
84 | + return array_keys($fields) ?: []; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Returns an array containing column names. |
|
89 | + * |
|
90 | + * @return array |
|
91 | + */ |
|
92 | + public function getAllFieldNames(): array |
|
93 | + { |
|
94 | + $allFields = $this->getAllFields(); |
|
95 | + return array_keys($allFields); |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Get the label key. |
|
100 | + * |
|
101 | + * @param string $fieldNameAndPath |
|
102 | + * @return string |
|
103 | + */ |
|
104 | + public function getLabelKey($fieldNameAndPath): string |
|
105 | + { |
|
106 | + $field = $this->getField($fieldNameAndPath); |
|
107 | + |
|
108 | + // First option is to get the label from the Grid TCA. |
|
109 | + $rawLabel = ''; |
|
110 | + if (isset($field['label'])) { |
|
111 | + $rawLabel = $field['label']; |
|
112 | + } |
|
113 | + |
|
114 | + // Second option is to fetch the label from the Column Renderer object. |
|
115 | + if (!$rawLabel && $this->hasRenderers($fieldNameAndPath)) { |
|
116 | + $renderers = $this->getRenderers($fieldNameAndPath); |
|
117 | + /** @var $renderer ColumnRendererInterface */ |
|
118 | + foreach ($renderers as $renderer) { |
|
119 | + if (isset($renderer['label'])) { |
|
120 | + $rawLabel = $renderer['label']; |
|
121 | + break; |
|
122 | + } |
|
123 | + } |
|
124 | + } |
|
125 | + return $rawLabel; |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Get the translation of a label given a column name. |
|
130 | + * |
|
131 | + * @param string $fieldNameAndPath |
|
132 | + * @return string |
|
133 | + */ |
|
134 | + public function getLabel($fieldNameAndPath) |
|
135 | + { |
|
136 | + $label = ''; |
|
137 | + if ($this->hasLabel($fieldNameAndPath)) { |
|
138 | + $labelKey = $this->getLabelKey($fieldNameAndPath); |
|
139 | + try { |
|
140 | + $label = $this->getLanguageService()->sL($labelKey); |
|
141 | + } catch (\InvalidArgumentException $e) { |
|
142 | + } |
|
143 | + if (empty($label)) { |
|
144 | + $label = $labelKey; |
|
145 | + } |
|
146 | + } else { |
|
147 | + // Important to notice the label can contains a path, e.g. metadata.categories and must be resolved. |
|
148 | + $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->tableName); |
|
149 | + $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $this->tableName); |
|
150 | + $table = Tca::table($dataType); |
|
151 | + |
|
152 | + if ($table->hasField($fieldName) && $table->field($fieldName)->hasLabel()) { |
|
153 | + $label = $table->field($fieldName)->getLabel(); |
|
154 | + } |
|
155 | + } |
|
156 | + |
|
157 | + return $label; |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * Returns the field name given its position. |
|
162 | + * |
|
163 | + * @param string $position the position of the field in the grid |
|
164 | + * @return string |
|
165 | + */ |
|
166 | + public function getFieldNameByPosition($position): string |
|
167 | + { |
|
168 | + $fields = array_keys($this->getFields()); |
|
169 | + if (empty($fields[$position])) { |
|
170 | + throw new InvalidKeyInArrayException('No field exist for position: ' . $position, 1356945119); |
|
171 | + } |
|
172 | + |
|
173 | + return (string)$fields[$position]; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Returns a field name. |
|
178 | + * |
|
179 | + * @param string $fieldName |
|
180 | + * @return array |
|
181 | + */ |
|
182 | + public function getField($fieldName): array |
|
183 | + { |
|
184 | + $fields = $this->getFields(); |
|
185 | + return $fields[$fieldName] ?: []; |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Returns an array containing column names for the Grid. |
|
190 | + * |
|
191 | + * @return array |
|
192 | + */ |
|
193 | + public function getFields(): array |
|
194 | + { |
|
195 | + // Cache this operation since it can take some time. |
|
196 | + if ($this->fields === null) { |
|
197 | + // Fetch all available fields first. |
|
198 | + $fields = $this->getAllFields(); |
|
199 | + |
|
200 | + if ($this->isBackendMode()) { |
|
201 | + // Then remove the not allowed. |
|
202 | + $fields = $this->filterByIncludedFields($fields); |
|
203 | + $fields = $this->filterByBackendUser($fields); |
|
204 | + $fields = $this->filterByExcludedFields($fields); |
|
205 | + } |
|
206 | + |
|
207 | + $this->fields = $fields; |
|
208 | + } |
|
209 | + |
|
210 | + return $this->fields; |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * Remove fields according to Grid configuration. |
|
215 | + * |
|
216 | + * @param $fields |
|
217 | + * @return array |
|
218 | + */ |
|
219 | + protected function filterByIncludedFields($fields): array |
|
220 | + { |
|
221 | + $filteredFields = $fields; |
|
222 | + $includedFields = $this->getIncludedFields(); |
|
223 | + if (count($includedFields) > 0) { |
|
224 | + $filteredFields = []; |
|
225 | + foreach ($fields as $fieldNameAndPath => $configuration) { |
|
226 | + if (in_array($fieldNameAndPath, $includedFields, true) || !Tca::table($this->tableName)->hasField($fieldNameAndPath)) { |
|
227 | + $filteredFields[$fieldNameAndPath] = $configuration; |
|
228 | + } |
|
229 | + } |
|
230 | + } |
|
231 | + return $filteredFields; |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * Remove fields according to BE User permission. |
|
236 | + * |
|
237 | + * @param $fields |
|
238 | + * @return array |
|
239 | + */ |
|
240 | + protected function filterByBackendUser($fields): array |
|
241 | + { |
|
242 | + if (!$this->getBackendUser()->isAdmin()) { |
|
243 | + foreach ($fields as $fieldName => $field) { |
|
244 | + if (Tca::table($this->tableName)->hasField($fieldName) && !Tca::table($this->tableName)->field($fieldName)->hasAccess()) { |
|
245 | + unset($fields[$fieldName]); |
|
246 | + } |
|
247 | + } |
|
248 | + } |
|
249 | + return $fields; |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * Remove fields according to Grid configuration. |
|
254 | + * |
|
255 | + * @param $fields |
|
256 | + * @return array |
|
257 | + */ |
|
258 | + protected function filterByExcludedFields($fields): array |
|
259 | + { |
|
260 | + // Unset excluded fields. |
|
261 | + foreach ($this->getExcludedFields() as $excludedField) { |
|
262 | + if (isset($fields[$excludedField])) { |
|
263 | + unset($fields[$excludedField]); |
|
264 | + } |
|
265 | + } |
|
266 | + |
|
267 | + return $fields; |
|
268 | + } |
|
269 | + |
|
270 | + /** |
|
271 | + * Returns an array containing column names for the Grid. |
|
272 | + * |
|
273 | + * @return array |
|
274 | + */ |
|
275 | + public function getAllFields(): array |
|
276 | + { |
|
277 | + // Cache this operation since it can take some time. |
|
278 | + if ($this->allFields === null) { |
|
279 | + $fields = isset($this->tca['columns']) && is_array($this->tca['columns']) ? $this->tca['columns'] : []; |
|
280 | + $gridFieldNames = array_keys($fields); |
|
281 | + |
|
282 | + // Fetch all fields of the TCA and merge it back to the fields configured for Grid. |
|
283 | + $tableFieldNames = Tca::table($this->tableName)->getFields(); |
|
284 | + |
|
285 | + // Just remove system fields from the Grid. |
|
286 | + foreach ($tableFieldNames as $key => $fieldName) { |
|
287 | + if (in_array($fieldName, Tca::getSystemFields())) { |
|
288 | + unset($tableFieldNames[$key]); |
|
289 | + } |
|
290 | + } |
|
291 | + |
|
292 | + $additionalFields = array_diff($tableFieldNames, $gridFieldNames); |
|
293 | + |
|
294 | + if (!empty($additionalFields)) { |
|
295 | + // Pop out last element of the key |
|
296 | + // Idea is to place new un-configured columns in between. By default, they will be hidden. |
|
297 | + end($fields); |
|
298 | + $lastColumnKey = key($fields); |
|
299 | + $lastColumn = array_pop($fields); |
|
300 | + |
|
301 | + // Feed up the grid fields with un configured elements |
|
302 | + foreach ($additionalFields as $additionalField) { |
|
303 | + $fields[$additionalField] = array( |
|
304 | + 'visible' => false |
|
305 | + ); |
|
306 | + |
|
307 | + // Try to guess the format of the field. |
|
308 | + $fieldType = Tca::table($this->tableName)->field($additionalField)->getType(); |
|
309 | + if ($fieldType === FieldType::DATE) { |
|
310 | + $fields[$additionalField]['format'] = 'Fab\Vidi\Formatter\Date'; |
|
311 | + } elseif ($fieldType === FieldType::DATETIME) { |
|
312 | + $fields[$additionalField]['format'] = 'Fab\Vidi\Formatter\Datetime'; |
|
313 | + } |
|
314 | + } |
|
315 | + $fields[$lastColumnKey] = $lastColumn; |
|
316 | + } |
|
317 | + |
|
318 | + $this->allFields = $fields; |
|
319 | + } |
|
320 | + |
|
321 | + return $this->allFields; |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * Tell whether the field exists in the grid or not. |
|
326 | + * |
|
327 | + * @param string $fieldName |
|
328 | + * @return bool |
|
329 | + */ |
|
330 | + public function hasField($fieldName): bool |
|
331 | + { |
|
332 | + $fields = $this->getFields(); |
|
333 | + return isset($fields[$fieldName]); |
|
334 | + } |
|
335 | + |
|
336 | + /** |
|
337 | + * Tell whether the facet exists in the grid or not. |
|
338 | + * |
|
339 | + * @param string $facetName |
|
340 | + * @return bool |
|
341 | + */ |
|
342 | + public function hasFacet($facetName): bool |
|
343 | + { |
|
344 | + $facets = $this->getFacets(); |
|
345 | + return isset($facets[$facetName]); |
|
346 | + } |
|
347 | + |
|
348 | + /** |
|
349 | + * Returns an array containing facets fields. |
|
350 | + * |
|
351 | + * @return FacetInterface[] |
|
352 | + */ |
|
353 | + public function getFacets(): array |
|
354 | + { |
|
355 | + if ($this->facets === null) { |
|
356 | + $this->facets = []; |
|
357 | + |
|
358 | + if (is_array($this->tca['facets'])) { |
|
359 | + foreach ($this->tca['facets'] as $key => $facetNameOrArray) { |
|
360 | + if (is_array($facetNameOrArray)) { |
|
361 | + $name = $facetNameOrArray['name'] ?? ''; |
|
362 | + |
|
363 | + $label = isset($facetNameOrArray['label']) |
|
364 | + ? $this->getLanguageService()->sL($facetNameOrArray['label']) |
|
365 | + : ''; |
|
366 | + |
|
367 | + $suggestions = $facetNameOrArray['suggestions'] ?? []; |
|
368 | + $configuration = $facetNameOrArray['configuration'] ?? []; |
|
369 | + |
|
370 | + /** @var FacetInterface $facetObject */ |
|
371 | + $facetObject = GeneralUtility::makeInstance($key, $name, $label, $suggestions, $configuration); |
|
372 | + $this->facets[$facetObject->getName()] = $facetObject; |
|
373 | + } else { |
|
374 | + $this->facets[$facetNameOrArray] = $this->instantiateStandardFacet($facetNameOrArray); |
|
375 | + } |
|
376 | + } |
|
377 | + } |
|
378 | + } |
|
379 | + return $this->facets; |
|
380 | + } |
|
381 | + |
|
382 | + /** |
|
383 | + * Returns the "sortable" value of the column. |
|
384 | + * |
|
385 | + * @param string $fieldName |
|
386 | + * @return int|string |
|
387 | + */ |
|
388 | + public function isSortable($fieldName) |
|
389 | + { |
|
390 | + $defaultValue = true; |
|
391 | + $hasSortableField = Tca::table($this->tableName)->hasSortableField(); |
|
392 | + if ($hasSortableField) { |
|
393 | + $isSortable = false; |
|
394 | + } else { |
|
395 | + $isSortable = $this->get($fieldName, 'sortable', $defaultValue); |
|
396 | + } |
|
397 | + return $isSortable; |
|
398 | + } |
|
399 | + |
|
400 | + /** |
|
401 | + * Returns the "canBeHidden" value of the column. |
|
402 | + * |
|
403 | + * @param string $fieldName |
|
404 | + * @return bool |
|
405 | + */ |
|
406 | + public function canBeHidden($fieldName): bool |
|
407 | + { |
|
408 | + $defaultValue = true; |
|
409 | + return $this->get($fieldName, 'canBeHidden', $defaultValue); |
|
410 | + } |
|
411 | + |
|
412 | + /** |
|
413 | + * Returns the "width" value of the column. |
|
414 | + * |
|
415 | + * @param string $fieldName |
|
416 | + * @return int|string |
|
417 | + */ |
|
418 | + public function getWidth($fieldName) |
|
419 | + { |
|
420 | + $defaultValue = 'auto'; |
|
421 | + return $this->get($fieldName, 'width', $defaultValue); |
|
422 | + } |
|
423 | + |
|
424 | + /** |
|
425 | + * Returns the "visible" value of the column. |
|
426 | + * |
|
427 | + * @param string $fieldName |
|
428 | + * @return bool |
|
429 | + */ |
|
430 | + public function isVisible($fieldName): bool |
|
431 | + { |
|
432 | + $defaultValue = true; |
|
433 | + return $this->get($fieldName, 'visible', $defaultValue); |
|
434 | + } |
|
435 | + |
|
436 | + /** |
|
437 | + * Returns the "editable" value of the column. |
|
438 | + * |
|
439 | + * @param string $columnName |
|
440 | + * @return bool |
|
441 | + */ |
|
442 | + public function isEditable($columnName): bool |
|
443 | + { |
|
444 | + $defaultValue = false; |
|
445 | + return $this->get($columnName, 'editable', $defaultValue); |
|
446 | + } |
|
447 | + |
|
448 | + /** |
|
449 | + * Returns the "localized" value of the column. |
|
450 | + * |
|
451 | + * @param string $columnName |
|
452 | + * @return bool |
|
453 | + */ |
|
454 | + public function isLocalized($columnName): bool |
|
455 | + { |
|
456 | + $defaultValue = true; |
|
457 | + return $this->get($columnName, 'localized', $defaultValue); |
|
458 | + } |
|
459 | + |
|
460 | + /** |
|
461 | + * |
|
462 | + * Returns the "html" value of the column. |
|
463 | + * |
|
464 | + * @param string $fieldName |
|
465 | + * @return string |
|
466 | + */ |
|
467 | + public function getHeader($fieldName): string |
|
468 | + { |
|
469 | + $defaultValue = ''; |
|
470 | + return $this->get($fieldName, 'html', $defaultValue); |
|
471 | + } |
|
472 | + |
|
473 | + /** |
|
474 | + * Fetch a possible from a Grid Renderer. If no value is found, returns null |
|
475 | + * |
|
476 | + * @param string $fieldName |
|
477 | + * @param string $key |
|
478 | + * @param mixed $defaultValue |
|
479 | + * @return null|mixed |
|
480 | + */ |
|
481 | + public function get($fieldName, $key, $defaultValue = null) |
|
482 | + { |
|
483 | + $value = $defaultValue; |
|
484 | + |
|
485 | + $field = $this->getField($fieldName); |
|
486 | + if (isset($field[$key])) { |
|
487 | + $value = $field[$key]; |
|
488 | + } elseif ($this->hasRenderers($fieldName)) { |
|
489 | + $renderers = $this->getRenderers($fieldName); |
|
490 | + foreach ($renderers as $rendererConfiguration) { |
|
491 | + if (isset($rendererConfiguration[$key])) { |
|
492 | + $value = $rendererConfiguration[$key]; |
|
493 | + } |
|
494 | + } |
|
495 | + } |
|
496 | + return $value; |
|
497 | + } |
|
498 | + |
|
499 | + /** |
|
500 | + * Returns whether the column has a renderer. |
|
501 | + * |
|
502 | + * @param string $fieldName |
|
503 | + * @return bool |
|
504 | + */ |
|
505 | + public function hasRenderers($fieldName): bool |
|
506 | + { |
|
507 | + $field = $this->getField($fieldName); |
|
508 | + return empty($field['renderer']) && empty($field['renderers']) ? false : true; |
|
509 | + } |
|
510 | + |
|
511 | + /** |
|
512 | + * Returns a renderer. |
|
513 | + * |
|
514 | + * @param string $fieldName |
|
515 | + * @return array |
|
516 | + */ |
|
517 | + public function getRenderers($fieldName): array |
|
518 | + { |
|
519 | + $field = $this->getField($fieldName); |
|
520 | + $renderers = []; |
|
521 | + if (!empty($field['renderer'])) { |
|
522 | + $renderers = $this->convertRendererToArray($field['renderer'], $field); |
|
523 | + } elseif (!empty($field['renderers']) && is_array($field['renderers'])) { |
|
524 | + foreach ($field['renderers'] as $renderer) { |
|
525 | + $rendererNameAndConfiguration = $this->convertRendererToArray($renderer, $field); |
|
526 | + $renderers = array_merge($renderers, $rendererNameAndConfiguration); |
|
527 | + } |
|
528 | + } |
|
529 | + |
|
530 | + return $renderers; |
|
531 | + } |
|
532 | + |
|
533 | + /** |
|
534 | + * @param string $renderer |
|
535 | + * @return array |
|
536 | + */ |
|
537 | + protected function convertRendererToArray($renderer, array $field): array |
|
538 | + { |
|
539 | + $result = []; |
|
540 | + if (is_string($renderer)) { |
|
541 | + $configuration = empty($field['rendererConfiguration']) |
|
542 | + ? [] |
|
543 | + : $field['rendererConfiguration']; |
|
544 | + |
|
545 | + /** @var ColumnRendererInterface $rendererObject */ |
|
546 | + $rendererObject = GeneralUtility::makeInstance($renderer); |
|
547 | + |
|
548 | + $result[$renderer] = array_merge($rendererObject->getConfiguration(), $configuration); |
|
549 | + // TODO: throw alert message because this is not compatible anymore as of TYPO3 8.7.7 |
|
550 | + } elseif ($renderer instanceof ColumnRendererInterface) { |
|
551 | + /** @var ColumnRendererInterface $renderer */ |
|
552 | + $result[get_class($renderer)] = $renderer->getConfiguration(); |
|
553 | + } |
|
554 | + return $result; |
|
555 | + } |
|
556 | + |
|
557 | + /** |
|
558 | + * Returns the class names applied to a cell |
|
559 | + * |
|
560 | + * @param string $fieldName |
|
561 | + * @return bool |
|
562 | + */ |
|
563 | + public function getClass($fieldName): bool |
|
564 | + { |
|
565 | + $field = $this->getField($fieldName); |
|
566 | + return isset($field['class']) ? $field['class'] : ''; |
|
567 | + } |
|
568 | + |
|
569 | + /** |
|
570 | + * Returns whether the column has a label. |
|
571 | + * |
|
572 | + * @param string $fieldNameAndPath |
|
573 | + * @return bool |
|
574 | + */ |
|
575 | + public function hasLabel($fieldNameAndPath): bool |
|
576 | + { |
|
577 | + $field = $this->getField($fieldNameAndPath); |
|
578 | + |
|
579 | + $hasLabel = empty($field['label']) ? false : true; |
|
580 | + |
|
581 | + if (!$hasLabel && $this->hasRenderers($fieldNameAndPath)) { |
|
582 | + $renderers = $this->getRenderers($fieldNameAndPath); |
|
583 | + /** @var $renderer ColumnRendererInterface */ |
|
584 | + foreach ($renderers as $renderer) { |
|
585 | + if (isset($renderer['label'])) { |
|
586 | + $hasLabel = true; |
|
587 | + break; |
|
588 | + } |
|
589 | + } |
|
590 | + } |
|
591 | + return $hasLabel; |
|
592 | + } |
|
593 | + |
|
594 | + /** |
|
595 | + * @return array |
|
596 | + */ |
|
597 | + public function getTca(): array |
|
598 | + { |
|
599 | + return $this->tca; |
|
600 | + } |
|
601 | + |
|
602 | + /** |
|
603 | + * @return array |
|
604 | + */ |
|
605 | + public function getIncludedFields(): array |
|
606 | + { |
|
607 | + return empty($this->tca['included_fields']) ? [] : GeneralUtility::trimExplode(',', $this->tca['included_fields'], true); |
|
608 | + } |
|
609 | + |
|
610 | + /** |
|
611 | + * Return excluded fields from configuration + preferences. |
|
612 | + * |
|
613 | + * @return array |
|
614 | + */ |
|
615 | + public function getExcludedFields(): array |
|
616 | + { |
|
617 | + $configurationFields = $this->getExcludedFieldsFromConfiguration(); |
|
618 | + $preferencesFields = $this->getExcludedFieldsFromPreferences(); |
|
619 | + |
|
620 | + return array_merge($configurationFields, $preferencesFields); |
|
621 | + } |
|
622 | + |
|
623 | + /** |
|
624 | + * Fetch excluded fields from configuration. |
|
625 | + * |
|
626 | + * @return array |
|
627 | + */ |
|
628 | + protected function getExcludedFieldsFromConfiguration(): array |
|
629 | + { |
|
630 | + $excludedFields = []; |
|
631 | + if (!empty($this->tca['excluded_fields'])) { |
|
632 | + $excludedFields = GeneralUtility::trimExplode(',', $this->tca['excluded_fields'], true); |
|
633 | + } elseif (!empty($this->tca['export']['excluded_fields'])) { // only for export for legacy reason. |
|
634 | + $excludedFields = GeneralUtility::trimExplode(',', $this->tca['export']['excluded_fields'], true); |
|
635 | + } |
|
636 | + return $excludedFields; |
|
637 | + } |
|
638 | + |
|
639 | + /** |
|
640 | + * Fetch excluded fields from preferences. |
|
641 | + * |
|
642 | + * @return array |
|
643 | + */ |
|
644 | + protected function getExcludedFieldsFromPreferences(): array |
|
645 | + { |
|
646 | + $excludedFields = $this->getModulePreferences()->get(ConfigurablePart::EXCLUDED_FIELDS, $this->tableName); |
|
647 | + return is_array($excludedFields) ? $excludedFields : []; |
|
648 | + } |
|
649 | + |
|
650 | + /** |
|
651 | + * @return bool |
|
652 | + */ |
|
653 | + public function areFilesIncludedInExport(): bool |
|
654 | + { |
|
655 | + $isIncluded = true; |
|
656 | + |
|
657 | + if (isset($this->tca['export']['include_files'])) { |
|
658 | + $isIncluded = (bool)$this->tca['export']['include_files']; |
|
659 | + } |
|
660 | + return $isIncluded; |
|
661 | + } |
|
662 | + |
|
663 | + /** |
|
664 | + * Returns a "facet" service instance. |
|
665 | + * |
|
666 | + * @param string|FacetInterface $facetName |
|
667 | + * @return StandardFacet |
|
668 | + */ |
|
669 | + protected function instantiateStandardFacet($facetName): StandardFacet |
|
670 | + { |
|
671 | + $label = $this->getLabel($facetName); |
|
672 | + |
|
673 | + /** @var StandardFacet $facetName */ |
|
674 | + $facet = GeneralUtility::makeInstance(StandardFacet::class, $facetName, $label); |
|
675 | + |
|
676 | + if (!$facet instanceof StandardFacet) { |
|
677 | + throw new \RuntimeException('I could not instantiate a facet for facet name "' . $facetName . '""', 1445856345); |
|
678 | + } |
|
679 | + return $facet; |
|
680 | + } |
|
681 | + |
|
682 | + /** |
|
683 | + * Returns a "facet" service instance. |
|
684 | + * |
|
685 | + * @param string|FacetInterface $facetName |
|
686 | + * @return FacetInterface |
|
687 | + */ |
|
688 | + public function facet($facetName = ''): FacetInterface |
|
689 | + { |
|
690 | + $facets = $this->getFacets(); |
|
691 | + return $facets[$facetName]; |
|
692 | + } |
|
693 | + |
|
694 | + /** |
|
695 | + * @return FieldPathResolver|object |
|
696 | + */ |
|
697 | + protected function getFieldPathResolver() |
|
698 | + { |
|
699 | + return GeneralUtility::makeInstance(FieldPathResolver::class); |
|
700 | + } |
|
701 | + |
|
702 | + /** |
|
703 | + * @return ModulePreferences|object |
|
704 | + */ |
|
705 | + protected function getModulePreferences() |
|
706 | + { |
|
707 | + return GeneralUtility::makeInstance(ModulePreferences::class); |
|
708 | + } |
|
709 | + |
|
710 | + /** |
|
711 | + * @return LanguageService|object |
|
712 | + */ |
|
713 | + protected function getLanguageService() |
|
714 | + { |
|
715 | + return GeneralUtility::makeInstance(LanguageService::class); |
|
716 | + } |
|
717 | 717 | } |
@@ -19,62 +19,62 @@ |
||
19 | 19 | */ |
20 | 20 | class SelectionRepository extends Repository |
21 | 21 | { |
22 | - /** |
|
23 | - * @param string $dataType |
|
24 | - * @return QueryResult |
|
25 | - */ |
|
26 | - public function findByDataTypeForCurrentBackendUser($dataType) |
|
27 | - { |
|
28 | - $query = $this->createQuery(); |
|
22 | + /** |
|
23 | + * @param string $dataType |
|
24 | + * @return QueryResult |
|
25 | + */ |
|
26 | + public function findByDataTypeForCurrentBackendUser($dataType) |
|
27 | + { |
|
28 | + $query = $this->createQuery(); |
|
29 | 29 | |
30 | - // Compute the OR part |
|
31 | - if ($this->getBackendUser()->isAdmin()) { |
|
32 | - $logicalOr = $query->logicalOr([$query->equals('visibility', Selection::VISIBILITY_EVERYONE), $query->equals('visibility', Selection::VISIBILITY_ADMIN_ONLY), $query->equals('cruser_id', $this->getBackendUser()->user['uid'])]); |
|
33 | - } else { |
|
34 | - $logicalOr = $query->logicalOr([$query->equals('visibility', Selection::VISIBILITY_EVERYONE), $query->equals('cruser_id', $this->getBackendUser()->user['uid'])]); |
|
35 | - } |
|
30 | + // Compute the OR part |
|
31 | + if ($this->getBackendUser()->isAdmin()) { |
|
32 | + $logicalOr = $query->logicalOr([$query->equals('visibility', Selection::VISIBILITY_EVERYONE), $query->equals('visibility', Selection::VISIBILITY_ADMIN_ONLY), $query->equals('cruser_id', $this->getBackendUser()->user['uid'])]); |
|
33 | + } else { |
|
34 | + $logicalOr = $query->logicalOr([$query->equals('visibility', Selection::VISIBILITY_EVERYONE), $query->equals('cruser_id', $this->getBackendUser()->user['uid'])]); |
|
35 | + } |
|
36 | 36 | |
37 | - // Add matching criteria |
|
38 | - $query->matching( |
|
39 | - $query->logicalAnd([$query->equals('dataType', $dataType), $logicalOr]) |
|
40 | - ); |
|
37 | + // Add matching criteria |
|
38 | + $query->matching( |
|
39 | + $query->logicalAnd([$query->equals('dataType', $dataType), $logicalOr]) |
|
40 | + ); |
|
41 | 41 | |
42 | - // Set ordering |
|
43 | - $query->setOrderings( |
|
44 | - array('name' => QueryInterface::ORDER_ASCENDING) |
|
45 | - ); |
|
42 | + // Set ordering |
|
43 | + $query->setOrderings( |
|
44 | + array('name' => QueryInterface::ORDER_ASCENDING) |
|
45 | + ); |
|
46 | 46 | |
47 | - return $query->execute(); |
|
48 | - } |
|
47 | + return $query->execute(); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param string $dataType |
|
52 | - * @return QueryResult |
|
53 | - */ |
|
54 | - public function findForEveryone($dataType) |
|
55 | - { |
|
56 | - $query = $this->createQuery(); |
|
50 | + /** |
|
51 | + * @param string $dataType |
|
52 | + * @return QueryResult |
|
53 | + */ |
|
54 | + public function findForEveryone($dataType) |
|
55 | + { |
|
56 | + $query = $this->createQuery(); |
|
57 | 57 | |
58 | - // Add matching criteria |
|
59 | - $query->matching( |
|
60 | - $query->logicalAnd([$query->equals('dataType', $dataType), $query->equals('visibility', Selection::VISIBILITY_EVERYONE)]) |
|
61 | - ); |
|
58 | + // Add matching criteria |
|
59 | + $query->matching( |
|
60 | + $query->logicalAnd([$query->equals('dataType', $dataType), $query->equals('visibility', Selection::VISIBILITY_EVERYONE)]) |
|
61 | + ); |
|
62 | 62 | |
63 | - // Set ordering |
|
64 | - $query->setOrderings( |
|
65 | - array('name' => QueryInterface::ORDER_ASCENDING) |
|
66 | - ); |
|
63 | + // Set ordering |
|
64 | + $query->setOrderings( |
|
65 | + array('name' => QueryInterface::ORDER_ASCENDING) |
|
66 | + ); |
|
67 | 67 | |
68 | - return $query->execute(); |
|
69 | - } |
|
68 | + return $query->execute(); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Returns an instance of the current Backend User. |
|
73 | - * |
|
74 | - * @return BackendUserAuthentication |
|
75 | - */ |
|
76 | - protected function getBackendUser() |
|
77 | - { |
|
78 | - return $GLOBALS['BE_USER']; |
|
79 | - } |
|
71 | + /** |
|
72 | + * Returns an instance of the current Backend User. |
|
73 | + * |
|
74 | + * @return BackendUserAuthentication |
|
75 | + */ |
|
76 | + protected function getBackendUser() |
|
77 | + { |
|
78 | + return $GLOBALS['BE_USER']; |
|
79 | + } |
|
80 | 80 | } |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | foreach ($order->getOrderings() as $ordering => $direction) { |
216 | 216 | if ($this->hasForeignRelationIn($ordering)) { |
217 | 217 | $relationalField = $this->getForeignRelationFrom($ordering); |
218 | - $matcher->like($relationalField . '.uid', ''); |
|
218 | + $matcher->like($relationalField.'.uid', ''); |
|
219 | 219 | } |
220 | 220 | } |
221 | 221 | } |
@@ -444,16 +444,16 @@ discard block |
||
444 | 444 | public function __call($methodName, $arguments) |
445 | 445 | { |
446 | 446 | if (substr($methodName, 0, 6) === 'findBy' && strlen($methodName) > 7) { |
447 | - $propertyName = strtolower(substr(substr($methodName, 6), 0, 1)) . substr(substr($methodName, 6), 1); |
|
447 | + $propertyName = strtolower(substr(substr($methodName, 6), 0, 1)).substr(substr($methodName, 6), 1); |
|
448 | 448 | $result = $this->processMagicCall($propertyName, $arguments[0]); |
449 | 449 | } elseif (substr($methodName, 0, 9) === 'findOneBy' && strlen($methodName) > 10) { |
450 | - $propertyName = strtolower(substr(substr($methodName, 9), 0, 1)) . substr(substr($methodName, 9), 1); |
|
450 | + $propertyName = strtolower(substr(substr($methodName, 9), 0, 1)).substr(substr($methodName, 9), 1); |
|
451 | 451 | $result = $this->processMagicCall($propertyName, $arguments[0], 'one'); |
452 | 452 | } elseif (substr($methodName, 0, 7) === 'countBy' && strlen($methodName) > 8) { |
453 | - $propertyName = strtolower(substr(substr($methodName, 7), 0, 1)) . substr(substr($methodName, 7), 1); |
|
453 | + $propertyName = strtolower(substr(substr($methodName, 7), 0, 1)).substr(substr($methodName, 7), 1); |
|
454 | 454 | $result = $this->processMagicCall($propertyName, $arguments[0], 'count'); |
455 | 455 | } else { |
456 | - throw new UnsupportedMethodException('The method "' . $methodName . '" is not supported by the repository.', 1360838010); |
|
456 | + throw new UnsupportedMethodException('The method "'.$methodName.'" is not supported by the repository.', 1360838010); |
|
457 | 457 | } |
458 | 458 | return $result; |
459 | 459 | } |
@@ -638,7 +638,7 @@ discard block |
||
638 | 638 | |
639 | 639 | if (Tca::table($dataType)->hasField($fieldName) && Tca::table($dataType)->field($fieldName)->hasRelation()) { |
640 | 640 | $foreignTable = Tca::table($dataType)->field($fieldName)->getForeignTable(); |
641 | - $fieldNameAndPath = $fieldNameAndPath . '.' . Tca::table($foreignTable)->getLabelField(); |
|
641 | + $fieldNameAndPath = $fieldNameAndPath.'.'.Tca::table($foreignTable)->getLabelField(); |
|
642 | 642 | } |
643 | 643 | $constraints[] = $query->like($fieldNameAndPath, $likeClause); |
644 | 644 | } |
@@ -708,17 +708,17 @@ discard block |
||
708 | 708 | |
709 | 709 | if (Tca::table($dataType)->field($fieldName)->hasRelation()) { |
710 | 710 | if (MathUtility::canBeInterpretedAsInteger($operand)) { |
711 | - $fieldNameAndPath = $fieldName . '.uid'; |
|
711 | + $fieldNameAndPath = $fieldName.'.uid'; |
|
712 | 712 | } else { |
713 | 713 | $foreignTableName = Tca::table($dataType)->field($fieldName)->getForeignTable(); |
714 | 714 | $foreignTable = Tca::table($foreignTableName); |
715 | - $fieldNameAndPath = $fieldName . '.' . $foreignTable->getLabelField(); |
|
715 | + $fieldNameAndPath = $fieldName.'.'.$foreignTable->getLabelField(); |
|
716 | 716 | } |
717 | 717 | |
718 | 718 | // If different means we should restore the prepended path segment for proper SQL parser. |
719 | 719 | // This is true for a composite field, e.g items.sys_file_metadata for categories. |
720 | 720 | if ($fieldName !== $fieldPath) { |
721 | - $fieldNameAndPath = $fieldPath . '.' . $fieldNameAndPath; |
|
721 | + $fieldNameAndPath = $fieldPath.'.'.$fieldNameAndPath; |
|
722 | 722 | } |
723 | 723 | } |
724 | 724 | |
@@ -770,7 +770,7 @@ discard block |
||
770 | 770 | $table = Tca::table($this->dataType); |
771 | 771 | if ($table->field($fieldName)->isGroup()) { |
772 | 772 | $valueParts = explode('.', $value, 2); |
773 | - $fieldName = $fieldName . '.' . $valueParts[0]; |
|
773 | + $fieldName = $fieldName.'.'.$valueParts[0]; |
|
774 | 774 | $value = $valueParts[1]; |
775 | 775 | } |
776 | 776 |
@@ -38,827 +38,827 @@ |
||
38 | 38 | */ |
39 | 39 | class ContentRepository implements RepositoryInterface |
40 | 40 | { |
41 | - /** |
|
42 | - * Tell whether it is a raw result (array) or object being returned. |
|
43 | - * |
|
44 | - * @var bool |
|
45 | - */ |
|
46 | - protected $rawResult = false; |
|
47 | - |
|
48 | - /** |
|
49 | - * The data type to be returned, e.g fe_users, fe_groups, tt_content, etc... |
|
50 | - * |
|
51 | - * @var string |
|
52 | - */ |
|
53 | - protected $dataType; |
|
54 | - |
|
55 | - /** |
|
56 | - * The source field is useful in the context of MM relations to know who is the caller |
|
57 | - * e.g findByItems which eventually corresponds to a field name. |
|
58 | - * |
|
59 | - * @var string |
|
60 | - */ |
|
61 | - protected $sourceFieldName = ''; |
|
62 | - |
|
63 | - /** |
|
64 | - * @var array |
|
65 | - */ |
|
66 | - protected $errorMessages = []; |
|
67 | - |
|
68 | - /** |
|
69 | - * @var QuerySettingsInterface |
|
70 | - */ |
|
71 | - protected $defaultQuerySettings; |
|
72 | - |
|
73 | - /** |
|
74 | - * @var DataHandler |
|
75 | - */ |
|
76 | - protected $dataHandler; |
|
77 | - |
|
78 | - /** |
|
79 | - * Constructor |
|
80 | - * |
|
81 | - * @param string $dataType |
|
82 | - */ |
|
83 | - public function __construct($dataType) |
|
84 | - { |
|
85 | - $this->dataType = $dataType; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Returns all objects of this repository. |
|
90 | - * |
|
91 | - * @return Content[] |
|
92 | - */ |
|
93 | - public function findAll() |
|
94 | - { |
|
95 | - $query = $this->createQuery(); |
|
96 | - return $query->execute(); |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Returns all "distinct" values for a given property. |
|
101 | - * |
|
102 | - * @param string $propertyName |
|
103 | - * @param Matcher $matcher |
|
104 | - * @param Order|null $order |
|
105 | - * @return Content[] |
|
106 | - */ |
|
107 | - public function findDistinctValues($propertyName, Matcher $matcher = null, Order $order = null): array |
|
108 | - { |
|
109 | - $query = $this->createQuery(); |
|
110 | - $query->setDistinct($propertyName); |
|
111 | - |
|
112 | - // Remove empty values from selection. |
|
113 | - $constraint = $query->logicalNot($query->equals($propertyName, '')); |
|
114 | - |
|
115 | - // Add some additional constraints from the Matcher object. |
|
116 | - $matcherConstraint = null; |
|
117 | - if ($matcher !== null) { |
|
118 | - $matcherConstraint = $this->computeConstraints($query, $matcher); |
|
119 | - } |
|
120 | - |
|
121 | - // Assemble the final constraints or not. |
|
122 | - if ($matcherConstraint) { |
|
123 | - $query->logicalAnd([$matcherConstraint, $constraint]); |
|
124 | - $query->matching($query->logicalAnd([$matcherConstraint, $constraint])); |
|
125 | - } else { |
|
126 | - $query->matching($constraint); |
|
127 | - } |
|
128 | - |
|
129 | - if ($order) { |
|
130 | - $query->setOrderings($order->getOrderings()); |
|
131 | - } |
|
132 | - |
|
133 | - return $query->execute(); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Returns all "distinct" values for a given property. |
|
138 | - * |
|
139 | - * @param string $propertyName |
|
140 | - * @param Matcher $matcher |
|
141 | - * @return int |
|
142 | - */ |
|
143 | - public function countDistinctValues($propertyName, Matcher $matcher = null): int |
|
144 | - { |
|
145 | - $query = $this->createQuery(); |
|
146 | - $query->setDistinct($propertyName); |
|
147 | - |
|
148 | - // Remove empty values from selection. |
|
149 | - $constraint = $query->logicalNot($query->equals($propertyName, '')); |
|
150 | - |
|
151 | - // Add some additional constraints from the Matcher object. |
|
152 | - $matcherConstraint = null; |
|
153 | - if (!is_null($matcher)) { |
|
154 | - $matcherConstraint = $this->computeConstraints($query, $matcher); |
|
155 | - } |
|
156 | - |
|
157 | - // Assemble the final constraints or not. |
|
158 | - if ($matcherConstraint) { |
|
159 | - $query->logicalAnd([$matcherConstraint, $constraint]); |
|
160 | - $query->matching($query->logicalAnd([$matcherConstraint, $constraint])); |
|
161 | - } else { |
|
162 | - $query->matching($constraint); |
|
163 | - } |
|
164 | - |
|
165 | - return $query->count(); |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Finds an object matching the given identifier. |
|
170 | - * |
|
171 | - * @param int $uid The identifier of the object to find |
|
172 | - * @return Content|null |
|
173 | - * @api |
|
174 | - */ |
|
175 | - public function findByUid($uid) |
|
176 | - { |
|
177 | - return $this->findByIdentifier($uid); |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * Finds all Contents given specified matches. |
|
182 | - * |
|
183 | - * @param string $propertyName |
|
184 | - * @param array $values |
|
185 | - * @return Content[] |
|
186 | - */ |
|
187 | - public function findIn($propertyName, array $values): array |
|
188 | - { |
|
189 | - $query = $this->createQuery(); |
|
190 | - $query->matching($query->in($propertyName, $values)); |
|
191 | - return $query->execute(); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Finds all Contents given specified matches. |
|
196 | - * |
|
197 | - * @param Matcher $matcher |
|
198 | - * @param Order $order The order |
|
199 | - * @param int $limit |
|
200 | - * @param int $offset |
|
201 | - * @return Content[] |
|
202 | - */ |
|
203 | - public function findBy(Matcher $matcher, Order $order = null, $limit = null, $offset = null): array |
|
204 | - { |
|
205 | - $query = $this->createQuery(); |
|
206 | - |
|
207 | - $limit = (int)$limit; // make sure to cast |
|
208 | - if ($limit > 0) { |
|
209 | - $query->setLimit($limit); |
|
210 | - } |
|
211 | - |
|
212 | - if ($order) { |
|
213 | - $query->setOrderings($order->getOrderings()); |
|
214 | - |
|
215 | - // Loops around the orderings adding if necessary a dummy condition |
|
216 | - // to make sure the relations can be resolved when transforming the query to plain SQL. |
|
217 | - foreach ($order->getOrderings() as $ordering => $direction) { |
|
218 | - if ($this->hasForeignRelationIn($ordering)) { |
|
219 | - $relationalField = $this->getForeignRelationFrom($ordering); |
|
220 | - $matcher->like($relationalField . '.uid', ''); |
|
221 | - } |
|
222 | - } |
|
223 | - } |
|
224 | - |
|
225 | - if ($offset) { |
|
226 | - $query->setOffset($offset); |
|
227 | - } |
|
228 | - |
|
229 | - $constraints = $this->computeConstraints($query, $matcher); |
|
230 | - |
|
231 | - if ($constraints) { |
|
232 | - $query->matching($constraints); |
|
233 | - } |
|
234 | - |
|
235 | - return $query->execute(); |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * Find one Content object given specified matches. |
|
240 | - * |
|
241 | - * @param Matcher $matcher |
|
242 | - * @return Content |
|
243 | - */ |
|
244 | - public function findOneBy(Matcher $matcher): Content |
|
245 | - { |
|
246 | - $query = $this->createQuery(); |
|
247 | - |
|
248 | - $constraints = $this->computeConstraints($query, $matcher); |
|
249 | - |
|
250 | - if ($constraints) { |
|
251 | - $query->matching($constraints); |
|
252 | - } |
|
253 | - |
|
254 | - $query->setLimit(1); // only take one! |
|
255 | - |
|
256 | - $resultSet = $query->execute(); |
|
257 | - if ($resultSet) { |
|
258 | - $resultSet = current($resultSet); |
|
259 | - } |
|
260 | - return $resultSet; |
|
261 | - } |
|
262 | - |
|
263 | - /** |
|
264 | - * Count all Contents given specified matches. |
|
265 | - * |
|
266 | - * @param Matcher $matcher |
|
267 | - * @return int |
|
268 | - */ |
|
269 | - public function countBy(Matcher $matcher): int |
|
270 | - { |
|
271 | - $query = $this->createQuery(); |
|
272 | - |
|
273 | - $constraints = $this->computeConstraints($query, $matcher); |
|
274 | - |
|
275 | - if ($constraints) { |
|
276 | - $query->matching($constraints); |
|
277 | - } |
|
278 | - |
|
279 | - return $query->count(); |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * Update a content with new information. |
|
284 | - * |
|
285 | - * @param Content $content |
|
286 | - * @param $language |
|
287 | - * @return bool |
|
288 | - */ |
|
289 | - public function localize($content, $language): bool |
|
290 | - { |
|
291 | - // Security check |
|
292 | - $this->getContentValidator()->validate($content); |
|
293 | - $this->getLanguageValidator()->validate($language); |
|
294 | - |
|
295 | - $dataType = $content->getDataType(); |
|
296 | - $handler = $this->getDataHandlerFactory()->action(ProcessAction::LOCALIZE)->forType($dataType)->getDataHandler(); |
|
297 | - |
|
298 | - $handlerResult = $handler->processLocalize($content, $language); |
|
299 | - $this->errorMessages = $handler->getErrorMessages(); |
|
300 | - return $handlerResult; |
|
301 | - } |
|
302 | - |
|
303 | - /** |
|
304 | - * Update a content with new information. |
|
305 | - * |
|
306 | - * @param Content $content |
|
307 | - * @return bool |
|
308 | - */ |
|
309 | - public function update($content) |
|
310 | - { |
|
311 | - // Security check. |
|
312 | - $this->getContentValidator()->validate($content); |
|
313 | - |
|
314 | - $dataType = $content->getDataType(); |
|
315 | - $handler = $this->getDataHandlerFactory()->action(ProcessAction::UPDATE)->forType($dataType)->getDataHandler(); |
|
316 | - |
|
317 | - $handlerResult = $handler->processUpdate($content); |
|
318 | - $this->errorMessages = $handler->getErrorMessages(); |
|
319 | - return $handlerResult; |
|
320 | - } |
|
321 | - |
|
322 | - /** |
|
323 | - * Removes an object from this repository. |
|
324 | - * |
|
325 | - * @param Content $content |
|
326 | - * @return boolean |
|
327 | - */ |
|
328 | - public function remove($content) |
|
329 | - { |
|
330 | - $dataType = $content->getDataType(); |
|
331 | - $handler = $this->getDataHandlerFactory()->action(ProcessAction::REMOVE)->forType($dataType)->getDataHandler(); |
|
332 | - |
|
333 | - $handlerResult = $handler->processRemove($content); |
|
334 | - $this->errorMessages = $handler->getErrorMessages(); |
|
335 | - return $handlerResult; |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * Move a content within this repository. |
|
340 | - * The $target corresponds to the pid to move the records to. |
|
341 | - * It can also be a negative value in case of sorting. The negative value would be the uid of its predecessor. |
|
342 | - * |
|
343 | - * @param Content $content |
|
344 | - * @param string $target |
|
345 | - * @return bool |
|
346 | - */ |
|
347 | - public function move($content, $target): bool |
|
348 | - { |
|
349 | - // Security check. |
|
350 | - $this->getContentValidator()->validate($content); |
|
351 | - |
|
352 | - $dataType = $content->getDataType(); |
|
353 | - $handler = $this->getDataHandlerFactory()->action(ProcessAction::MOVE)->forType($dataType)->getDataHandler(); |
|
354 | - |
|
355 | - $handlerResult = $handler->processMove($content, $target); |
|
356 | - $this->errorMessages = $handler->getErrorMessages(); |
|
357 | - return $handlerResult; |
|
358 | - } |
|
359 | - |
|
360 | - /** |
|
361 | - * Copy a content within this repository. |
|
362 | - * |
|
363 | - * @param Content $content |
|
364 | - * @return bool |
|
365 | - */ |
|
366 | - public function copy($content, $target): bool |
|
367 | - { |
|
368 | - // Security check. |
|
369 | - $this->getContentValidator()->validate($content); |
|
370 | - |
|
371 | - $dataType = $content->getDataType(); |
|
372 | - $handler = $this->getDataHandlerFactory()->action(ProcessAction::COPY)->forType($dataType)->getDataHandler(); |
|
373 | - |
|
374 | - $handlerResult = $handler->processCopy($content, $target); |
|
375 | - $this->errorMessages = $handler->getErrorMessages(); |
|
376 | - return $handlerResult; |
|
377 | - } |
|
378 | - |
|
379 | - /** |
|
380 | - * Adds an object to this repository. |
|
381 | - * |
|
382 | - * @param object $object The object to add |
|
383 | - * @return void |
|
384 | - * @api |
|
385 | - */ |
|
386 | - public function add($object) |
|
387 | - { |
|
388 | - throw new \BadMethodCallException('Repository does not support the add() method.', 1375805599); |
|
389 | - } |
|
390 | - |
|
391 | - /** |
|
392 | - * Returns the total number objects of this repository. |
|
393 | - * |
|
394 | - * @return integer The object count |
|
395 | - * @api |
|
396 | - */ |
|
397 | - public function countAll() |
|
398 | - { |
|
399 | - $query = $this->createQuery(); |
|
400 | - return $query->count(); |
|
401 | - } |
|
402 | - |
|
403 | - /** |
|
404 | - * Removes all objects of this repository as if remove() was called for |
|
405 | - * all of them. |
|
406 | - * |
|
407 | - * @return void |
|
408 | - * @api |
|
409 | - */ |
|
410 | - public function removeAll() |
|
411 | - { |
|
412 | - // TODO: Implement removeAll() method. |
|
413 | - } |
|
414 | - |
|
415 | - /** |
|
416 | - * Finds an object matching the given identifier. |
|
417 | - * |
|
418 | - * @param mixed $identifier The identifier of the object to find |
|
419 | - * @return Content|null |
|
420 | - * @api |
|
421 | - */ |
|
422 | - public function findByIdentifier($identifier) |
|
423 | - { |
|
424 | - $query = $this->createQuery(); |
|
425 | - |
|
426 | - $result = $query->matching( |
|
427 | - $query->equals('uid', $identifier) |
|
428 | - ) |
|
429 | - ->execute(); |
|
430 | - |
|
431 | - if (is_array($result)) { |
|
432 | - $result = current($result); |
|
433 | - } |
|
434 | - |
|
435 | - return $result; |
|
436 | - } |
|
437 | - |
|
438 | - /** |
|
439 | - * Dispatches magic methods (findBy[Property]()) |
|
440 | - * |
|
441 | - * @param string $methodName The name of the magic method |
|
442 | - * @param string $arguments The arguments of the magic method |
|
443 | - * @return mixed |
|
444 | - * @api |
|
445 | - */ |
|
446 | - public function __call($methodName, $arguments) |
|
447 | - { |
|
448 | - if (substr($methodName, 0, 6) === 'findBy' && strlen($methodName) > 7) { |
|
449 | - $propertyName = strtolower(substr(substr($methodName, 6), 0, 1)) . substr(substr($methodName, 6), 1); |
|
450 | - $result = $this->processMagicCall($propertyName, $arguments[0]); |
|
451 | - } elseif (substr($methodName, 0, 9) === 'findOneBy' && strlen($methodName) > 10) { |
|
452 | - $propertyName = strtolower(substr(substr($methodName, 9), 0, 1)) . substr(substr($methodName, 9), 1); |
|
453 | - $result = $this->processMagicCall($propertyName, $arguments[0], 'one'); |
|
454 | - } elseif (substr($methodName, 0, 7) === 'countBy' && strlen($methodName) > 8) { |
|
455 | - $propertyName = strtolower(substr(substr($methodName, 7), 0, 1)) . substr(substr($methodName, 7), 1); |
|
456 | - $result = $this->processMagicCall($propertyName, $arguments[0], 'count'); |
|
457 | - } else { |
|
458 | - throw new UnsupportedMethodException('The method "' . $methodName . '" is not supported by the repository.', 1360838010); |
|
459 | - } |
|
460 | - return $result; |
|
461 | - } |
|
462 | - |
|
463 | - /** |
|
464 | - * Returns a query for objects of this repository |
|
465 | - * |
|
466 | - * @return Query |
|
467 | - * @api |
|
468 | - */ |
|
469 | - public function createQuery() |
|
470 | - { |
|
471 | - /** @var Query $query */ |
|
472 | - $query = GeneralUtility::makeInstance(Query::class, $this->dataType); |
|
473 | - $query->setSourceFieldName($this->sourceFieldName); |
|
474 | - |
|
475 | - if ($this->defaultQuerySettings) { |
|
476 | - $query->setTypo3QuerySettings($this->defaultQuerySettings); |
|
477 | - } else { |
|
478 | - // Initialize and pass the query settings at this level. |
|
479 | - $querySettings = GeneralUtility::makeInstance(Typo3QuerySettings::class); |
|
480 | - |
|
481 | - // Default choice for the BE. |
|
482 | - if ($this->isBackendMode()) { |
|
483 | - $querySettings->setIgnoreEnableFields(true); |
|
484 | - } |
|
485 | - |
|
486 | - $query->setTypo3QuerySettings($querySettings); |
|
487 | - } |
|
488 | - |
|
489 | - return $query; |
|
490 | - } |
|
491 | - |
|
492 | - /** |
|
493 | - * Sets the property names to order the result by per default. |
|
494 | - * Expected like this: |
|
495 | - * array( |
|
496 | - * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING, |
|
497 | - * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING |
|
498 | - * ) |
|
499 | - * |
|
500 | - * @param array $defaultOrderings The property names to order by |
|
501 | - * @return void |
|
502 | - * @api |
|
503 | - */ |
|
504 | - public function setDefaultOrderings(array $defaultOrderings) |
|
505 | - { |
|
506 | - throw new \BadMethodCallException('Repository does not support the setDefaultOrderings() method.', 1375805598); |
|
507 | - } |
|
508 | - |
|
509 | - /** |
|
510 | - * Sets the default query settings to be used in this repository |
|
511 | - * |
|
512 | - * @param QuerySettingsInterface $defaultQuerySettings The query settings to be used by default |
|
513 | - * @return void |
|
514 | - * @api |
|
515 | - */ |
|
516 | - public function setDefaultQuerySettings(QuerySettingsInterface $defaultQuerySettings) |
|
517 | - { |
|
518 | - $this->defaultQuerySettings = $defaultQuerySettings; |
|
519 | - } |
|
520 | - |
|
521 | - /** |
|
522 | - * @return void |
|
523 | - */ |
|
524 | - public function resetDefaultQuerySettings(): void |
|
525 | - { |
|
526 | - $this->defaultQuerySettings = null; |
|
527 | - } |
|
528 | - |
|
529 | - |
|
530 | - /** |
|
531 | - * @return array |
|
532 | - */ |
|
533 | - public function getErrorMessages(): array |
|
534 | - { |
|
535 | - return $this->errorMessages; |
|
536 | - } |
|
537 | - |
|
538 | - /** |
|
539 | - * @param string $sourceFieldName |
|
540 | - * @return $this |
|
541 | - */ |
|
542 | - public function setSourceFieldName($sourceFieldName): self |
|
543 | - { |
|
544 | - $this->sourceFieldName = $sourceFieldName; |
|
545 | - return $this; |
|
546 | - } |
|
547 | - |
|
548 | - /** |
|
549 | - * @return string |
|
550 | - */ |
|
551 | - public function getDataType(): string |
|
552 | - { |
|
553 | - return $this->dataType; |
|
554 | - } |
|
555 | - |
|
556 | - /** |
|
557 | - * Tell whether the order has a foreign table in its expression, e.g. "metadata.title". |
|
558 | - * |
|
559 | - * @param string $ordering |
|
560 | - * @return bool |
|
561 | - */ |
|
562 | - protected function hasForeignRelationIn($ordering): bool |
|
563 | - { |
|
564 | - return strpos($ordering, '.') !== false; |
|
565 | - } |
|
566 | - |
|
567 | - /** |
|
568 | - * Extract the foreign relation of the ordering "metadata.title" -> "metadata" |
|
569 | - * |
|
570 | - * @param string $ordering |
|
571 | - * @return string |
|
572 | - */ |
|
573 | - protected function getForeignRelationFrom($ordering): string |
|
574 | - { |
|
575 | - $parts = explode('.', $ordering); |
|
576 | - return $parts[0]; |
|
577 | - } |
|
578 | - |
|
579 | - /** |
|
580 | - * Get the constraints |
|
581 | - * |
|
582 | - * @param Query $query |
|
583 | - * @param Matcher $matcher |
|
584 | - * @return ConstraintInterface|null |
|
585 | - */ |
|
586 | - protected function computeConstraints(Query $query, Matcher $matcher): ?ConstraintInterface |
|
587 | - { |
|
588 | - $constraints = null; |
|
589 | - |
|
590 | - $collectedConstraints = []; |
|
591 | - |
|
592 | - // Search term |
|
593 | - $constraint = $this->computeSearchTermConstraint($query, $matcher); |
|
594 | - if ($constraint) { |
|
595 | - $collectedConstraints[] = $constraint; |
|
596 | - } |
|
597 | - |
|
598 | - foreach ($matcher->getSupportedOperators() as $operator) { |
|
599 | - $constraint = $this->computeConstraint($query, $matcher, $operator); |
|
600 | - if ($constraint) { |
|
601 | - $collectedConstraints[] = $constraint; |
|
602 | - } |
|
603 | - } |
|
604 | - |
|
605 | - if (count($collectedConstraints) > 1) { |
|
606 | - $logical = $matcher->getDefaultLogicalSeparator(); |
|
607 | - $constraints = $query->$logical($collectedConstraints); |
|
608 | - } elseif (!empty($collectedConstraints)) { |
|
609 | - // true means there is one constraint only and should become the result |
|
610 | - $constraints = current($collectedConstraints); |
|
611 | - } |
|
612 | - |
|
613 | - // Trigger signal for post processing the computed constraints object. |
|
614 | - $constraints = $this->emitPostProcessConstraintsSignal($query, $constraints); |
|
615 | - |
|
616 | - return $constraints; |
|
617 | - } |
|
618 | - |
|
619 | - /** |
|
620 | - * Computes the search constraint and returns it. |
|
621 | - * |
|
622 | - * @param Query $query |
|
623 | - * @param Matcher $matcher |
|
624 | - * @return ConstraintInterface|null |
|
625 | - */ |
|
626 | - protected function computeSearchTermConstraint(Query $query, Matcher $matcher): ?ConstraintInterface |
|
627 | - { |
|
628 | - $result = null; |
|
629 | - |
|
630 | - // Search term case |
|
631 | - if ($matcher->getSearchTerm()) { |
|
632 | - $fields = GeneralUtility::trimExplode(',', Tca::table($this->dataType)->getSearchFields(), true); |
|
633 | - |
|
634 | - $constraints = []; |
|
635 | - $likeClause = sprintf('%%%s%%', $matcher->getSearchTerm()); |
|
636 | - foreach ($fields as $fieldNameAndPath) { |
|
637 | - if ($this->isSuitableForLike($fieldNameAndPath, $matcher->getSearchTerm())) { |
|
638 | - $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->dataType); |
|
639 | - $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $this->dataType); |
|
640 | - |
|
641 | - if (Tca::table($dataType)->hasField($fieldName) && Tca::table($dataType)->field($fieldName)->hasRelation()) { |
|
642 | - $foreignTable = Tca::table($dataType)->field($fieldName)->getForeignTable(); |
|
643 | - $fieldNameAndPath = $fieldNameAndPath . '.' . Tca::table($foreignTable)->getLabelField(); |
|
644 | - } |
|
645 | - $constraints[] = $query->like($fieldNameAndPath, $likeClause); |
|
646 | - } |
|
647 | - } |
|
648 | - $logical = $matcher->getLogicalSeparatorForSearchTerm(); |
|
649 | - $result = $query->$logical($constraints); |
|
650 | - } |
|
651 | - |
|
652 | - return $result; |
|
653 | - } |
|
654 | - |
|
655 | - /** |
|
656 | - * It does not make sense to have a "like" in presence of numerical field, e.g "uid". |
|
657 | - * Tell whether the given value makes sense for a "like" clause. |
|
658 | - * |
|
659 | - * @param string $fieldNameAndPath |
|
660 | - * @param string $value |
|
661 | - * @return bool |
|
662 | - */ |
|
663 | - protected function isSuitableForLike($fieldNameAndPath, $value): bool |
|
664 | - { |
|
665 | - $isSuitable = true; |
|
666 | - |
|
667 | - // true means it is a string |
|
668 | - if (!MathUtility::canBeInterpretedAsInteger($value)) { |
|
669 | - $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->dataType); |
|
670 | - $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $this->dataType); |
|
671 | - |
|
672 | - if (Tca::table($dataType)->field($fieldName)->isNumerical() |
|
673 | - && !Tca::table($dataType)->field($fieldName)->hasRelation() |
|
674 | - ) { |
|
675 | - $isSuitable = false; |
|
676 | - } |
|
677 | - } |
|
678 | - |
|
679 | - return $isSuitable; |
|
680 | - } |
|
681 | - |
|
682 | - /** |
|
683 | - * Computes the constraint for matches and returns it. |
|
684 | - * |
|
685 | - * @param Query $query |
|
686 | - * @param Matcher $matcher |
|
687 | - * @param string $operator |
|
688 | - * @return ConstraintInterface|null |
|
689 | - */ |
|
690 | - protected function computeConstraint(Query $query, Matcher $matcher, $operator): ?ConstraintInterface |
|
691 | - { |
|
692 | - $result = null; |
|
693 | - |
|
694 | - $operatorName = ucfirst($operator); |
|
695 | - $getCriteria = sprintf('get%s', $operatorName); |
|
696 | - $criteria = $matcher->$getCriteria(); |
|
697 | - |
|
698 | - if (!empty($criteria)) { |
|
699 | - $constraints = []; |
|
700 | - |
|
701 | - foreach ($criteria as $criterion) { |
|
702 | - $fieldNameAndPath = $criterion['fieldNameAndPath']; |
|
703 | - $operand = $criterion['operand']; |
|
704 | - |
|
705 | - // Compute a few variables... |
|
706 | - // $dataType is generally equals to $this->dataType but not always... if fieldName is a path. |
|
707 | - $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->dataType); |
|
708 | - $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $this->dataType); |
|
709 | - $fieldPath = $this->getFieldPathResolver()->stripFieldName($fieldNameAndPath, $this->dataType); |
|
710 | - |
|
711 | - if (Tca::table($dataType)->field($fieldName)->hasRelation()) { |
|
712 | - if (MathUtility::canBeInterpretedAsInteger($operand)) { |
|
713 | - $fieldNameAndPath = $fieldName . '.uid'; |
|
714 | - } else { |
|
715 | - $foreignTableName = Tca::table($dataType)->field($fieldName)->getForeignTable(); |
|
716 | - $foreignTable = Tca::table($foreignTableName); |
|
717 | - $fieldNameAndPath = $fieldName . '.' . $foreignTable->getLabelField(); |
|
718 | - } |
|
719 | - |
|
720 | - // If different means we should restore the prepended path segment for proper SQL parser. |
|
721 | - // This is true for a composite field, e.g items.sys_file_metadata for categories. |
|
722 | - if ($fieldName !== $fieldPath) { |
|
723 | - $fieldNameAndPath = $fieldPath . '.' . $fieldNameAndPath; |
|
724 | - } |
|
725 | - } |
|
726 | - |
|
727 | - if (strpos($operator, 'not') === 0) { |
|
728 | - $strippedOperator = strtolower(substr($operator, 3)); |
|
729 | - $constraints[] = $query->logicalNot($query->$strippedOperator($fieldNameAndPath, $criterion['operand'])); |
|
730 | - } else { |
|
731 | - $constraints[] = $query->$operator($fieldNameAndPath, $criterion['operand']); |
|
732 | - } |
|
733 | - } |
|
734 | - |
|
735 | - $getLogicalSeparator = sprintf('getLogicalSeparatorFor%s', $operatorName); |
|
736 | - $logical = method_exists($matcher, $getLogicalSeparator) |
|
737 | - ? $matcher->$getLogicalSeparator() |
|
738 | - : $matcher->getDefaultLogicalSeparator(); |
|
739 | - |
|
740 | - $result = $query->$logical($constraints); |
|
741 | - } |
|
742 | - |
|
743 | - return $result; |
|
744 | - } |
|
745 | - |
|
746 | - /** |
|
747 | - * @return DataHandler |
|
748 | - */ |
|
749 | - protected function getDataHandler(): DataHandler |
|
750 | - { |
|
751 | - if (!$this->dataHandler) { |
|
752 | - $this->dataHandler = GeneralUtility::makeInstance(DataHandler::class); |
|
753 | - } |
|
754 | - return $this->dataHandler; |
|
755 | - } |
|
756 | - |
|
757 | - /** |
|
758 | - * Handle the magic call by properly creating a Query object and returning its result. |
|
759 | - * |
|
760 | - * @param string $propertyName |
|
761 | - * @param string $value |
|
762 | - * @param string $flag |
|
763 | - * @return mixed |
|
764 | - */ |
|
765 | - protected function processMagicCall($propertyName, $value, $flag = '') |
|
766 | - { |
|
767 | - $fieldName = Property::name($propertyName)->of($this->dataType)->toFieldName(); |
|
768 | - |
|
769 | - /** @var $matcher Matcher */ |
|
770 | - $matcher = GeneralUtility::makeInstance(Matcher::class, [], $this->getDataType()); |
|
771 | - |
|
772 | - $table = Tca::table($this->dataType); |
|
773 | - if ($table->field($fieldName)->isGroup()) { |
|
774 | - $valueParts = explode('.', $value, 2); |
|
775 | - $fieldName = $fieldName . '.' . $valueParts[0]; |
|
776 | - $value = $valueParts[1]; |
|
777 | - } |
|
778 | - |
|
779 | - $matcher->equals($fieldName, $value); |
|
780 | - |
|
781 | - if ($flag === 'count') { |
|
782 | - $result = $this->countBy($matcher); |
|
783 | - } else { |
|
784 | - $result = $this->findBy($matcher); |
|
785 | - } |
|
786 | - return $flag === 'one' && !empty($result) ? reset($result) : $result; |
|
787 | - } |
|
788 | - |
|
789 | - /** |
|
790 | - * @return DataHandlerFactory|object |
|
791 | - */ |
|
792 | - protected function getDataHandlerFactory() |
|
793 | - { |
|
794 | - return GeneralUtility::makeInstance(DataHandlerFactory::class); |
|
795 | - } |
|
796 | - |
|
797 | - protected function isBackendMode(): bool |
|
798 | - { |
|
799 | - return Typo3Mode::isBackendMode(); |
|
800 | - } |
|
801 | - |
|
802 | - /** |
|
803 | - * @return FieldPathResolver|object |
|
804 | - */ |
|
805 | - protected function getFieldPathResolver() |
|
806 | - { |
|
807 | - return GeneralUtility::makeInstance(FieldPathResolver::class); |
|
808 | - } |
|
809 | - |
|
810 | - /** |
|
811 | - * @return ContentValidator|object |
|
812 | - */ |
|
813 | - protected function getContentValidator(): ContentValidator |
|
814 | - { |
|
815 | - return GeneralUtility::makeInstance(ContentValidator::class); |
|
816 | - } |
|
817 | - |
|
818 | - /** |
|
819 | - * @return LanguageValidator|object |
|
820 | - */ |
|
821 | - protected function getLanguageValidator(): LanguageValidator |
|
822 | - { |
|
823 | - return GeneralUtility::makeInstance(LanguageValidator::class); |
|
824 | - } |
|
825 | - |
|
826 | - /** |
|
827 | - * Signal that is called for post-processing the computed constraints object. |
|
828 | - * |
|
829 | - * @param Query $query |
|
830 | - * @param ConstraintInterface|null $constraints |
|
831 | - * @return ConstraintInterface|null $constraints |
|
832 | - */ |
|
833 | - protected function emitPostProcessConstraintsSignal(Query $query, $constraints): ?ConstraintInterface |
|
834 | - { |
|
835 | - /** @var ConstraintContainer $constraintContainer */ |
|
836 | - $constraintContainer = GeneralUtility::makeInstance(ConstraintContainer::class); |
|
837 | - $result = $this->getSignalSlotDispatcher()->dispatch( |
|
838 | - self::class, |
|
839 | - 'postProcessConstraintsObject', |
|
840 | - [ |
|
841 | - $query, |
|
842 | - $constraints, |
|
843 | - $constraintContainer |
|
844 | - ] |
|
845 | - ); |
|
846 | - |
|
847 | - // Backward compatibility. |
|
848 | - $processedConstraints = $result[1]; |
|
849 | - |
|
850 | - // New way to transmit the constraints. |
|
851 | - if ($constraintContainer->getConstraint()) { |
|
852 | - $processedConstraints = $constraintContainer->getConstraint(); |
|
853 | - } |
|
854 | - return $processedConstraints; |
|
855 | - } |
|
856 | - |
|
857 | - /** |
|
858 | - * @return Dispatcher |
|
859 | - */ |
|
860 | - protected function getSignalSlotDispatcher(): Dispatcher |
|
861 | - { |
|
862 | - return GeneralUtility::makeInstance(Dispatcher::class); |
|
863 | - } |
|
41 | + /** |
|
42 | + * Tell whether it is a raw result (array) or object being returned. |
|
43 | + * |
|
44 | + * @var bool |
|
45 | + */ |
|
46 | + protected $rawResult = false; |
|
47 | + |
|
48 | + /** |
|
49 | + * The data type to be returned, e.g fe_users, fe_groups, tt_content, etc... |
|
50 | + * |
|
51 | + * @var string |
|
52 | + */ |
|
53 | + protected $dataType; |
|
54 | + |
|
55 | + /** |
|
56 | + * The source field is useful in the context of MM relations to know who is the caller |
|
57 | + * e.g findByItems which eventually corresponds to a field name. |
|
58 | + * |
|
59 | + * @var string |
|
60 | + */ |
|
61 | + protected $sourceFieldName = ''; |
|
62 | + |
|
63 | + /** |
|
64 | + * @var array |
|
65 | + */ |
|
66 | + protected $errorMessages = []; |
|
67 | + |
|
68 | + /** |
|
69 | + * @var QuerySettingsInterface |
|
70 | + */ |
|
71 | + protected $defaultQuerySettings; |
|
72 | + |
|
73 | + /** |
|
74 | + * @var DataHandler |
|
75 | + */ |
|
76 | + protected $dataHandler; |
|
77 | + |
|
78 | + /** |
|
79 | + * Constructor |
|
80 | + * |
|
81 | + * @param string $dataType |
|
82 | + */ |
|
83 | + public function __construct($dataType) |
|
84 | + { |
|
85 | + $this->dataType = $dataType; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Returns all objects of this repository. |
|
90 | + * |
|
91 | + * @return Content[] |
|
92 | + */ |
|
93 | + public function findAll() |
|
94 | + { |
|
95 | + $query = $this->createQuery(); |
|
96 | + return $query->execute(); |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Returns all "distinct" values for a given property. |
|
101 | + * |
|
102 | + * @param string $propertyName |
|
103 | + * @param Matcher $matcher |
|
104 | + * @param Order|null $order |
|
105 | + * @return Content[] |
|
106 | + */ |
|
107 | + public function findDistinctValues($propertyName, Matcher $matcher = null, Order $order = null): array |
|
108 | + { |
|
109 | + $query = $this->createQuery(); |
|
110 | + $query->setDistinct($propertyName); |
|
111 | + |
|
112 | + // Remove empty values from selection. |
|
113 | + $constraint = $query->logicalNot($query->equals($propertyName, '')); |
|
114 | + |
|
115 | + // Add some additional constraints from the Matcher object. |
|
116 | + $matcherConstraint = null; |
|
117 | + if ($matcher !== null) { |
|
118 | + $matcherConstraint = $this->computeConstraints($query, $matcher); |
|
119 | + } |
|
120 | + |
|
121 | + // Assemble the final constraints or not. |
|
122 | + if ($matcherConstraint) { |
|
123 | + $query->logicalAnd([$matcherConstraint, $constraint]); |
|
124 | + $query->matching($query->logicalAnd([$matcherConstraint, $constraint])); |
|
125 | + } else { |
|
126 | + $query->matching($constraint); |
|
127 | + } |
|
128 | + |
|
129 | + if ($order) { |
|
130 | + $query->setOrderings($order->getOrderings()); |
|
131 | + } |
|
132 | + |
|
133 | + return $query->execute(); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Returns all "distinct" values for a given property. |
|
138 | + * |
|
139 | + * @param string $propertyName |
|
140 | + * @param Matcher $matcher |
|
141 | + * @return int |
|
142 | + */ |
|
143 | + public function countDistinctValues($propertyName, Matcher $matcher = null): int |
|
144 | + { |
|
145 | + $query = $this->createQuery(); |
|
146 | + $query->setDistinct($propertyName); |
|
147 | + |
|
148 | + // Remove empty values from selection. |
|
149 | + $constraint = $query->logicalNot($query->equals($propertyName, '')); |
|
150 | + |
|
151 | + // Add some additional constraints from the Matcher object. |
|
152 | + $matcherConstraint = null; |
|
153 | + if (!is_null($matcher)) { |
|
154 | + $matcherConstraint = $this->computeConstraints($query, $matcher); |
|
155 | + } |
|
156 | + |
|
157 | + // Assemble the final constraints or not. |
|
158 | + if ($matcherConstraint) { |
|
159 | + $query->logicalAnd([$matcherConstraint, $constraint]); |
|
160 | + $query->matching($query->logicalAnd([$matcherConstraint, $constraint])); |
|
161 | + } else { |
|
162 | + $query->matching($constraint); |
|
163 | + } |
|
164 | + |
|
165 | + return $query->count(); |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Finds an object matching the given identifier. |
|
170 | + * |
|
171 | + * @param int $uid The identifier of the object to find |
|
172 | + * @return Content|null |
|
173 | + * @api |
|
174 | + */ |
|
175 | + public function findByUid($uid) |
|
176 | + { |
|
177 | + return $this->findByIdentifier($uid); |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * Finds all Contents given specified matches. |
|
182 | + * |
|
183 | + * @param string $propertyName |
|
184 | + * @param array $values |
|
185 | + * @return Content[] |
|
186 | + */ |
|
187 | + public function findIn($propertyName, array $values): array |
|
188 | + { |
|
189 | + $query = $this->createQuery(); |
|
190 | + $query->matching($query->in($propertyName, $values)); |
|
191 | + return $query->execute(); |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Finds all Contents given specified matches. |
|
196 | + * |
|
197 | + * @param Matcher $matcher |
|
198 | + * @param Order $order The order |
|
199 | + * @param int $limit |
|
200 | + * @param int $offset |
|
201 | + * @return Content[] |
|
202 | + */ |
|
203 | + public function findBy(Matcher $matcher, Order $order = null, $limit = null, $offset = null): array |
|
204 | + { |
|
205 | + $query = $this->createQuery(); |
|
206 | + |
|
207 | + $limit = (int)$limit; // make sure to cast |
|
208 | + if ($limit > 0) { |
|
209 | + $query->setLimit($limit); |
|
210 | + } |
|
211 | + |
|
212 | + if ($order) { |
|
213 | + $query->setOrderings($order->getOrderings()); |
|
214 | + |
|
215 | + // Loops around the orderings adding if necessary a dummy condition |
|
216 | + // to make sure the relations can be resolved when transforming the query to plain SQL. |
|
217 | + foreach ($order->getOrderings() as $ordering => $direction) { |
|
218 | + if ($this->hasForeignRelationIn($ordering)) { |
|
219 | + $relationalField = $this->getForeignRelationFrom($ordering); |
|
220 | + $matcher->like($relationalField . '.uid', ''); |
|
221 | + } |
|
222 | + } |
|
223 | + } |
|
224 | + |
|
225 | + if ($offset) { |
|
226 | + $query->setOffset($offset); |
|
227 | + } |
|
228 | + |
|
229 | + $constraints = $this->computeConstraints($query, $matcher); |
|
230 | + |
|
231 | + if ($constraints) { |
|
232 | + $query->matching($constraints); |
|
233 | + } |
|
234 | + |
|
235 | + return $query->execute(); |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * Find one Content object given specified matches. |
|
240 | + * |
|
241 | + * @param Matcher $matcher |
|
242 | + * @return Content |
|
243 | + */ |
|
244 | + public function findOneBy(Matcher $matcher): Content |
|
245 | + { |
|
246 | + $query = $this->createQuery(); |
|
247 | + |
|
248 | + $constraints = $this->computeConstraints($query, $matcher); |
|
249 | + |
|
250 | + if ($constraints) { |
|
251 | + $query->matching($constraints); |
|
252 | + } |
|
253 | + |
|
254 | + $query->setLimit(1); // only take one! |
|
255 | + |
|
256 | + $resultSet = $query->execute(); |
|
257 | + if ($resultSet) { |
|
258 | + $resultSet = current($resultSet); |
|
259 | + } |
|
260 | + return $resultSet; |
|
261 | + } |
|
262 | + |
|
263 | + /** |
|
264 | + * Count all Contents given specified matches. |
|
265 | + * |
|
266 | + * @param Matcher $matcher |
|
267 | + * @return int |
|
268 | + */ |
|
269 | + public function countBy(Matcher $matcher): int |
|
270 | + { |
|
271 | + $query = $this->createQuery(); |
|
272 | + |
|
273 | + $constraints = $this->computeConstraints($query, $matcher); |
|
274 | + |
|
275 | + if ($constraints) { |
|
276 | + $query->matching($constraints); |
|
277 | + } |
|
278 | + |
|
279 | + return $query->count(); |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * Update a content with new information. |
|
284 | + * |
|
285 | + * @param Content $content |
|
286 | + * @param $language |
|
287 | + * @return bool |
|
288 | + */ |
|
289 | + public function localize($content, $language): bool |
|
290 | + { |
|
291 | + // Security check |
|
292 | + $this->getContentValidator()->validate($content); |
|
293 | + $this->getLanguageValidator()->validate($language); |
|
294 | + |
|
295 | + $dataType = $content->getDataType(); |
|
296 | + $handler = $this->getDataHandlerFactory()->action(ProcessAction::LOCALIZE)->forType($dataType)->getDataHandler(); |
|
297 | + |
|
298 | + $handlerResult = $handler->processLocalize($content, $language); |
|
299 | + $this->errorMessages = $handler->getErrorMessages(); |
|
300 | + return $handlerResult; |
|
301 | + } |
|
302 | + |
|
303 | + /** |
|
304 | + * Update a content with new information. |
|
305 | + * |
|
306 | + * @param Content $content |
|
307 | + * @return bool |
|
308 | + */ |
|
309 | + public function update($content) |
|
310 | + { |
|
311 | + // Security check. |
|
312 | + $this->getContentValidator()->validate($content); |
|
313 | + |
|
314 | + $dataType = $content->getDataType(); |
|
315 | + $handler = $this->getDataHandlerFactory()->action(ProcessAction::UPDATE)->forType($dataType)->getDataHandler(); |
|
316 | + |
|
317 | + $handlerResult = $handler->processUpdate($content); |
|
318 | + $this->errorMessages = $handler->getErrorMessages(); |
|
319 | + return $handlerResult; |
|
320 | + } |
|
321 | + |
|
322 | + /** |
|
323 | + * Removes an object from this repository. |
|
324 | + * |
|
325 | + * @param Content $content |
|
326 | + * @return boolean |
|
327 | + */ |
|
328 | + public function remove($content) |
|
329 | + { |
|
330 | + $dataType = $content->getDataType(); |
|
331 | + $handler = $this->getDataHandlerFactory()->action(ProcessAction::REMOVE)->forType($dataType)->getDataHandler(); |
|
332 | + |
|
333 | + $handlerResult = $handler->processRemove($content); |
|
334 | + $this->errorMessages = $handler->getErrorMessages(); |
|
335 | + return $handlerResult; |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * Move a content within this repository. |
|
340 | + * The $target corresponds to the pid to move the records to. |
|
341 | + * It can also be a negative value in case of sorting. The negative value would be the uid of its predecessor. |
|
342 | + * |
|
343 | + * @param Content $content |
|
344 | + * @param string $target |
|
345 | + * @return bool |
|
346 | + */ |
|
347 | + public function move($content, $target): bool |
|
348 | + { |
|
349 | + // Security check. |
|
350 | + $this->getContentValidator()->validate($content); |
|
351 | + |
|
352 | + $dataType = $content->getDataType(); |
|
353 | + $handler = $this->getDataHandlerFactory()->action(ProcessAction::MOVE)->forType($dataType)->getDataHandler(); |
|
354 | + |
|
355 | + $handlerResult = $handler->processMove($content, $target); |
|
356 | + $this->errorMessages = $handler->getErrorMessages(); |
|
357 | + return $handlerResult; |
|
358 | + } |
|
359 | + |
|
360 | + /** |
|
361 | + * Copy a content within this repository. |
|
362 | + * |
|
363 | + * @param Content $content |
|
364 | + * @return bool |
|
365 | + */ |
|
366 | + public function copy($content, $target): bool |
|
367 | + { |
|
368 | + // Security check. |
|
369 | + $this->getContentValidator()->validate($content); |
|
370 | + |
|
371 | + $dataType = $content->getDataType(); |
|
372 | + $handler = $this->getDataHandlerFactory()->action(ProcessAction::COPY)->forType($dataType)->getDataHandler(); |
|
373 | + |
|
374 | + $handlerResult = $handler->processCopy($content, $target); |
|
375 | + $this->errorMessages = $handler->getErrorMessages(); |
|
376 | + return $handlerResult; |
|
377 | + } |
|
378 | + |
|
379 | + /** |
|
380 | + * Adds an object to this repository. |
|
381 | + * |
|
382 | + * @param object $object The object to add |
|
383 | + * @return void |
|
384 | + * @api |
|
385 | + */ |
|
386 | + public function add($object) |
|
387 | + { |
|
388 | + throw new \BadMethodCallException('Repository does not support the add() method.', 1375805599); |
|
389 | + } |
|
390 | + |
|
391 | + /** |
|
392 | + * Returns the total number objects of this repository. |
|
393 | + * |
|
394 | + * @return integer The object count |
|
395 | + * @api |
|
396 | + */ |
|
397 | + public function countAll() |
|
398 | + { |
|
399 | + $query = $this->createQuery(); |
|
400 | + return $query->count(); |
|
401 | + } |
|
402 | + |
|
403 | + /** |
|
404 | + * Removes all objects of this repository as if remove() was called for |
|
405 | + * all of them. |
|
406 | + * |
|
407 | + * @return void |
|
408 | + * @api |
|
409 | + */ |
|
410 | + public function removeAll() |
|
411 | + { |
|
412 | + // TODO: Implement removeAll() method. |
|
413 | + } |
|
414 | + |
|
415 | + /** |
|
416 | + * Finds an object matching the given identifier. |
|
417 | + * |
|
418 | + * @param mixed $identifier The identifier of the object to find |
|
419 | + * @return Content|null |
|
420 | + * @api |
|
421 | + */ |
|
422 | + public function findByIdentifier($identifier) |
|
423 | + { |
|
424 | + $query = $this->createQuery(); |
|
425 | + |
|
426 | + $result = $query->matching( |
|
427 | + $query->equals('uid', $identifier) |
|
428 | + ) |
|
429 | + ->execute(); |
|
430 | + |
|
431 | + if (is_array($result)) { |
|
432 | + $result = current($result); |
|
433 | + } |
|
434 | + |
|
435 | + return $result; |
|
436 | + } |
|
437 | + |
|
438 | + /** |
|
439 | + * Dispatches magic methods (findBy[Property]()) |
|
440 | + * |
|
441 | + * @param string $methodName The name of the magic method |
|
442 | + * @param string $arguments The arguments of the magic method |
|
443 | + * @return mixed |
|
444 | + * @api |
|
445 | + */ |
|
446 | + public function __call($methodName, $arguments) |
|
447 | + { |
|
448 | + if (substr($methodName, 0, 6) === 'findBy' && strlen($methodName) > 7) { |
|
449 | + $propertyName = strtolower(substr(substr($methodName, 6), 0, 1)) . substr(substr($methodName, 6), 1); |
|
450 | + $result = $this->processMagicCall($propertyName, $arguments[0]); |
|
451 | + } elseif (substr($methodName, 0, 9) === 'findOneBy' && strlen($methodName) > 10) { |
|
452 | + $propertyName = strtolower(substr(substr($methodName, 9), 0, 1)) . substr(substr($methodName, 9), 1); |
|
453 | + $result = $this->processMagicCall($propertyName, $arguments[0], 'one'); |
|
454 | + } elseif (substr($methodName, 0, 7) === 'countBy' && strlen($methodName) > 8) { |
|
455 | + $propertyName = strtolower(substr(substr($methodName, 7), 0, 1)) . substr(substr($methodName, 7), 1); |
|
456 | + $result = $this->processMagicCall($propertyName, $arguments[0], 'count'); |
|
457 | + } else { |
|
458 | + throw new UnsupportedMethodException('The method "' . $methodName . '" is not supported by the repository.', 1360838010); |
|
459 | + } |
|
460 | + return $result; |
|
461 | + } |
|
462 | + |
|
463 | + /** |
|
464 | + * Returns a query for objects of this repository |
|
465 | + * |
|
466 | + * @return Query |
|
467 | + * @api |
|
468 | + */ |
|
469 | + public function createQuery() |
|
470 | + { |
|
471 | + /** @var Query $query */ |
|
472 | + $query = GeneralUtility::makeInstance(Query::class, $this->dataType); |
|
473 | + $query->setSourceFieldName($this->sourceFieldName); |
|
474 | + |
|
475 | + if ($this->defaultQuerySettings) { |
|
476 | + $query->setTypo3QuerySettings($this->defaultQuerySettings); |
|
477 | + } else { |
|
478 | + // Initialize and pass the query settings at this level. |
|
479 | + $querySettings = GeneralUtility::makeInstance(Typo3QuerySettings::class); |
|
480 | + |
|
481 | + // Default choice for the BE. |
|
482 | + if ($this->isBackendMode()) { |
|
483 | + $querySettings->setIgnoreEnableFields(true); |
|
484 | + } |
|
485 | + |
|
486 | + $query->setTypo3QuerySettings($querySettings); |
|
487 | + } |
|
488 | + |
|
489 | + return $query; |
|
490 | + } |
|
491 | + |
|
492 | + /** |
|
493 | + * Sets the property names to order the result by per default. |
|
494 | + * Expected like this: |
|
495 | + * array( |
|
496 | + * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING, |
|
497 | + * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING |
|
498 | + * ) |
|
499 | + * |
|
500 | + * @param array $defaultOrderings The property names to order by |
|
501 | + * @return void |
|
502 | + * @api |
|
503 | + */ |
|
504 | + public function setDefaultOrderings(array $defaultOrderings) |
|
505 | + { |
|
506 | + throw new \BadMethodCallException('Repository does not support the setDefaultOrderings() method.', 1375805598); |
|
507 | + } |
|
508 | + |
|
509 | + /** |
|
510 | + * Sets the default query settings to be used in this repository |
|
511 | + * |
|
512 | + * @param QuerySettingsInterface $defaultQuerySettings The query settings to be used by default |
|
513 | + * @return void |
|
514 | + * @api |
|
515 | + */ |
|
516 | + public function setDefaultQuerySettings(QuerySettingsInterface $defaultQuerySettings) |
|
517 | + { |
|
518 | + $this->defaultQuerySettings = $defaultQuerySettings; |
|
519 | + } |
|
520 | + |
|
521 | + /** |
|
522 | + * @return void |
|
523 | + */ |
|
524 | + public function resetDefaultQuerySettings(): void |
|
525 | + { |
|
526 | + $this->defaultQuerySettings = null; |
|
527 | + } |
|
528 | + |
|
529 | + |
|
530 | + /** |
|
531 | + * @return array |
|
532 | + */ |
|
533 | + public function getErrorMessages(): array |
|
534 | + { |
|
535 | + return $this->errorMessages; |
|
536 | + } |
|
537 | + |
|
538 | + /** |
|
539 | + * @param string $sourceFieldName |
|
540 | + * @return $this |
|
541 | + */ |
|
542 | + public function setSourceFieldName($sourceFieldName): self |
|
543 | + { |
|
544 | + $this->sourceFieldName = $sourceFieldName; |
|
545 | + return $this; |
|
546 | + } |
|
547 | + |
|
548 | + /** |
|
549 | + * @return string |
|
550 | + */ |
|
551 | + public function getDataType(): string |
|
552 | + { |
|
553 | + return $this->dataType; |
|
554 | + } |
|
555 | + |
|
556 | + /** |
|
557 | + * Tell whether the order has a foreign table in its expression, e.g. "metadata.title". |
|
558 | + * |
|
559 | + * @param string $ordering |
|
560 | + * @return bool |
|
561 | + */ |
|
562 | + protected function hasForeignRelationIn($ordering): bool |
|
563 | + { |
|
564 | + return strpos($ordering, '.') !== false; |
|
565 | + } |
|
566 | + |
|
567 | + /** |
|
568 | + * Extract the foreign relation of the ordering "metadata.title" -> "metadata" |
|
569 | + * |
|
570 | + * @param string $ordering |
|
571 | + * @return string |
|
572 | + */ |
|
573 | + protected function getForeignRelationFrom($ordering): string |
|
574 | + { |
|
575 | + $parts = explode('.', $ordering); |
|
576 | + return $parts[0]; |
|
577 | + } |
|
578 | + |
|
579 | + /** |
|
580 | + * Get the constraints |
|
581 | + * |
|
582 | + * @param Query $query |
|
583 | + * @param Matcher $matcher |
|
584 | + * @return ConstraintInterface|null |
|
585 | + */ |
|
586 | + protected function computeConstraints(Query $query, Matcher $matcher): ?ConstraintInterface |
|
587 | + { |
|
588 | + $constraints = null; |
|
589 | + |
|
590 | + $collectedConstraints = []; |
|
591 | + |
|
592 | + // Search term |
|
593 | + $constraint = $this->computeSearchTermConstraint($query, $matcher); |
|
594 | + if ($constraint) { |
|
595 | + $collectedConstraints[] = $constraint; |
|
596 | + } |
|
597 | + |
|
598 | + foreach ($matcher->getSupportedOperators() as $operator) { |
|
599 | + $constraint = $this->computeConstraint($query, $matcher, $operator); |
|
600 | + if ($constraint) { |
|
601 | + $collectedConstraints[] = $constraint; |
|
602 | + } |
|
603 | + } |
|
604 | + |
|
605 | + if (count($collectedConstraints) > 1) { |
|
606 | + $logical = $matcher->getDefaultLogicalSeparator(); |
|
607 | + $constraints = $query->$logical($collectedConstraints); |
|
608 | + } elseif (!empty($collectedConstraints)) { |
|
609 | + // true means there is one constraint only and should become the result |
|
610 | + $constraints = current($collectedConstraints); |
|
611 | + } |
|
612 | + |
|
613 | + // Trigger signal for post processing the computed constraints object. |
|
614 | + $constraints = $this->emitPostProcessConstraintsSignal($query, $constraints); |
|
615 | + |
|
616 | + return $constraints; |
|
617 | + } |
|
618 | + |
|
619 | + /** |
|
620 | + * Computes the search constraint and returns it. |
|
621 | + * |
|
622 | + * @param Query $query |
|
623 | + * @param Matcher $matcher |
|
624 | + * @return ConstraintInterface|null |
|
625 | + */ |
|
626 | + protected function computeSearchTermConstraint(Query $query, Matcher $matcher): ?ConstraintInterface |
|
627 | + { |
|
628 | + $result = null; |
|
629 | + |
|
630 | + // Search term case |
|
631 | + if ($matcher->getSearchTerm()) { |
|
632 | + $fields = GeneralUtility::trimExplode(',', Tca::table($this->dataType)->getSearchFields(), true); |
|
633 | + |
|
634 | + $constraints = []; |
|
635 | + $likeClause = sprintf('%%%s%%', $matcher->getSearchTerm()); |
|
636 | + foreach ($fields as $fieldNameAndPath) { |
|
637 | + if ($this->isSuitableForLike($fieldNameAndPath, $matcher->getSearchTerm())) { |
|
638 | + $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->dataType); |
|
639 | + $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $this->dataType); |
|
640 | + |
|
641 | + if (Tca::table($dataType)->hasField($fieldName) && Tca::table($dataType)->field($fieldName)->hasRelation()) { |
|
642 | + $foreignTable = Tca::table($dataType)->field($fieldName)->getForeignTable(); |
|
643 | + $fieldNameAndPath = $fieldNameAndPath . '.' . Tca::table($foreignTable)->getLabelField(); |
|
644 | + } |
|
645 | + $constraints[] = $query->like($fieldNameAndPath, $likeClause); |
|
646 | + } |
|
647 | + } |
|
648 | + $logical = $matcher->getLogicalSeparatorForSearchTerm(); |
|
649 | + $result = $query->$logical($constraints); |
|
650 | + } |
|
651 | + |
|
652 | + return $result; |
|
653 | + } |
|
654 | + |
|
655 | + /** |
|
656 | + * It does not make sense to have a "like" in presence of numerical field, e.g "uid". |
|
657 | + * Tell whether the given value makes sense for a "like" clause. |
|
658 | + * |
|
659 | + * @param string $fieldNameAndPath |
|
660 | + * @param string $value |
|
661 | + * @return bool |
|
662 | + */ |
|
663 | + protected function isSuitableForLike($fieldNameAndPath, $value): bool |
|
664 | + { |
|
665 | + $isSuitable = true; |
|
666 | + |
|
667 | + // true means it is a string |
|
668 | + if (!MathUtility::canBeInterpretedAsInteger($value)) { |
|
669 | + $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->dataType); |
|
670 | + $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $this->dataType); |
|
671 | + |
|
672 | + if (Tca::table($dataType)->field($fieldName)->isNumerical() |
|
673 | + && !Tca::table($dataType)->field($fieldName)->hasRelation() |
|
674 | + ) { |
|
675 | + $isSuitable = false; |
|
676 | + } |
|
677 | + } |
|
678 | + |
|
679 | + return $isSuitable; |
|
680 | + } |
|
681 | + |
|
682 | + /** |
|
683 | + * Computes the constraint for matches and returns it. |
|
684 | + * |
|
685 | + * @param Query $query |
|
686 | + * @param Matcher $matcher |
|
687 | + * @param string $operator |
|
688 | + * @return ConstraintInterface|null |
|
689 | + */ |
|
690 | + protected function computeConstraint(Query $query, Matcher $matcher, $operator): ?ConstraintInterface |
|
691 | + { |
|
692 | + $result = null; |
|
693 | + |
|
694 | + $operatorName = ucfirst($operator); |
|
695 | + $getCriteria = sprintf('get%s', $operatorName); |
|
696 | + $criteria = $matcher->$getCriteria(); |
|
697 | + |
|
698 | + if (!empty($criteria)) { |
|
699 | + $constraints = []; |
|
700 | + |
|
701 | + foreach ($criteria as $criterion) { |
|
702 | + $fieldNameAndPath = $criterion['fieldNameAndPath']; |
|
703 | + $operand = $criterion['operand']; |
|
704 | + |
|
705 | + // Compute a few variables... |
|
706 | + // $dataType is generally equals to $this->dataType but not always... if fieldName is a path. |
|
707 | + $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->dataType); |
|
708 | + $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $this->dataType); |
|
709 | + $fieldPath = $this->getFieldPathResolver()->stripFieldName($fieldNameAndPath, $this->dataType); |
|
710 | + |
|
711 | + if (Tca::table($dataType)->field($fieldName)->hasRelation()) { |
|
712 | + if (MathUtility::canBeInterpretedAsInteger($operand)) { |
|
713 | + $fieldNameAndPath = $fieldName . '.uid'; |
|
714 | + } else { |
|
715 | + $foreignTableName = Tca::table($dataType)->field($fieldName)->getForeignTable(); |
|
716 | + $foreignTable = Tca::table($foreignTableName); |
|
717 | + $fieldNameAndPath = $fieldName . '.' . $foreignTable->getLabelField(); |
|
718 | + } |
|
719 | + |
|
720 | + // If different means we should restore the prepended path segment for proper SQL parser. |
|
721 | + // This is true for a composite field, e.g items.sys_file_metadata for categories. |
|
722 | + if ($fieldName !== $fieldPath) { |
|
723 | + $fieldNameAndPath = $fieldPath . '.' . $fieldNameAndPath; |
|
724 | + } |
|
725 | + } |
|
726 | + |
|
727 | + if (strpos($operator, 'not') === 0) { |
|
728 | + $strippedOperator = strtolower(substr($operator, 3)); |
|
729 | + $constraints[] = $query->logicalNot($query->$strippedOperator($fieldNameAndPath, $criterion['operand'])); |
|
730 | + } else { |
|
731 | + $constraints[] = $query->$operator($fieldNameAndPath, $criterion['operand']); |
|
732 | + } |
|
733 | + } |
|
734 | + |
|
735 | + $getLogicalSeparator = sprintf('getLogicalSeparatorFor%s', $operatorName); |
|
736 | + $logical = method_exists($matcher, $getLogicalSeparator) |
|
737 | + ? $matcher->$getLogicalSeparator() |
|
738 | + : $matcher->getDefaultLogicalSeparator(); |
|
739 | + |
|
740 | + $result = $query->$logical($constraints); |
|
741 | + } |
|
742 | + |
|
743 | + return $result; |
|
744 | + } |
|
745 | + |
|
746 | + /** |
|
747 | + * @return DataHandler |
|
748 | + */ |
|
749 | + protected function getDataHandler(): DataHandler |
|
750 | + { |
|
751 | + if (!$this->dataHandler) { |
|
752 | + $this->dataHandler = GeneralUtility::makeInstance(DataHandler::class); |
|
753 | + } |
|
754 | + return $this->dataHandler; |
|
755 | + } |
|
756 | + |
|
757 | + /** |
|
758 | + * Handle the magic call by properly creating a Query object and returning its result. |
|
759 | + * |
|
760 | + * @param string $propertyName |
|
761 | + * @param string $value |
|
762 | + * @param string $flag |
|
763 | + * @return mixed |
|
764 | + */ |
|
765 | + protected function processMagicCall($propertyName, $value, $flag = '') |
|
766 | + { |
|
767 | + $fieldName = Property::name($propertyName)->of($this->dataType)->toFieldName(); |
|
768 | + |
|
769 | + /** @var $matcher Matcher */ |
|
770 | + $matcher = GeneralUtility::makeInstance(Matcher::class, [], $this->getDataType()); |
|
771 | + |
|
772 | + $table = Tca::table($this->dataType); |
|
773 | + if ($table->field($fieldName)->isGroup()) { |
|
774 | + $valueParts = explode('.', $value, 2); |
|
775 | + $fieldName = $fieldName . '.' . $valueParts[0]; |
|
776 | + $value = $valueParts[1]; |
|
777 | + } |
|
778 | + |
|
779 | + $matcher->equals($fieldName, $value); |
|
780 | + |
|
781 | + if ($flag === 'count') { |
|
782 | + $result = $this->countBy($matcher); |
|
783 | + } else { |
|
784 | + $result = $this->findBy($matcher); |
|
785 | + } |
|
786 | + return $flag === 'one' && !empty($result) ? reset($result) : $result; |
|
787 | + } |
|
788 | + |
|
789 | + /** |
|
790 | + * @return DataHandlerFactory|object |
|
791 | + */ |
|
792 | + protected function getDataHandlerFactory() |
|
793 | + { |
|
794 | + return GeneralUtility::makeInstance(DataHandlerFactory::class); |
|
795 | + } |
|
796 | + |
|
797 | + protected function isBackendMode(): bool |
|
798 | + { |
|
799 | + return Typo3Mode::isBackendMode(); |
|
800 | + } |
|
801 | + |
|
802 | + /** |
|
803 | + * @return FieldPathResolver|object |
|
804 | + */ |
|
805 | + protected function getFieldPathResolver() |
|
806 | + { |
|
807 | + return GeneralUtility::makeInstance(FieldPathResolver::class); |
|
808 | + } |
|
809 | + |
|
810 | + /** |
|
811 | + * @return ContentValidator|object |
|
812 | + */ |
|
813 | + protected function getContentValidator(): ContentValidator |
|
814 | + { |
|
815 | + return GeneralUtility::makeInstance(ContentValidator::class); |
|
816 | + } |
|
817 | + |
|
818 | + /** |
|
819 | + * @return LanguageValidator|object |
|
820 | + */ |
|
821 | + protected function getLanguageValidator(): LanguageValidator |
|
822 | + { |
|
823 | + return GeneralUtility::makeInstance(LanguageValidator::class); |
|
824 | + } |
|
825 | + |
|
826 | + /** |
|
827 | + * Signal that is called for post-processing the computed constraints object. |
|
828 | + * |
|
829 | + * @param Query $query |
|
830 | + * @param ConstraintInterface|null $constraints |
|
831 | + * @return ConstraintInterface|null $constraints |
|
832 | + */ |
|
833 | + protected function emitPostProcessConstraintsSignal(Query $query, $constraints): ?ConstraintInterface |
|
834 | + { |
|
835 | + /** @var ConstraintContainer $constraintContainer */ |
|
836 | + $constraintContainer = GeneralUtility::makeInstance(ConstraintContainer::class); |
|
837 | + $result = $this->getSignalSlotDispatcher()->dispatch( |
|
838 | + self::class, |
|
839 | + 'postProcessConstraintsObject', |
|
840 | + [ |
|
841 | + $query, |
|
842 | + $constraints, |
|
843 | + $constraintContainer |
|
844 | + ] |
|
845 | + ); |
|
846 | + |
|
847 | + // Backward compatibility. |
|
848 | + $processedConstraints = $result[1]; |
|
849 | + |
|
850 | + // New way to transmit the constraints. |
|
851 | + if ($constraintContainer->getConstraint()) { |
|
852 | + $processedConstraints = $constraintContainer->getConstraint(); |
|
853 | + } |
|
854 | + return $processedConstraints; |
|
855 | + } |
|
856 | + |
|
857 | + /** |
|
858 | + * @return Dispatcher |
|
859 | + */ |
|
860 | + protected function getSignalSlotDispatcher(): Dispatcher |
|
861 | + { |
|
862 | + return GeneralUtility::makeInstance(Dispatcher::class); |
|
863 | + } |
|
864 | 864 | } |