@@ -97,7 +97,7 @@ |
||
| 97 | 97 | /** @var Response $response */ |
| 98 | 98 | $response = $this->templateVariableContainer->get('response'); |
| 99 | 99 | $response->withHeader('Content-Type', 'application/csv'); |
| 100 | - $response->withHeader('Content-Disposition', 'attachment; filename="' . basename($this->exportFileNameAndPath) . '"'); |
|
| 100 | + $response->withHeader('Content-Disposition', 'attachment; filename="'.basename($this->exportFileNameAndPath).'"'); |
|
| 101 | 101 | $response->withHeader('Content-Length', filesize($this->exportFileNameAndPath)); |
| 102 | 102 | $response->withHeader('Content-Description', 'File Transfer'); |
| 103 | 103 | } |
@@ -17,86 +17,86 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class ToCsvViewHelper extends AbstractToFormatViewHelper |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Render a CSV export request. |
|
| 22 | - * |
|
| 23 | - */ |
|
| 24 | - public function render() |
|
| 25 | - { |
|
| 26 | - $objects = $this->templateVariableContainer->get('objects'); |
|
| 20 | + /** |
|
| 21 | + * Render a CSV export request. |
|
| 22 | + * |
|
| 23 | + */ |
|
| 24 | + public function render() |
|
| 25 | + { |
|
| 26 | + $objects = $this->templateVariableContainer->get('objects'); |
|
| 27 | 27 | |
| 28 | - // Make sure we have something to process... |
|
| 29 | - if (!empty($objects)) { |
|
| 30 | - // Initialization step. |
|
| 31 | - $this->initializeEnvironment($objects); |
|
| 32 | - $this->exportFileNameAndPath .= '.csv'; // add extension to the file. |
|
| 28 | + // Make sure we have something to process... |
|
| 29 | + if (!empty($objects)) { |
|
| 30 | + // Initialization step. |
|
| 31 | + $this->initializeEnvironment($objects); |
|
| 32 | + $this->exportFileNameAndPath .= '.csv'; // add extension to the file. |
|
| 33 | 33 | |
| 34 | - // Write the exported data to a CSV file. |
|
| 35 | - $this->writeCsvFile($objects); |
|
| 34 | + // Write the exported data to a CSV file. |
|
| 35 | + $this->writeCsvFile($objects); |
|
| 36 | 36 | |
| 37 | - // We must generate a zip archive since there are files included. |
|
| 38 | - if ($this->hasCollectedFiles()) { |
|
| 39 | - $this->writeZipFile(); |
|
| 40 | - $this->sendZipHttpHeaders(); |
|
| 37 | + // We must generate a zip archive since there are files included. |
|
| 38 | + if ($this->hasCollectedFiles()) { |
|
| 39 | + $this->writeZipFile(); |
|
| 40 | + $this->sendZipHttpHeaders(); |
|
| 41 | 41 | |
| 42 | - readfile($this->zipFileNameAndPath); |
|
| 43 | - } else { |
|
| 44 | - $this->sendCsvHttpHeaders(); |
|
| 45 | - readfile($this->exportFileNameAndPath); |
|
| 46 | - } |
|
| 42 | + readfile($this->zipFileNameAndPath); |
|
| 43 | + } else { |
|
| 44 | + $this->sendCsvHttpHeaders(); |
|
| 45 | + readfile($this->exportFileNameAndPath); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - GeneralUtility::rmdir($this->temporaryDirectory, true); |
|
| 49 | - } |
|
| 50 | - } |
|
| 48 | + GeneralUtility::rmdir($this->temporaryDirectory, true); |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Write the CSV file to a temporary location. |
|
| 54 | - * |
|
| 55 | - * @param array $objects |
|
| 56 | - */ |
|
| 57 | - protected function writeCsvFile(array $objects) |
|
| 58 | - { |
|
| 59 | - // Create a file pointer |
|
| 60 | - $output = fopen($this->exportFileNameAndPath, 'w'); |
|
| 52 | + /** |
|
| 53 | + * Write the CSV file to a temporary location. |
|
| 54 | + * |
|
| 55 | + * @param array $objects |
|
| 56 | + */ |
|
| 57 | + protected function writeCsvFile(array $objects) |
|
| 58 | + { |
|
| 59 | + // Create a file pointer |
|
| 60 | + $output = fopen($this->exportFileNameAndPath, 'w'); |
|
| 61 | 61 | |
| 62 | - // Handle CSV header, get the first object and get the list of fields. |
|
| 63 | - /** @var Content $object */ |
|
| 64 | - $object = reset($objects); |
|
| 65 | - fputcsv($output, $object->toFields()); |
|
| 66 | - $this->checkWhetherObjectMayIncludeFiles($object); |
|
| 62 | + // Handle CSV header, get the first object and get the list of fields. |
|
| 63 | + /** @var Content $object */ |
|
| 64 | + $object = reset($objects); |
|
| 65 | + fputcsv($output, $object->toFields()); |
|
| 66 | + $this->checkWhetherObjectMayIncludeFiles($object); |
|
| 67 | 67 | |
| 68 | - foreach ($objects as $object) { |
|
| 69 | - if ($this->hasFileFields()) { |
|
| 70 | - $this->collectFiles($object); |
|
| 71 | - } |
|
| 68 | + foreach ($objects as $object) { |
|
| 69 | + if ($this->hasFileFields()) { |
|
| 70 | + $this->collectFiles($object); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - // Make sure we have a flat array of values for the CSV purpose. |
|
| 74 | - $flattenValues = []; |
|
| 75 | - foreach ($object->toValues() as $fieldName => $value) { |
|
| 76 | - if (is_array($value)) { |
|
| 77 | - $flattenValues[$fieldName] = implode(', ', $value); |
|
| 78 | - } else { |
|
| 79 | - $flattenValues[$fieldName] = str_replace("\n", "\r", $value); // for Excel purpose. |
|
| 80 | - } |
|
| 81 | - } |
|
| 73 | + // Make sure we have a flat array of values for the CSV purpose. |
|
| 74 | + $flattenValues = []; |
|
| 75 | + foreach ($object->toValues() as $fieldName => $value) { |
|
| 76 | + if (is_array($value)) { |
|
| 77 | + $flattenValues[$fieldName] = implode(', ', $value); |
|
| 78 | + } else { |
|
| 79 | + $flattenValues[$fieldName] = str_replace("\n", "\r", $value); // for Excel purpose. |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - fputcsv($output, $flattenValues); |
|
| 84 | - } |
|
| 83 | + fputcsv($output, $flattenValues); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - // close file handler |
|
| 87 | - fclose($output); |
|
| 88 | - } |
|
| 86 | + // close file handler |
|
| 87 | + fclose($output); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * @return void |
|
| 92 | - */ |
|
| 93 | - protected function sendCsvHttpHeaders() |
|
| 94 | - { |
|
| 95 | - /** @var Response $response */ |
|
| 96 | - $response = $this->templateVariableContainer->get('response'); |
|
| 97 | - $response->withHeader('Content-Type', 'application/csv'); |
|
| 98 | - $response->withHeader('Content-Disposition', 'attachment; filename="' . basename($this->exportFileNameAndPath) . '"'); |
|
| 99 | - $response->withHeader('Content-Length', filesize($this->exportFileNameAndPath)); |
|
| 100 | - $response->withHeader('Content-Description', 'File Transfer'); |
|
| 101 | - } |
|
| 90 | + /** |
|
| 91 | + * @return void |
|
| 92 | + */ |
|
| 93 | + protected function sendCsvHttpHeaders() |
|
| 94 | + { |
|
| 95 | + /** @var Response $response */ |
|
| 96 | + $response = $this->templateVariableContainer->get('response'); |
|
| 97 | + $response->withHeader('Content-Type', 'application/csv'); |
|
| 98 | + $response->withHeader('Content-Disposition', 'attachment; filename="' . basename($this->exportFileNameAndPath) . '"'); |
|
| 99 | + $response->withHeader('Content-Length', filesize($this->exportFileNameAndPath)); |
|
| 100 | + $response->withHeader('Content-Description', 'File Transfer'); |
|
| 101 | + } |
|
| 102 | 102 | } |
@@ -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; |
@@ -51,1044 +51,1044 @@ |
||
| 51 | 51 | */ |
| 52 | 52 | class VidiDbBackend |
| 53 | 53 | { |
| 54 | - public const OPERATOR_EQUAL_TO_NULL = 'operatorEqualToNull'; |
|
| 55 | - public const OPERATOR_NOT_EQUAL_TO_NULL = 'operatorNotEqualToNull'; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * The TYPO3 page repository. Used for language and workspace overlay |
|
| 59 | - * |
|
| 60 | - * @var PageRepository |
|
| 61 | - */ |
|
| 62 | - protected $pageRepository; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @var Query |
|
| 66 | - */ |
|
| 67 | - protected $query; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Store some info related to table name and its aliases. |
|
| 71 | - * |
|
| 72 | - * @var array |
|
| 73 | - */ |
|
| 74 | - protected $tableNameAliases = array( |
|
| 75 | - 'aliases' => [], |
|
| 76 | - 'aliasIncrement' => [], |
|
| 77 | - ); |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Use to store the current foreign table name alias. |
|
| 81 | - * |
|
| 82 | - * @var string |
|
| 83 | - */ |
|
| 84 | - protected $currentChildTableNameAlias = ''; |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @param Query $query |
|
| 88 | - */ |
|
| 89 | - public function __construct(Query $query) |
|
| 90 | - { |
|
| 91 | - $this->query = $query; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @param $parameters |
|
| 96 | - * @return array |
|
| 97 | - */ |
|
| 98 | - protected static function getTypes($parameters) |
|
| 99 | - { |
|
| 100 | - $types = []; |
|
| 101 | - foreach ($parameters as $parameter) { |
|
| 102 | - if (is_array($parameter)) { |
|
| 103 | - if (MathUtility::canBeInterpretedAsInteger($parameter[0])) { |
|
| 104 | - $types[] = \Doctrine\DBAL\Connection::PARAM_INT_ARRAY; |
|
| 105 | - } else { |
|
| 106 | - $types[] = \Doctrine\DBAL\Connection::PARAM_STR_ARRAY; |
|
| 107 | - } |
|
| 108 | - } else { |
|
| 109 | - if (MathUtility::canBeInterpretedAsInteger($parameter)) { |
|
| 110 | - $types[] = ParameterType::INTEGER; |
|
| 111 | - } else { |
|
| 112 | - $types[] = ParameterType::STRING; |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - return $types; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Returns the result of the query |
|
| 121 | - */ |
|
| 122 | - public function fetchResult() |
|
| 123 | - { |
|
| 124 | - $parameters = []; |
|
| 125 | - $statementParts = $this->parseQuery($parameters); |
|
| 126 | - $statementParts = $this->processStatementStructureForRecursiveMMRelation($statementParts); |
|
| 127 | - $sql = $this->buildQuery($statementParts); |
|
| 128 | - //print $sql; exit(); |
|
| 129 | - |
|
| 130 | - $rows = $this->getConnection() |
|
| 131 | - ->executeQuery($sql, $parameters, self::getTypes($parameters)) |
|
| 132 | - ->fetchAllAssociative(); |
|
| 133 | - |
|
| 134 | - return $this->getContentObjects($rows); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Returns the number of tuples matching the query. |
|
| 139 | - * |
|
| 140 | - * @return int The number of matching tuples |
|
| 141 | - */ |
|
| 142 | - public function countResult() |
|
| 143 | - { |
|
| 144 | - $parameters = []; |
|
| 145 | - $statementParts = $this->parseQuery($parameters); |
|
| 146 | - $statementParts = $this->processStatementStructureForRecursiveMMRelation($statementParts); |
|
| 147 | - $types = self::getTypes($parameters); |
|
| 148 | - |
|
| 149 | - // if limit is set, we need to count the rows "manually" as COUNT(*) ignores LIMIT constraints |
|
| 150 | - if (!empty($statementParts['limit'])) { |
|
| 151 | - $sql = $this->buildQuery($statementParts); |
|
| 152 | - |
|
| 153 | - $count = $this |
|
| 154 | - ->getConnection() |
|
| 155 | - ->executeQuery($sql, $parameters, $types) |
|
| 156 | - ->rowCount(); |
|
| 157 | - } else { |
|
| 158 | - $statementParts['fields'] = array('COUNT(*)'); |
|
| 159 | - // having orderings without grouping is not compatible with non-MySQL DBMS |
|
| 160 | - $statementParts['orderings'] = []; |
|
| 161 | - if (isset($statementParts['keywords']['distinct'])) { |
|
| 162 | - unset($statementParts['keywords']['distinct']); |
|
| 163 | - $distinctField = $this->query->getDistinct() ? $this->query->getDistinct() : 'uid'; |
|
| 164 | - $statementParts['fields'] = array('COUNT(DISTINCT ' . $statementParts['mainTable'] . '.' . $distinctField . ')'); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - $sql = $this->buildQuery($statementParts); |
|
| 168 | - $count = $this |
|
| 169 | - ->getConnection() |
|
| 170 | - ->executeQuery($sql, $parameters, $types) |
|
| 171 | - ->fetchColumn(0); |
|
| 172 | - } |
|
| 173 | - return (int)$count; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * Parses the query and returns the SQL statement parts. |
|
| 178 | - * |
|
| 179 | - * @param array &$parameters |
|
| 180 | - * @return array |
|
| 181 | - */ |
|
| 182 | - public function parseQuery(array &$parameters) |
|
| 183 | - { |
|
| 184 | - $statementParts = []; |
|
| 185 | - $statementParts['keywords'] = []; |
|
| 186 | - $statementParts['tables'] = []; |
|
| 187 | - $statementParts['unions'] = []; |
|
| 188 | - $statementParts['fields'] = []; |
|
| 189 | - $statementParts['where'] = []; |
|
| 190 | - $statementParts['additionalWhereClause'] = []; |
|
| 191 | - $statementParts['orderings'] = []; |
|
| 192 | - $statementParts['limit'] = []; |
|
| 193 | - $query = $this->query; |
|
| 194 | - $source = $query->getSource(); |
|
| 195 | - $this->parseSource($source, $statementParts); |
|
| 196 | - $this->parseConstraint($query->getConstraint(), $source, $statementParts, $parameters); |
|
| 197 | - $this->parseOrderings($query->getOrderings(), $source, $statementParts); |
|
| 198 | - $this->parseLimitAndOffset($query->getLimit(), $query->getOffset(), $statementParts); |
|
| 199 | - $tableNames = array_unique(array_keys($statementParts['tables'] + $statementParts['unions'])); |
|
| 200 | - foreach ($tableNames as $tableNameOrAlias) { |
|
| 201 | - if (is_string($tableNameOrAlias) && strlen($tableNameOrAlias) > 0) { |
|
| 202 | - $this->addAdditionalWhereClause($query->getTypo3QuerySettings(), $tableNameOrAlias, $statementParts); |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - return $statementParts; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * Fiddle with the statement structure to handle recursive MM relations. |
|
| 211 | - * For the recursive MM query to work, we must invert some values. |
|
| 212 | - * Let see if that is the best way of doing that... |
|
| 213 | - * |
|
| 214 | - * @param array $statementParts |
|
| 215 | - * @return array |
|
| 216 | - */ |
|
| 217 | - public function processStatementStructureForRecursiveMMRelation(array $statementParts) |
|
| 218 | - { |
|
| 219 | - if ($this->hasRecursiveMMRelation()) { |
|
| 220 | - $tableName = $this->query->getType(); |
|
| 221 | - |
|
| 222 | - // In order the MM query to work for a recursive MM query, we must invert some values. |
|
| 223 | - // tx_domain_model_foo0 (the alias) <--> tx_domain_model_foo (the origin table name) |
|
| 224 | - $values = []; |
|
| 225 | - foreach ($statementParts['fields'] as $key => $value) { |
|
| 226 | - $values[$key] = str_replace($tableName, $tableName . '0', $value); |
|
| 227 | - } |
|
| 228 | - $statementParts['fields'] = $values; |
|
| 229 | - |
|
| 230 | - // Same comment as above. |
|
| 231 | - $values = []; |
|
| 232 | - foreach ($statementParts['where'] as $key => $value) { |
|
| 233 | - $values[$key] = str_replace($tableName . '0', $tableName, $value); |
|
| 234 | - } |
|
| 235 | - $statementParts['where'] = $values; |
|
| 236 | - |
|
| 237 | - // We must be more restrictive by transforming the "left" union by "inner" |
|
| 238 | - $values = []; |
|
| 239 | - foreach ($statementParts['unions'] as $key => $value) { |
|
| 240 | - $values[$key] = str_replace('LEFT JOIN', 'INNER JOIN', $value); |
|
| 241 | - } |
|
| 242 | - $statementParts['unions'] = $values; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - return $statementParts; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * Tell whether there is a recursive MM relation. |
|
| 250 | - * |
|
| 251 | - * @return bool |
|
| 252 | - */ |
|
| 253 | - public function hasRecursiveMMRelation() |
|
| 254 | - { |
|
| 255 | - return isset($this->tableNameAliases['aliasIncrement'][$this->query->getType()]); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * Returns the statement, ready to be executed. |
|
| 260 | - * |
|
| 261 | - * @param array $statementParts The SQL statement parts |
|
| 262 | - * @return string The SQL statement |
|
| 263 | - */ |
|
| 264 | - public function buildQuery(array $statementParts) |
|
| 265 | - { |
|
| 266 | - // Add more statement to the UNION part. |
|
| 267 | - if (!empty($statementParts['unions'])) { |
|
| 268 | - foreach ($statementParts['unions'] as $tableName => $unionPart) { |
|
| 269 | - if (!empty($statementParts['additionalWhereClause'][$tableName])) { |
|
| 270 | - $statementParts['unions'][$tableName] .= ' AND ' . implode(' AND ', $statementParts['additionalWhereClause'][$tableName]); |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - $statement = 'SELECT ' . implode(' ', $statementParts['keywords']) . ' ' . implode(',', $statementParts['fields']) . ' FROM ' . implode(' ', $statementParts['tables']) . ' ' . implode(' ', $statementParts['unions']); |
|
| 276 | - if (!empty($statementParts['where'])) { |
|
| 277 | - $statement .= ' WHERE ' . implode('', $statementParts['where']); |
|
| 278 | - if (!empty($statementParts['additionalWhereClause'][$this->query->getType()])) { |
|
| 279 | - $statement .= ' AND ' . implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]); |
|
| 280 | - } |
|
| 281 | - } elseif (!empty($statementParts['additionalWhereClause'])) { |
|
| 282 | - $statement .= ' WHERE ' . implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]); |
|
| 283 | - } |
|
| 284 | - if (!empty($statementParts['orderings'])) { |
|
| 285 | - $statement .= ' ORDER BY ' . implode(', ', $statementParts['orderings']); |
|
| 286 | - } |
|
| 287 | - if (!empty($statementParts['limit'])) { |
|
| 288 | - $statement .= ' LIMIT ' . $statementParts['limit']; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - return $statement; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * Transforms a Query Source into SQL and parameter arrays |
|
| 296 | - * |
|
| 297 | - * @param SourceInterface $source The source |
|
| 298 | - * @param array &$sql |
|
| 299 | - * @return void |
|
| 300 | - */ |
|
| 301 | - protected function parseSource(SourceInterface $source, array &$sql) |
|
| 302 | - { |
|
| 303 | - $tableName = $this->getTableName(); |
|
| 304 | - $sql['fields'][$tableName] = $tableName . '.*'; |
|
| 305 | - if ($this->query->getDistinct()) { |
|
| 306 | - $sql['fields'][$tableName] = $tableName . '.' . $this->query->getDistinct(); |
|
| 307 | - $sql['keywords']['distinct'] = 'DISTINCT'; |
|
| 308 | - } |
|
| 309 | - $sql['tables'][$tableName] = $tableName; |
|
| 310 | - $sql['mainTable'] = $tableName; |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * Transforms a constraint into SQL and parameter arrays |
|
| 315 | - * |
|
| 316 | - * @param ConstraintInterface $constraint The constraint |
|
| 317 | - * @param SourceInterface $source The source |
|
| 318 | - * @param array &$statementParts The query parts |
|
| 319 | - * @param array &$parameters The parameters that will replace the markers |
|
| 320 | - * @return void |
|
| 321 | - */ |
|
| 322 | - protected function parseConstraint(ConstraintInterface $constraint = null, SourceInterface $source, array &$statementParts, array &$parameters) |
|
| 323 | - { |
|
| 324 | - if ($constraint instanceof AndInterface) { |
|
| 325 | - $statementParts['where'][] = '('; |
|
| 326 | - $this->parseConstraint($constraint->getConstraint1(), $source, $statementParts, $parameters); |
|
| 327 | - $statementParts['where'][] = ' AND '; |
|
| 328 | - $this->parseConstraint($constraint->getConstraint2(), $source, $statementParts, $parameters); |
|
| 329 | - $statementParts['where'][] = ')'; |
|
| 330 | - } elseif ($constraint instanceof OrInterface) { |
|
| 331 | - $statementParts['where'][] = '('; |
|
| 332 | - $this->parseConstraint($constraint->getConstraint1(), $source, $statementParts, $parameters); |
|
| 333 | - $statementParts['where'][] = ' OR '; |
|
| 334 | - $this->parseConstraint($constraint->getConstraint2(), $source, $statementParts, $parameters); |
|
| 335 | - $statementParts['where'][] = ')'; |
|
| 336 | - } elseif ($constraint instanceof NotInterface) { |
|
| 337 | - $statementParts['where'][] = 'NOT ('; |
|
| 338 | - $this->parseConstraint($constraint->getConstraint(), $source, $statementParts, $parameters); |
|
| 339 | - $statementParts['where'][] = ')'; |
|
| 340 | - } elseif ($constraint instanceof ComparisonInterface) { |
|
| 341 | - $this->parseComparison($constraint, $source, $statementParts, $parameters); |
|
| 342 | - } |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - /** |
|
| 346 | - * Parse a Comparison into SQL and parameter arrays. |
|
| 347 | - * |
|
| 348 | - * @param ComparisonInterface $comparison The comparison to parse |
|
| 349 | - * @param SourceInterface $source The source |
|
| 350 | - * @param array &$statementParts SQL query parts to add to |
|
| 351 | - * @param array &$parameters Parameters to bind to the SQL |
|
| 352 | - * @return void |
|
| 353 | - * @throws Exception\RepositoryException |
|
| 354 | - */ |
|
| 355 | - protected function parseComparison(ComparisonInterface $comparison, SourceInterface $source, array &$statementParts, array &$parameters) |
|
| 356 | - { |
|
| 357 | - $operand1 = $comparison->getOperand1(); |
|
| 358 | - $operator = $comparison->getOperator(); |
|
| 359 | - $operand2 = $comparison->getOperand2(); |
|
| 360 | - if ($operator === QueryInterface::OPERATOR_IN) { |
|
| 361 | - $items = []; |
|
| 362 | - $hasValue = false; |
|
| 363 | - foreach ($operand2 as $value) { |
|
| 364 | - $value = $this->getPlainValue($value); |
|
| 365 | - if ($value !== null) { |
|
| 366 | - $items[] = $value; |
|
| 367 | - $hasValue = true; |
|
| 368 | - } |
|
| 369 | - } |
|
| 370 | - if ($hasValue === false) { |
|
| 371 | - $statementParts['where'][] = '1<>1'; |
|
| 372 | - } else { |
|
| 373 | - $this->parseDynamicOperand($operand1, $operator, $source, $statementParts, $parameters, null); |
|
| 374 | - $parameters[] = $items; |
|
| 375 | - } |
|
| 376 | - } elseif ($operator === QueryInterface::OPERATOR_CONTAINS) { |
|
| 377 | - if ($operand2 === null) { |
|
| 378 | - $statementParts['where'][] = '1<>1'; |
|
| 379 | - } else { |
|
| 380 | - throw new \Exception('Not implemented! Contact extension author.', 1412931227); |
|
| 381 | - # @todo re-implement me if necessary. |
|
| 382 | - #$tableName = $this->query->getType(); |
|
| 383 | - #$propertyName = $operand1->getPropertyName(); |
|
| 384 | - #while (strpos($propertyName, '.') !== false) { |
|
| 385 | - # $this->addUnionStatement($tableName, $propertyName, $statementParts); |
|
| 386 | - #} |
|
| 387 | - #$columnName = $propertyName; |
|
| 388 | - #$columnMap = $propertyName; |
|
| 389 | - #$typeOfRelation = $columnMap instanceof ColumnMap ? $columnMap->getTypeOfRelation() : null; |
|
| 390 | - #if ($typeOfRelation === ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) { |
|
| 391 | - # $relationTableName = $columnMap->getRelationTableName(); |
|
| 392 | - # $statementParts['where'][] = $tableName . '.uid IN (SELECT ' . $columnMap->getParentKeyFieldName() . ' FROM ' . $relationTableName . ' WHERE ' . $columnMap->getChildKeyFieldName() . '=?)'; |
|
| 393 | - # $parameters[] = intval($this->getPlainValue($operand2)); |
|
| 394 | - #} elseif ($typeOfRelation === ColumnMap::RELATION_HAS_MANY) { |
|
| 395 | - # $parentKeyFieldName = $columnMap->getParentKeyFieldName(); |
|
| 396 | - # if (isset($parentKeyFieldName)) { |
|
| 397 | - # $childTableName = $columnMap->getChildTableName(); |
|
| 398 | - # $statementParts['where'][] = $tableName . '.uid=(SELECT ' . $childTableName . '.' . $parentKeyFieldName . ' FROM ' . $childTableName . ' WHERE ' . $childTableName . '.uid=?)'; |
|
| 399 | - # $parameters[] = intval($this->getPlainValue($operand2)); |
|
| 400 | - # } else { |
|
| 401 | - # $statementParts['where'][] = 'FIND_IN_SET(?,' . $tableName . '.' . $columnName . ')'; |
|
| 402 | - # $parameters[] = intval($this->getPlainValue($operand2)); |
|
| 403 | - # } |
|
| 404 | - #} else { |
|
| 405 | - # throw new Exception\RepositoryException('Unsupported or non-existing property name "' . $propertyName . '" used in relation matching.', 1327065745); |
|
| 406 | - #} |
|
| 407 | - } |
|
| 408 | - } else { |
|
| 409 | - if ($operand2 === null) { |
|
| 410 | - if ($operator === QueryInterface::OPERATOR_EQUAL_TO) { |
|
| 411 | - $operator = self::OPERATOR_EQUAL_TO_NULL; |
|
| 412 | - } elseif ($operator === QueryInterface::OPERATOR_NOT_EQUAL_TO) { |
|
| 413 | - $operator = self::OPERATOR_NOT_EQUAL_TO_NULL; |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - $this->parseDynamicOperand($operand1, $operator, $source, $statementParts, $parameters); |
|
| 417 | - $parameters[] = $this->getPlainValue($operand2); |
|
| 418 | - } |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * Returns a plain value, i.e. objects are flattened if possible. |
|
| 423 | - * |
|
| 424 | - * @param mixed $input |
|
| 425 | - * @return mixed |
|
| 426 | - * @throws UnexpectedTypeException |
|
| 427 | - */ |
|
| 428 | - protected function getPlainValue($input) |
|
| 429 | - { |
|
| 430 | - if (is_array($input)) { |
|
| 431 | - throw new UnexpectedTypeException('An array could not be converted to a plain value.', 1274799932); |
|
| 432 | - } |
|
| 433 | - if ($input instanceof \DateTime) { |
|
| 434 | - return $input->format('U'); |
|
| 435 | - } elseif (is_object($input)) { |
|
| 436 | - if ($input instanceof LazyLoadingProxy) { |
|
| 437 | - $realInput = $input->_loadRealInstance(); |
|
| 438 | - } else { |
|
| 439 | - $realInput = $input; |
|
| 440 | - } |
|
| 441 | - if ($realInput instanceof DomainObjectInterface) { |
|
| 442 | - return $realInput->getUid(); |
|
| 443 | - } else { |
|
| 444 | - throw new UnexpectedTypeException('An object of class "' . get_class($realInput) . '" could not be converted to a plain value.', 1274799934); |
|
| 445 | - } |
|
| 446 | - } elseif (is_bool($input)) { |
|
| 447 | - return $input === true ? 1 : 0; |
|
| 448 | - } else { |
|
| 449 | - return $input; |
|
| 450 | - } |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - /** |
|
| 454 | - * Parse a DynamicOperand into SQL and parameter arrays. |
|
| 455 | - * |
|
| 456 | - * @param DynamicOperandInterface $operand |
|
| 457 | - * @param string $operator One of the JCR_OPERATOR_* constants |
|
| 458 | - * @param SourceInterface $source The source |
|
| 459 | - * @param array &$statementParts The query parts |
|
| 460 | - * @param array &$parameters The parameters that will replace the markers |
|
| 461 | - * @param string $valueFunction an optional SQL function to apply to the operand value |
|
| 462 | - * @return void |
|
| 463 | - */ |
|
| 464 | - protected function parseDynamicOperand(DynamicOperandInterface $operand, $operator, SourceInterface $source, array &$statementParts, array &$parameters, $valueFunction = null) |
|
| 465 | - { |
|
| 466 | - if ($operand instanceof LowerCaseInterface) { |
|
| 467 | - $this->parseDynamicOperand($operand->getOperand(), $operator, $source, $statementParts, $parameters, 'LOWER'); |
|
| 468 | - } elseif ($operand instanceof UpperCaseInterface) { |
|
| 469 | - $this->parseDynamicOperand($operand->getOperand(), $operator, $source, $statementParts, $parameters, 'UPPER'); |
|
| 470 | - } elseif ($operand instanceof PropertyValueInterface) { |
|
| 471 | - $propertyName = $operand->getPropertyName(); |
|
| 472 | - |
|
| 473 | - // Reset value. |
|
| 474 | - $this->currentChildTableNameAlias = ''; |
|
| 475 | - |
|
| 476 | - if ($source instanceof SelectorInterface) { |
|
| 477 | - $tableName = $this->query->getType(); |
|
| 478 | - while (strpos($propertyName, '.') !== false) { |
|
| 479 | - $this->addUnionStatement($tableName, $propertyName, $statementParts); |
|
| 480 | - } |
|
| 481 | - } elseif ($source instanceof JoinInterface) { |
|
| 482 | - $tableName = $source->getJoinCondition()->getSelector1Name(); |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - $columnName = $propertyName; |
|
| 486 | - $resolvedOperator = $this->resolveOperator($operator); |
|
| 487 | - $constraintSQL = ''; |
|
| 488 | - |
|
| 489 | - $marker = $operator === QueryInterface::OPERATOR_IN |
|
| 490 | - ? '(?)' |
|
| 491 | - : '?'; |
|
| 492 | - |
|
| 493 | - if ($valueFunction === null) { |
|
| 494 | - $constraintSQL .= (!empty($tableName) ? $tableName . '.' : '') . $columnName . ' ' . $resolvedOperator . ' ' . $marker; |
|
| 495 | - } else { |
|
| 496 | - $constraintSQL .= $valueFunction . '(' . (!empty($tableName) ? $tableName . '.' : '') . $columnName . ') ' . $resolvedOperator . ' ' . $marker; |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - if (isset($tableName) && !empty($this->currentChildTableNameAlias)) { |
|
| 500 | - $constraintSQL = $this->replaceTableNameByAlias($tableName, $this->currentChildTableNameAlias, $constraintSQL); |
|
| 501 | - } |
|
| 502 | - $statementParts['where'][] = $constraintSQL; |
|
| 503 | - } |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - /** |
|
| 507 | - * @param string &$tableName |
|
| 508 | - * @param string &$propertyPath |
|
| 509 | - * @param array &$statementParts |
|
| 510 | - */ |
|
| 511 | - protected function addUnionStatement(&$tableName, &$propertyPath, array &$statementParts) |
|
| 512 | - { |
|
| 513 | - $table = Tca::table($tableName); |
|
| 514 | - |
|
| 515 | - $explodedPropertyPath = explode('.', $propertyPath, 2); |
|
| 516 | - $fieldName = $explodedPropertyPath[0]; |
|
| 517 | - |
|
| 518 | - // Field of type "group" are special because property path must contain the table name |
|
| 519 | - // to determine the relation type. Example for sys_category, property path will look like "items.sys_file" |
|
| 520 | - $parts = explode('.', $propertyPath, 3); |
|
| 521 | - if ($table->field($fieldName)->isGroup() && count($parts) > 2) { |
|
| 522 | - $explodedPropertyPath[0] = $parts[0] . '.' . $parts[1]; |
|
| 523 | - $explodedPropertyPath[1] = $parts[2]; |
|
| 524 | - $fieldName = $explodedPropertyPath[0]; |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - $parentKeyFieldName = $table->field($fieldName)->getForeignField(); |
|
| 528 | - $childTableName = $table->field($fieldName)->getForeignTable(); |
|
| 529 | - |
|
| 530 | - if ($childTableName === null) { |
|
| 531 | - throw new InvalidRelationConfigurationException('The relation information for property "' . $fieldName . '" of class "' . $tableName . '" is missing.', 1353170925); |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - if ($table->field($fieldName)->hasOne()) { // includes relation "one-to-one" and "many-to-one" |
|
| 535 | - // sometimes the opposite relation is not defined. We don't want to force this config for backward compatibility reasons. |
|
| 536 | - // $parentKeyFieldName === null does the trick somehow. Before condition was if (isset($parentKeyFieldName)) |
|
| 537 | - if ($table->field($fieldName)->hasRelationManyToOne() || $parentKeyFieldName === null) { |
|
| 538 | - $statementParts['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.' . $fieldName . '=' . $childTableName . '.uid'; |
|
| 539 | - } else { |
|
| 540 | - $statementParts['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.uid=' . $childTableName . '.' . $parentKeyFieldName; |
|
| 541 | - } |
|
| 542 | - } elseif ($table->field($fieldName)->hasRelationManyToMany()) { |
|
| 543 | - $relationTableName = $table->field($fieldName)->getManyToManyTable(); |
|
| 544 | - |
|
| 545 | - $parentKeyFieldName = $table->field($fieldName)->isOppositeRelation() ? 'uid_foreign' : 'uid_local'; |
|
| 546 | - $childKeyFieldName = !$table->field($fieldName)->isOppositeRelation() ? 'uid_foreign' : 'uid_local'; |
|
| 547 | - |
|
| 548 | - // MM table e.g sys_category_record_mm |
|
| 549 | - $relationTableNameAlias = $this->generateAlias($relationTableName); |
|
| 550 | - $join = sprintf( |
|
| 551 | - 'LEFT JOIN %s AS %s ON %s.uid=%s.%s', |
|
| 552 | - $relationTableName, |
|
| 553 | - $relationTableNameAlias, |
|
| 554 | - $tableName, |
|
| 555 | - $relationTableNameAlias, |
|
| 556 | - $parentKeyFieldName |
|
| 557 | - ); |
|
| 558 | - $statementParts['unions'][$relationTableNameAlias] = $join; |
|
| 559 | - |
|
| 560 | - // Foreign table e.g sys_category |
|
| 561 | - $childTableNameAlias = $this->generateAlias($childTableName); |
|
| 562 | - $this->currentChildTableNameAlias = $childTableNameAlias; |
|
| 563 | - $join = sprintf( |
|
| 564 | - 'LEFT JOIN %s AS %s ON %s.%s=%s.uid', |
|
| 565 | - $childTableName, |
|
| 566 | - $childTableNameAlias, |
|
| 567 | - $relationTableNameAlias, |
|
| 568 | - $childKeyFieldName, |
|
| 569 | - $childTableNameAlias |
|
| 570 | - ); |
|
| 571 | - $statementParts['unions'][$childTableNameAlias] = $join; |
|
| 572 | - |
|
| 573 | - // Find a possible table name for a MM condition. |
|
| 574 | - $tableNameCondition = $table->field($fieldName)->getAdditionalTableNameCondition(); |
|
| 575 | - if ($tableNameCondition) { |
|
| 576 | - // If we can find a source file name, we can then retrieve more MM conditions from the TCA such as a field name. |
|
| 577 | - $sourceFileName = $this->query->getSourceFieldName(); |
|
| 578 | - if (empty($sourceFileName)) { |
|
| 579 | - $additionalMMConditions = array( |
|
| 580 | - 'tablenames' => $tableNameCondition, |
|
| 581 | - ); |
|
| 582 | - } else { |
|
| 583 | - $additionalMMConditions = Tca::table($tableNameCondition)->field($sourceFileName)->getAdditionalMMCondition(); |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - foreach ($additionalMMConditions as $additionalFieldName => $additionalMMCondition) { |
|
| 587 | - $additionalJoin = sprintf(' AND %s.%s = "%s"', $relationTableNameAlias, $additionalFieldName, $additionalMMCondition); |
|
| 588 | - $statementParts['unions'][$relationTableNameAlias] .= $additionalJoin; |
|
| 589 | - |
|
| 590 | - $additionalJoin = sprintf(' AND %s.%s = "%s"', $relationTableNameAlias, $additionalFieldName, $additionalMMCondition); |
|
| 591 | - $statementParts['unions'][$childTableNameAlias] .= $additionalJoin; |
|
| 592 | - } |
|
| 593 | - } |
|
| 594 | - } elseif ($table->field($fieldName)->hasMany()) { // includes relations "many-to-one" and "csv" relations |
|
| 595 | - $childTableNameAlias = $this->generateAlias($childTableName); |
|
| 596 | - $this->currentChildTableNameAlias = $childTableNameAlias; |
|
| 597 | - |
|
| 598 | - if (isset($parentKeyFieldName)) { |
|
| 599 | - $join = sprintf( |
|
| 600 | - 'LEFT JOIN %s AS %s ON %s.uid=%s.%s', |
|
| 601 | - $childTableName, |
|
| 602 | - $childTableNameAlias, |
|
| 603 | - $tableName, |
|
| 604 | - $childTableNameAlias, |
|
| 605 | - $parentKeyFieldName |
|
| 606 | - ); |
|
| 607 | - $statementParts['unions'][$childTableNameAlias] = $join; |
|
| 608 | - } else { |
|
| 609 | - $join = sprintf( |
|
| 610 | - 'LEFT JOIN %s AS %s ON (FIND_IN_SET(%s.uid, %s.%s))', |
|
| 611 | - $childTableName, |
|
| 612 | - $childTableNameAlias, |
|
| 613 | - $childTableNameAlias, |
|
| 614 | - $tableName, |
|
| 615 | - $fieldName |
|
| 616 | - ); |
|
| 617 | - $statementParts['unions'][$childTableNameAlias] = $join; |
|
| 618 | - } |
|
| 619 | - } else { |
|
| 620 | - throw new Exception('Could not determine type of relation.', 1252502725); |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - $statementParts['keywords']['distinct'] = 'DISTINCT'; |
|
| 624 | - $propertyPath = $explodedPropertyPath[1]; |
|
| 625 | - $tableName = $childTableName; |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - /** |
|
| 629 | - * Returns the SQL operator for the given JCR operator type. |
|
| 630 | - * |
|
| 631 | - * @param string $operator One of the JCR_OPERATOR_* constants |
|
| 632 | - * @return string an SQL operator |
|
| 633 | - * @throws Exception |
|
| 634 | - */ |
|
| 635 | - protected function resolveOperator($operator) |
|
| 636 | - { |
|
| 637 | - switch ($operator) { |
|
| 638 | - case self::OPERATOR_EQUAL_TO_NULL: |
|
| 639 | - $operator = 'IS'; |
|
| 640 | - break; |
|
| 641 | - case self::OPERATOR_NOT_EQUAL_TO_NULL: |
|
| 642 | - $operator = 'IS NOT'; |
|
| 643 | - break; |
|
| 644 | - case QueryInterface::OPERATOR_IN: |
|
| 645 | - $operator = 'IN'; |
|
| 646 | - break; |
|
| 647 | - case QueryInterface::OPERATOR_EQUAL_TO: |
|
| 648 | - $operator = '='; |
|
| 649 | - break; |
|
| 650 | - case QueryInterface::OPERATOR_NOT_EQUAL_TO: |
|
| 651 | - $operator = '!='; |
|
| 652 | - break; |
|
| 653 | - case QueryInterface::OPERATOR_LESS_THAN: |
|
| 654 | - $operator = '<'; |
|
| 655 | - break; |
|
| 656 | - case QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO: |
|
| 657 | - $operator = '<='; |
|
| 658 | - break; |
|
| 659 | - case QueryInterface::OPERATOR_GREATER_THAN: |
|
| 660 | - $operator = '>'; |
|
| 661 | - break; |
|
| 662 | - case QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO: |
|
| 663 | - $operator = '>='; |
|
| 664 | - break; |
|
| 665 | - case QueryInterface::OPERATOR_LIKE: |
|
| 666 | - $operator = 'LIKE'; |
|
| 667 | - break; |
|
| 668 | - default: |
|
| 669 | - throw new Exception('Unsupported operator encountered.', 1242816073); |
|
| 670 | - } |
|
| 671 | - return $operator; |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - /** |
|
| 675 | - * Adds additional WHERE statements according to the query settings. |
|
| 676 | - * |
|
| 677 | - * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings |
|
| 678 | - * @param string $tableNameOrAlias The table name to add the additional where clause for |
|
| 679 | - * @param array &$statementParts |
|
| 680 | - * @return void |
|
| 681 | - */ |
|
| 682 | - protected function addAdditionalWhereClause(QuerySettingsInterface $querySettings, $tableNameOrAlias, &$statementParts) |
|
| 683 | - { |
|
| 684 | - $this->addVisibilityConstraintStatement($querySettings, $tableNameOrAlias, $statementParts); |
|
| 685 | - if ($querySettings->getRespectSysLanguage()) { |
|
| 686 | - $this->addSysLanguageStatement($tableNameOrAlias, $statementParts, $querySettings); |
|
| 687 | - } |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - /** |
|
| 691 | - * Adds enableFields and deletedClause to the query if necessary |
|
| 692 | - * |
|
| 693 | - * @param QuerySettingsInterface $querySettings |
|
| 694 | - * @param string $tableNameOrAlias The database table name |
|
| 695 | - * @param array &$statementParts The query parts |
|
| 696 | - * @return void |
|
| 697 | - */ |
|
| 698 | - protected function addVisibilityConstraintStatement(QuerySettingsInterface $querySettings, $tableNameOrAlias, array &$statementParts) |
|
| 699 | - { |
|
| 700 | - $statement = ''; |
|
| 701 | - $tableName = $this->resolveTableNameAlias($tableNameOrAlias); |
|
| 702 | - if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) { |
|
| 703 | - $ignoreEnableFields = $querySettings->getIgnoreEnableFields(); |
|
| 704 | - $enableFieldsToBeIgnored = $querySettings->getEnableFieldsToBeIgnored(); |
|
| 705 | - $includeDeleted = $querySettings->getIncludeDeleted(); |
|
| 706 | - if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend()) { |
|
| 707 | - $statement .= $this->getFrontendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $enableFieldsToBeIgnored, $includeDeleted); |
|
| 708 | - } else { |
|
| 709 | - // 'BE' case |
|
| 710 | - $statement .= $this->getBackendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $includeDeleted); |
|
| 711 | - } |
|
| 712 | - |
|
| 713 | - // Remove the prefixing "AND" if any. |
|
| 714 | - if (!empty($statement)) { |
|
| 715 | - $statement = strtolower(substr($statement, 1, 3)) === 'and' ? substr($statement, 5) : $statement; |
|
| 716 | - $statementParts['additionalWhereClause'][$tableNameOrAlias][] = $statement; |
|
| 717 | - } |
|
| 718 | - } |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - /** |
|
| 722 | - * Returns constraint statement for frontend context |
|
| 723 | - * |
|
| 724 | - * @param string $tableNameOrAlias |
|
| 725 | - * @param boolean $ignoreEnableFields A flag indicating whether the enable fields should be ignored |
|
| 726 | - * @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. |
|
| 727 | - * @param boolean $includeDeleted A flag indicating whether deleted records should be included |
|
| 728 | - * @return string |
|
| 729 | - * @throws Exception\InconsistentQuerySettingsException |
|
| 730 | - */ |
|
| 731 | - protected function getFrontendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $enableFieldsToBeIgnored, $includeDeleted) |
|
| 732 | - { |
|
| 733 | - $statement = ''; |
|
| 734 | - $tableName = $this->resolveTableNameAlias($tableNameOrAlias); |
|
| 735 | - if ($ignoreEnableFields && !$includeDeleted) { |
|
| 736 | - if (count($enableFieldsToBeIgnored)) { |
|
| 737 | - // array_combine() is necessary because of the way \TYPO3\CMS\Frontend\Page\PageRepository::enableFields() is implemented |
|
| 738 | - $statement .= $this->getPageRepository()->enableFields($tableName, -1, array_combine($enableFieldsToBeIgnored, $enableFieldsToBeIgnored)); |
|
| 739 | - } else { |
|
| 740 | - $statement .= $this->getPageRepository()->deleteClause($tableName); |
|
| 741 | - } |
|
| 742 | - } elseif (!$ignoreEnableFields && !$includeDeleted) { |
|
| 743 | - $statement .= $this->getPageRepository()->enableFields($tableName); |
|
| 744 | - } elseif (!$ignoreEnableFields && $includeDeleted) { |
|
| 745 | - throw new InconsistentQuerySettingsException('Query setting "ignoreEnableFields=false" can not be used together with "includeDeleted=true" in frontend context.', 1327678173); |
|
| 746 | - } |
|
| 747 | - return $this->replaceTableNameByAlias($tableName, $tableNameOrAlias, $statement); |
|
| 748 | - } |
|
| 749 | - |
|
| 750 | - /** |
|
| 751 | - * Returns constraint statement for backend context |
|
| 752 | - * |
|
| 753 | - * @param string $tableNameOrAlias |
|
| 754 | - * @param boolean $ignoreEnableFields A flag indicating whether the enable fields should be ignored |
|
| 755 | - * @param boolean $includeDeleted A flag indicating whether deleted records should be included |
|
| 756 | - * @return string |
|
| 757 | - */ |
|
| 758 | - protected function getBackendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $includeDeleted) |
|
| 759 | - { |
|
| 760 | - $tableName = $this->resolveTableNameAlias($tableNameOrAlias); |
|
| 761 | - $statement = ''; |
|
| 762 | - if (!$ignoreEnableFields) { |
|
| 763 | - $statement .= BackendUtility::BEenableFields($tableName); |
|
| 764 | - } |
|
| 765 | - |
|
| 766 | - // If the table is found to have "workspace" support, add the corresponding fields in the statement. |
|
| 767 | - if (Tca::table($tableName)->hasWorkspaceSupport()) { |
|
| 768 | - if ($this->getBackendUser()->workspace === 0) { |
|
| 769 | - $statement .= ' AND ' . $tableName . '.t3ver_state<=' . new VersionState(VersionState::DEFAULT_STATE); |
|
| 770 | - } else { |
|
| 771 | - // Show only records of live and of the current workspace |
|
| 772 | - // In case we are in a Versioning preview |
|
| 773 | - $statement .= ' AND (' . |
|
| 774 | - $tableName . '.t3ver_wsid=0 OR ' . |
|
| 775 | - $tableName . '.t3ver_wsid=' . (int)$this->getBackendUser()->workspace . |
|
| 776 | - ')'; |
|
| 777 | - } |
|
| 778 | - |
|
| 779 | - // Check if this segment make sense here or whether it should be in the "if" part when we have workspace = 0 |
|
| 780 | - $statement .= ' AND ' . $tableName . '.pid<>-1'; |
|
| 781 | - } |
|
| 782 | - |
|
| 783 | - if (!$includeDeleted) { |
|
| 784 | - $statement .= BackendUtility::deleteClause($tableName); |
|
| 785 | - } |
|
| 786 | - |
|
| 787 | - return $this->replaceTableNameByAlias($tableName, $tableNameOrAlias, $statement); |
|
| 788 | - } |
|
| 789 | - |
|
| 790 | - /** |
|
| 791 | - * Builds the language field statement |
|
| 792 | - * |
|
| 793 | - * @param string $tableNameOrAlias The database table name |
|
| 794 | - * @param array &$statementParts The query parts |
|
| 795 | - * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings |
|
| 796 | - * @return void |
|
| 797 | - * @throws Exception |
|
| 798 | - */ |
|
| 799 | - protected function addSysLanguageStatement($tableNameOrAlias, array &$statementParts, $querySettings) |
|
| 800 | - { |
|
| 801 | - $tableName = $this->resolveTableNameAlias($tableNameOrAlias); |
|
| 802 | - if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) { |
|
| 803 | - if (!empty($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])) { |
|
| 804 | - // Select all entries for the current language |
|
| 805 | - $additionalWhereClause = $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . ' IN (' . intval($querySettings->getLanguageUid()) . ',-1)'; |
|
| 806 | - // If any language is set -> get those entries which are not translated yet |
|
| 807 | - // They will be removed by t3lib_page::getRecordOverlay if not matching overlay mode |
|
| 808 | - if (isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']) |
|
| 809 | - && $querySettings->getLanguageUid() > 0 |
|
| 810 | - ) { |
|
| 811 | - $additionalWhereClause .= ' OR (' . $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=0' . |
|
| 812 | - ' AND ' . $tableNameOrAlias . '.uid NOT IN (SELECT ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] . |
|
| 813 | - ' FROM ' . $tableName . |
|
| 814 | - ' WHERE ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] . '>0' . |
|
| 815 | - ' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '>0'; |
|
| 816 | - |
|
| 817 | - // Add delete clause to ensure all entries are loaded |
|
| 818 | - if (isset($GLOBALS['TCA'][$tableName]['ctrl']['delete'])) { |
|
| 819 | - $additionalWhereClause .= ' AND ' . $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['delete'] . '=0'; |
|
| 820 | - } |
|
| 821 | - $additionalWhereClause .= '))'; |
|
| 822 | - } |
|
| 823 | - $statementParts['additionalWhereClause'][$tableNameOrAlias][] = '(' . $additionalWhereClause . ')'; |
|
| 824 | - } |
|
| 825 | - } |
|
| 826 | - } |
|
| 827 | - |
|
| 828 | - /** |
|
| 829 | - * Transforms orderings into SQL. |
|
| 830 | - * |
|
| 831 | - * @param array $orderings An array of orderings (Tx_Extbase_Persistence_QOM_Ordering) |
|
| 832 | - * @param SourceInterface $source The source |
|
| 833 | - * @param array &$statementParts The query parts |
|
| 834 | - * @return void |
|
| 835 | - * @throws Exception\UnsupportedOrderException |
|
| 836 | - */ |
|
| 837 | - protected function parseOrderings(array $orderings, SourceInterface $source, array &$statementParts) |
|
| 838 | - { |
|
| 839 | - foreach ($orderings as $fieldNameAndPath => $order) { |
|
| 840 | - switch ($order) { |
|
| 841 | - case QueryInterface::ORDER_ASCENDING: |
|
| 842 | - $order = 'ASC'; |
|
| 843 | - break; |
|
| 844 | - case QueryInterface::ORDER_DESCENDING: |
|
| 845 | - $order = 'DESC'; |
|
| 846 | - break; |
|
| 847 | - default: |
|
| 848 | - throw new UnsupportedOrderException('Unsupported order encountered.', 1456845126); |
|
| 849 | - } |
|
| 850 | - |
|
| 851 | - $tableName = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->query->getType()); |
|
| 852 | - $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $tableName); |
|
| 853 | - $statementParts['orderings'][] = sprintf('%s.%s %s', $tableName, $fieldName, $order); |
|
| 854 | - } |
|
| 855 | - } |
|
| 856 | - |
|
| 857 | - /** |
|
| 858 | - * Transforms limit and offset into SQL |
|
| 859 | - * |
|
| 860 | - * @param int $limit |
|
| 861 | - * @param int $offset |
|
| 862 | - * @param array &$statementParts |
|
| 863 | - * @return void |
|
| 864 | - */ |
|
| 865 | - protected function parseLimitAndOffset($limit, $offset, array &$statementParts) |
|
| 866 | - { |
|
| 867 | - if ($limit !== null && $offset !== null) { |
|
| 868 | - $statementParts['limit'] = intval($offset) . ', ' . intval($limit); |
|
| 869 | - } elseif ($limit !== null) { |
|
| 870 | - $statementParts['limit'] = intval($limit); |
|
| 871 | - } |
|
| 872 | - } |
|
| 873 | - |
|
| 874 | - /** |
|
| 875 | - * @param array $rows |
|
| 876 | - * @return array |
|
| 877 | - */ |
|
| 878 | - protected function getContentObjects(array $rows): array |
|
| 879 | - { |
|
| 880 | - $contentObjects = []; |
|
| 881 | - foreach ($rows as $row) { |
|
| 882 | - // Get language uid from querySettings. |
|
| 883 | - // Ensure the backend handling is not broken (fallback to Get parameter 'L' if needed) |
|
| 884 | - $overlaidRow = $this->doLanguageAndWorkspaceOverlay( |
|
| 885 | - $row, |
|
| 886 | - $this->query->getTypo3QuerySettings() |
|
| 887 | - ); |
|
| 888 | - |
|
| 889 | - $contentObjects[] = GeneralUtility::makeInstance( |
|
| 890 | - Content::class, |
|
| 891 | - $this->query->getType(), |
|
| 892 | - $overlaidRow |
|
| 893 | - ); |
|
| 894 | - } |
|
| 895 | - |
|
| 896 | - return $contentObjects; |
|
| 897 | - } |
|
| 898 | - |
|
| 899 | - /** |
|
| 900 | - * Performs workspace and language overlay on the given row array. The language and workspace id is automatically |
|
| 901 | - * detected (depending on FE or BE context). You can also explicitly set the language/workspace id. |
|
| 902 | - * |
|
| 903 | - * @param array $row |
|
| 904 | - * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings |
|
| 905 | - * @return array |
|
| 906 | - */ |
|
| 907 | - protected function doLanguageAndWorkspaceOverlay(array $row, $querySettings) |
|
| 908 | - { |
|
| 909 | - $tableName = $this->getTableName(); |
|
| 910 | - |
|
| 911 | - $pageRepository = $this->getPageRepository(); |
|
| 912 | - if (is_object($GLOBALS['TSFE'])) { |
|
| 913 | - $languageMode = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('language', 'legacyLanguageMode'); |
|
| 914 | - #if ($this->isBackendUserLogged() && $this->getBackendUser()->workspace !== 0) { |
|
| 915 | - # $pageRepository->versioningWorkspaceId = $this->getBackendUser()->workspace; |
|
| 916 | - #} |
|
| 917 | - } else { |
|
| 918 | - $languageMode = ''; |
|
| 919 | - $workspaceUid = $this->getBackendUser()->workspace; |
|
| 920 | - #$pageRepository->versioningWorkspaceId = $workspaceUid; |
|
| 921 | - #if ($this->getBackendUser()->workspace !== 0) { |
|
| 922 | - # $pageRepository->versioningPreview = 1; |
|
| 923 | - #} |
|
| 924 | - } |
|
| 925 | - |
|
| 926 | - // If current row is a translation select its parent |
|
| 927 | - if (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) |
|
| 928 | - && isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']) |
|
| 929 | - ) { |
|
| 930 | - if (isset($row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']]) |
|
| 931 | - && $row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] > 0 |
|
| 932 | - ) { |
|
| 933 | - $queryBuilder = $this->getQueryBuilder(); |
|
| 934 | - $row = $queryBuilder |
|
| 935 | - ->select($tableName . '.*') |
|
| 936 | - ->from($tableName) |
|
| 937 | - ->andWhere( |
|
| 938 | - $tableName . '.uid=' . (int)$row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']], |
|
| 939 | - $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . ' = 0' |
|
| 940 | - ) |
|
| 941 | - ->execute() |
|
| 942 | - ->fetch(); |
|
| 943 | - } |
|
| 944 | - } |
|
| 945 | - |
|
| 946 | - // Retrieve the original uid; Used for Workspaces! |
|
| 947 | - if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend()) { |
|
| 948 | - $pageRepository->versionOL($tableName, $row, true, true); |
|
| 949 | - } else { |
|
| 950 | - \TYPO3\CMS\Backend\Utility\BackendUtility::workspaceOL($tableName, $row); |
|
| 951 | - } |
|
| 952 | - if (isset($row['_ORIG_uid'])) { |
|
| 953 | - $row['uid'] = $row['_ORIG_uid']; |
|
| 954 | - } |
|
| 955 | - |
|
| 956 | - // Special case for table "pages" |
|
| 957 | - if ($tableName == 'pages') { |
|
| 958 | - $row = $pageRepository->getPageOverlay($row, $querySettings->getLanguageUid()); |
|
| 959 | - } elseif (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) |
|
| 960 | - && $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== '' |
|
| 961 | - ) { |
|
| 962 | - if (in_array($row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']], array(-1, 0))) { |
|
| 963 | - $overlayMode = $languageMode === 'strict' ? 'hideNonTranslated' : ''; |
|
| 964 | - $row = $pageRepository->getRecordOverlay($tableName, $row, $querySettings->getLanguageUid(), $overlayMode); |
|
| 965 | - } |
|
| 966 | - } |
|
| 967 | - |
|
| 968 | - return $row; |
|
| 969 | - } |
|
| 970 | - |
|
| 971 | - /** |
|
| 972 | - * Return a resolved table name given a possible table name alias. |
|
| 973 | - * |
|
| 974 | - * @param string $tableNameOrAlias |
|
| 975 | - * @return string |
|
| 976 | - */ |
|
| 977 | - protected function resolveTableNameAlias($tableNameOrAlias) |
|
| 978 | - { |
|
| 979 | - $resolvedTableName = $tableNameOrAlias; |
|
| 980 | - if (!empty($this->tableNameAliases['aliases'][$tableNameOrAlias])) { |
|
| 981 | - $resolvedTableName = $this->tableNameAliases['aliases'][$tableNameOrAlias]; |
|
| 982 | - } |
|
| 983 | - return $resolvedTableName; |
|
| 984 | - } |
|
| 985 | - |
|
| 986 | - /** |
|
| 987 | - * Generate a unique table name alias for the given table name. |
|
| 988 | - * |
|
| 989 | - * @param string $tableName |
|
| 990 | - * @return string |
|
| 991 | - */ |
|
| 992 | - protected function generateAlias($tableName) |
|
| 993 | - { |
|
| 994 | - if (!isset($this->tableNameAliases['aliasIncrement'][$tableName])) { |
|
| 995 | - $this->tableNameAliases['aliasIncrement'][$tableName] = 0; |
|
| 996 | - } |
|
| 997 | - |
|
| 998 | - $numberOfAliases = $this->tableNameAliases['aliasIncrement'][$tableName]; |
|
| 999 | - $tableNameAlias = $tableName . $numberOfAliases; |
|
| 1000 | - |
|
| 1001 | - $this->tableNameAliases['aliasIncrement'][$tableName]++; |
|
| 1002 | - $this->tableNameAliases['aliases'][$tableNameAlias] = $tableName; |
|
| 1003 | - |
|
| 1004 | - return $tableNameAlias; |
|
| 1005 | - } |
|
| 1006 | - |
|
| 1007 | - /** |
|
| 1008 | - * Replace the table names by its table name alias within the given statement. |
|
| 1009 | - * |
|
| 1010 | - * @param string $tableName |
|
| 1011 | - * @param string $tableNameAlias |
|
| 1012 | - * @param string $statement |
|
| 1013 | - * @return string |
|
| 1014 | - */ |
|
| 1015 | - protected function replaceTableNameByAlias($tableName, $tableNameAlias, $statement) |
|
| 1016 | - { |
|
| 1017 | - if ($statement && $tableName !== $tableNameAlias) { |
|
| 1018 | - $statement = str_replace($tableName, $tableNameAlias, $statement); |
|
| 1019 | - } |
|
| 1020 | - return $statement; |
|
| 1021 | - } |
|
| 1022 | - |
|
| 1023 | - /** |
|
| 1024 | - * Returns an instance of the current Backend User. |
|
| 1025 | - * |
|
| 1026 | - * @return BackendUserAuthentication |
|
| 1027 | - */ |
|
| 1028 | - protected function getBackendUser() |
|
| 1029 | - { |
|
| 1030 | - return $GLOBALS['BE_USER']; |
|
| 1031 | - } |
|
| 1032 | - |
|
| 1033 | - /** |
|
| 1034 | - * Tell whether a Backend User is logged in. |
|
| 1035 | - * |
|
| 1036 | - * @return bool |
|
| 1037 | - */ |
|
| 1038 | - protected function isBackendUserLogged() |
|
| 1039 | - { |
|
| 1040 | - return is_object($GLOBALS['BE_USER']); |
|
| 1041 | - } |
|
| 1042 | - |
|
| 1043 | - /** |
|
| 1044 | - * @return PageRepository|object |
|
| 1045 | - */ |
|
| 1046 | - protected function getPageRepository() |
|
| 1047 | - { |
|
| 1048 | - if (!$this->pageRepository instanceof PageRepository) { |
|
| 1049 | - if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend() && is_object($GLOBALS['TSFE'])) { |
|
| 1050 | - $this->pageRepository = $GLOBALS['TSFE']->sys_page; |
|
| 1051 | - } else { |
|
| 1052 | - $this->pageRepository = GeneralUtility::makeInstance(PageRepository::class); |
|
| 1053 | - } |
|
| 1054 | - } |
|
| 1055 | - |
|
| 1056 | - return $this->pageRepository; |
|
| 1057 | - } |
|
| 1058 | - |
|
| 1059 | - /** |
|
| 1060 | - * @return FieldPathResolver|object |
|
| 1061 | - */ |
|
| 1062 | - protected function getFieldPathResolver() |
|
| 1063 | - { |
|
| 1064 | - return GeneralUtility::makeInstance(FieldPathResolver::class); |
|
| 1065 | - } |
|
| 1066 | - |
|
| 1067 | - /** |
|
| 1068 | - * @return object|Connection |
|
| 1069 | - */ |
|
| 1070 | - protected function getConnection(): Connection |
|
| 1071 | - { |
|
| 1072 | - /** @var ConnectionPool $connectionPool */ |
|
| 1073 | - return GeneralUtility::makeInstance(ConnectionPool::class) |
|
| 1074 | - ->getConnectionForTable($this->getTableName()); |
|
| 1075 | - } |
|
| 1076 | - |
|
| 1077 | - /** |
|
| 1078 | - * @return object|QueryBuilder |
|
| 1079 | - */ |
|
| 1080 | - protected function getQueryBuilder(): QueryBuilder |
|
| 1081 | - { |
|
| 1082 | - /** @var ConnectionPool $connectionPool */ |
|
| 1083 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
| 1084 | - return $connectionPool->getQueryBuilderForTable($this->getTableName()); |
|
| 1085 | - } |
|
| 1086 | - |
|
| 1087 | - /** |
|
| 1088 | - * @return string |
|
| 1089 | - */ |
|
| 1090 | - public function getTableName(): string |
|
| 1091 | - { |
|
| 1092 | - return $this->query->getSource()->getNodeTypeName(); // getSelectorName() |
|
| 1093 | - } |
|
| 54 | + public const OPERATOR_EQUAL_TO_NULL = 'operatorEqualToNull'; |
|
| 55 | + public const OPERATOR_NOT_EQUAL_TO_NULL = 'operatorNotEqualToNull'; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * The TYPO3 page repository. Used for language and workspace overlay |
|
| 59 | + * |
|
| 60 | + * @var PageRepository |
|
| 61 | + */ |
|
| 62 | + protected $pageRepository; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @var Query |
|
| 66 | + */ |
|
| 67 | + protected $query; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Store some info related to table name and its aliases. |
|
| 71 | + * |
|
| 72 | + * @var array |
|
| 73 | + */ |
|
| 74 | + protected $tableNameAliases = array( |
|
| 75 | + 'aliases' => [], |
|
| 76 | + 'aliasIncrement' => [], |
|
| 77 | + ); |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Use to store the current foreign table name alias. |
|
| 81 | + * |
|
| 82 | + * @var string |
|
| 83 | + */ |
|
| 84 | + protected $currentChildTableNameAlias = ''; |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @param Query $query |
|
| 88 | + */ |
|
| 89 | + public function __construct(Query $query) |
|
| 90 | + { |
|
| 91 | + $this->query = $query; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @param $parameters |
|
| 96 | + * @return array |
|
| 97 | + */ |
|
| 98 | + protected static function getTypes($parameters) |
|
| 99 | + { |
|
| 100 | + $types = []; |
|
| 101 | + foreach ($parameters as $parameter) { |
|
| 102 | + if (is_array($parameter)) { |
|
| 103 | + if (MathUtility::canBeInterpretedAsInteger($parameter[0])) { |
|
| 104 | + $types[] = \Doctrine\DBAL\Connection::PARAM_INT_ARRAY; |
|
| 105 | + } else { |
|
| 106 | + $types[] = \Doctrine\DBAL\Connection::PARAM_STR_ARRAY; |
|
| 107 | + } |
|
| 108 | + } else { |
|
| 109 | + if (MathUtility::canBeInterpretedAsInteger($parameter)) { |
|
| 110 | + $types[] = ParameterType::INTEGER; |
|
| 111 | + } else { |
|
| 112 | + $types[] = ParameterType::STRING; |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + return $types; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Returns the result of the query |
|
| 121 | + */ |
|
| 122 | + public function fetchResult() |
|
| 123 | + { |
|
| 124 | + $parameters = []; |
|
| 125 | + $statementParts = $this->parseQuery($parameters); |
|
| 126 | + $statementParts = $this->processStatementStructureForRecursiveMMRelation($statementParts); |
|
| 127 | + $sql = $this->buildQuery($statementParts); |
|
| 128 | + //print $sql; exit(); |
|
| 129 | + |
|
| 130 | + $rows = $this->getConnection() |
|
| 131 | + ->executeQuery($sql, $parameters, self::getTypes($parameters)) |
|
| 132 | + ->fetchAllAssociative(); |
|
| 133 | + |
|
| 134 | + return $this->getContentObjects($rows); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Returns the number of tuples matching the query. |
|
| 139 | + * |
|
| 140 | + * @return int The number of matching tuples |
|
| 141 | + */ |
|
| 142 | + public function countResult() |
|
| 143 | + { |
|
| 144 | + $parameters = []; |
|
| 145 | + $statementParts = $this->parseQuery($parameters); |
|
| 146 | + $statementParts = $this->processStatementStructureForRecursiveMMRelation($statementParts); |
|
| 147 | + $types = self::getTypes($parameters); |
|
| 148 | + |
|
| 149 | + // if limit is set, we need to count the rows "manually" as COUNT(*) ignores LIMIT constraints |
|
| 150 | + if (!empty($statementParts['limit'])) { |
|
| 151 | + $sql = $this->buildQuery($statementParts); |
|
| 152 | + |
|
| 153 | + $count = $this |
|
| 154 | + ->getConnection() |
|
| 155 | + ->executeQuery($sql, $parameters, $types) |
|
| 156 | + ->rowCount(); |
|
| 157 | + } else { |
|
| 158 | + $statementParts['fields'] = array('COUNT(*)'); |
|
| 159 | + // having orderings without grouping is not compatible with non-MySQL DBMS |
|
| 160 | + $statementParts['orderings'] = []; |
|
| 161 | + if (isset($statementParts['keywords']['distinct'])) { |
|
| 162 | + unset($statementParts['keywords']['distinct']); |
|
| 163 | + $distinctField = $this->query->getDistinct() ? $this->query->getDistinct() : 'uid'; |
|
| 164 | + $statementParts['fields'] = array('COUNT(DISTINCT ' . $statementParts['mainTable'] . '.' . $distinctField . ')'); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + $sql = $this->buildQuery($statementParts); |
|
| 168 | + $count = $this |
|
| 169 | + ->getConnection() |
|
| 170 | + ->executeQuery($sql, $parameters, $types) |
|
| 171 | + ->fetchColumn(0); |
|
| 172 | + } |
|
| 173 | + return (int)$count; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Parses the query and returns the SQL statement parts. |
|
| 178 | + * |
|
| 179 | + * @param array &$parameters |
|
| 180 | + * @return array |
|
| 181 | + */ |
|
| 182 | + public function parseQuery(array &$parameters) |
|
| 183 | + { |
|
| 184 | + $statementParts = []; |
|
| 185 | + $statementParts['keywords'] = []; |
|
| 186 | + $statementParts['tables'] = []; |
|
| 187 | + $statementParts['unions'] = []; |
|
| 188 | + $statementParts['fields'] = []; |
|
| 189 | + $statementParts['where'] = []; |
|
| 190 | + $statementParts['additionalWhereClause'] = []; |
|
| 191 | + $statementParts['orderings'] = []; |
|
| 192 | + $statementParts['limit'] = []; |
|
| 193 | + $query = $this->query; |
|
| 194 | + $source = $query->getSource(); |
|
| 195 | + $this->parseSource($source, $statementParts); |
|
| 196 | + $this->parseConstraint($query->getConstraint(), $source, $statementParts, $parameters); |
|
| 197 | + $this->parseOrderings($query->getOrderings(), $source, $statementParts); |
|
| 198 | + $this->parseLimitAndOffset($query->getLimit(), $query->getOffset(), $statementParts); |
|
| 199 | + $tableNames = array_unique(array_keys($statementParts['tables'] + $statementParts['unions'])); |
|
| 200 | + foreach ($tableNames as $tableNameOrAlias) { |
|
| 201 | + if (is_string($tableNameOrAlias) && strlen($tableNameOrAlias) > 0) { |
|
| 202 | + $this->addAdditionalWhereClause($query->getTypo3QuerySettings(), $tableNameOrAlias, $statementParts); |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + return $statementParts; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Fiddle with the statement structure to handle recursive MM relations. |
|
| 211 | + * For the recursive MM query to work, we must invert some values. |
|
| 212 | + * Let see if that is the best way of doing that... |
|
| 213 | + * |
|
| 214 | + * @param array $statementParts |
|
| 215 | + * @return array |
|
| 216 | + */ |
|
| 217 | + public function processStatementStructureForRecursiveMMRelation(array $statementParts) |
|
| 218 | + { |
|
| 219 | + if ($this->hasRecursiveMMRelation()) { |
|
| 220 | + $tableName = $this->query->getType(); |
|
| 221 | + |
|
| 222 | + // In order the MM query to work for a recursive MM query, we must invert some values. |
|
| 223 | + // tx_domain_model_foo0 (the alias) <--> tx_domain_model_foo (the origin table name) |
|
| 224 | + $values = []; |
|
| 225 | + foreach ($statementParts['fields'] as $key => $value) { |
|
| 226 | + $values[$key] = str_replace($tableName, $tableName . '0', $value); |
|
| 227 | + } |
|
| 228 | + $statementParts['fields'] = $values; |
|
| 229 | + |
|
| 230 | + // Same comment as above. |
|
| 231 | + $values = []; |
|
| 232 | + foreach ($statementParts['where'] as $key => $value) { |
|
| 233 | + $values[$key] = str_replace($tableName . '0', $tableName, $value); |
|
| 234 | + } |
|
| 235 | + $statementParts['where'] = $values; |
|
| 236 | + |
|
| 237 | + // We must be more restrictive by transforming the "left" union by "inner" |
|
| 238 | + $values = []; |
|
| 239 | + foreach ($statementParts['unions'] as $key => $value) { |
|
| 240 | + $values[$key] = str_replace('LEFT JOIN', 'INNER JOIN', $value); |
|
| 241 | + } |
|
| 242 | + $statementParts['unions'] = $values; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + return $statementParts; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * Tell whether there is a recursive MM relation. |
|
| 250 | + * |
|
| 251 | + * @return bool |
|
| 252 | + */ |
|
| 253 | + public function hasRecursiveMMRelation() |
|
| 254 | + { |
|
| 255 | + return isset($this->tableNameAliases['aliasIncrement'][$this->query->getType()]); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * Returns the statement, ready to be executed. |
|
| 260 | + * |
|
| 261 | + * @param array $statementParts The SQL statement parts |
|
| 262 | + * @return string The SQL statement |
|
| 263 | + */ |
|
| 264 | + public function buildQuery(array $statementParts) |
|
| 265 | + { |
|
| 266 | + // Add more statement to the UNION part. |
|
| 267 | + if (!empty($statementParts['unions'])) { |
|
| 268 | + foreach ($statementParts['unions'] as $tableName => $unionPart) { |
|
| 269 | + if (!empty($statementParts['additionalWhereClause'][$tableName])) { |
|
| 270 | + $statementParts['unions'][$tableName] .= ' AND ' . implode(' AND ', $statementParts['additionalWhereClause'][$tableName]); |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + $statement = 'SELECT ' . implode(' ', $statementParts['keywords']) . ' ' . implode(',', $statementParts['fields']) . ' FROM ' . implode(' ', $statementParts['tables']) . ' ' . implode(' ', $statementParts['unions']); |
|
| 276 | + if (!empty($statementParts['where'])) { |
|
| 277 | + $statement .= ' WHERE ' . implode('', $statementParts['where']); |
|
| 278 | + if (!empty($statementParts['additionalWhereClause'][$this->query->getType()])) { |
|
| 279 | + $statement .= ' AND ' . implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]); |
|
| 280 | + } |
|
| 281 | + } elseif (!empty($statementParts['additionalWhereClause'])) { |
|
| 282 | + $statement .= ' WHERE ' . implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]); |
|
| 283 | + } |
|
| 284 | + if (!empty($statementParts['orderings'])) { |
|
| 285 | + $statement .= ' ORDER BY ' . implode(', ', $statementParts['orderings']); |
|
| 286 | + } |
|
| 287 | + if (!empty($statementParts['limit'])) { |
|
| 288 | + $statement .= ' LIMIT ' . $statementParts['limit']; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + return $statement; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * Transforms a Query Source into SQL and parameter arrays |
|
| 296 | + * |
|
| 297 | + * @param SourceInterface $source The source |
|
| 298 | + * @param array &$sql |
|
| 299 | + * @return void |
|
| 300 | + */ |
|
| 301 | + protected function parseSource(SourceInterface $source, array &$sql) |
|
| 302 | + { |
|
| 303 | + $tableName = $this->getTableName(); |
|
| 304 | + $sql['fields'][$tableName] = $tableName . '.*'; |
|
| 305 | + if ($this->query->getDistinct()) { |
|
| 306 | + $sql['fields'][$tableName] = $tableName . '.' . $this->query->getDistinct(); |
|
| 307 | + $sql['keywords']['distinct'] = 'DISTINCT'; |
|
| 308 | + } |
|
| 309 | + $sql['tables'][$tableName] = $tableName; |
|
| 310 | + $sql['mainTable'] = $tableName; |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * Transforms a constraint into SQL and parameter arrays |
|
| 315 | + * |
|
| 316 | + * @param ConstraintInterface $constraint The constraint |
|
| 317 | + * @param SourceInterface $source The source |
|
| 318 | + * @param array &$statementParts The query parts |
|
| 319 | + * @param array &$parameters The parameters that will replace the markers |
|
| 320 | + * @return void |
|
| 321 | + */ |
|
| 322 | + protected function parseConstraint(ConstraintInterface $constraint = null, SourceInterface $source, array &$statementParts, array &$parameters) |
|
| 323 | + { |
|
| 324 | + if ($constraint instanceof AndInterface) { |
|
| 325 | + $statementParts['where'][] = '('; |
|
| 326 | + $this->parseConstraint($constraint->getConstraint1(), $source, $statementParts, $parameters); |
|
| 327 | + $statementParts['where'][] = ' AND '; |
|
| 328 | + $this->parseConstraint($constraint->getConstraint2(), $source, $statementParts, $parameters); |
|
| 329 | + $statementParts['where'][] = ')'; |
|
| 330 | + } elseif ($constraint instanceof OrInterface) { |
|
| 331 | + $statementParts['where'][] = '('; |
|
| 332 | + $this->parseConstraint($constraint->getConstraint1(), $source, $statementParts, $parameters); |
|
| 333 | + $statementParts['where'][] = ' OR '; |
|
| 334 | + $this->parseConstraint($constraint->getConstraint2(), $source, $statementParts, $parameters); |
|
| 335 | + $statementParts['where'][] = ')'; |
|
| 336 | + } elseif ($constraint instanceof NotInterface) { |
|
| 337 | + $statementParts['where'][] = 'NOT ('; |
|
| 338 | + $this->parseConstraint($constraint->getConstraint(), $source, $statementParts, $parameters); |
|
| 339 | + $statementParts['where'][] = ')'; |
|
| 340 | + } elseif ($constraint instanceof ComparisonInterface) { |
|
| 341 | + $this->parseComparison($constraint, $source, $statementParts, $parameters); |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + /** |
|
| 346 | + * Parse a Comparison into SQL and parameter arrays. |
|
| 347 | + * |
|
| 348 | + * @param ComparisonInterface $comparison The comparison to parse |
|
| 349 | + * @param SourceInterface $source The source |
|
| 350 | + * @param array &$statementParts SQL query parts to add to |
|
| 351 | + * @param array &$parameters Parameters to bind to the SQL |
|
| 352 | + * @return void |
|
| 353 | + * @throws Exception\RepositoryException |
|
| 354 | + */ |
|
| 355 | + protected function parseComparison(ComparisonInterface $comparison, SourceInterface $source, array &$statementParts, array &$parameters) |
|
| 356 | + { |
|
| 357 | + $operand1 = $comparison->getOperand1(); |
|
| 358 | + $operator = $comparison->getOperator(); |
|
| 359 | + $operand2 = $comparison->getOperand2(); |
|
| 360 | + if ($operator === QueryInterface::OPERATOR_IN) { |
|
| 361 | + $items = []; |
|
| 362 | + $hasValue = false; |
|
| 363 | + foreach ($operand2 as $value) { |
|
| 364 | + $value = $this->getPlainValue($value); |
|
| 365 | + if ($value !== null) { |
|
| 366 | + $items[] = $value; |
|
| 367 | + $hasValue = true; |
|
| 368 | + } |
|
| 369 | + } |
|
| 370 | + if ($hasValue === false) { |
|
| 371 | + $statementParts['where'][] = '1<>1'; |
|
| 372 | + } else { |
|
| 373 | + $this->parseDynamicOperand($operand1, $operator, $source, $statementParts, $parameters, null); |
|
| 374 | + $parameters[] = $items; |
|
| 375 | + } |
|
| 376 | + } elseif ($operator === QueryInterface::OPERATOR_CONTAINS) { |
|
| 377 | + if ($operand2 === null) { |
|
| 378 | + $statementParts['where'][] = '1<>1'; |
|
| 379 | + } else { |
|
| 380 | + throw new \Exception('Not implemented! Contact extension author.', 1412931227); |
|
| 381 | + # @todo re-implement me if necessary. |
|
| 382 | + #$tableName = $this->query->getType(); |
|
| 383 | + #$propertyName = $operand1->getPropertyName(); |
|
| 384 | + #while (strpos($propertyName, '.') !== false) { |
|
| 385 | + # $this->addUnionStatement($tableName, $propertyName, $statementParts); |
|
| 386 | + #} |
|
| 387 | + #$columnName = $propertyName; |
|
| 388 | + #$columnMap = $propertyName; |
|
| 389 | + #$typeOfRelation = $columnMap instanceof ColumnMap ? $columnMap->getTypeOfRelation() : null; |
|
| 390 | + #if ($typeOfRelation === ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) { |
|
| 391 | + # $relationTableName = $columnMap->getRelationTableName(); |
|
| 392 | + # $statementParts['where'][] = $tableName . '.uid IN (SELECT ' . $columnMap->getParentKeyFieldName() . ' FROM ' . $relationTableName . ' WHERE ' . $columnMap->getChildKeyFieldName() . '=?)'; |
|
| 393 | + # $parameters[] = intval($this->getPlainValue($operand2)); |
|
| 394 | + #} elseif ($typeOfRelation === ColumnMap::RELATION_HAS_MANY) { |
|
| 395 | + # $parentKeyFieldName = $columnMap->getParentKeyFieldName(); |
|
| 396 | + # if (isset($parentKeyFieldName)) { |
|
| 397 | + # $childTableName = $columnMap->getChildTableName(); |
|
| 398 | + # $statementParts['where'][] = $tableName . '.uid=(SELECT ' . $childTableName . '.' . $parentKeyFieldName . ' FROM ' . $childTableName . ' WHERE ' . $childTableName . '.uid=?)'; |
|
| 399 | + # $parameters[] = intval($this->getPlainValue($operand2)); |
|
| 400 | + # } else { |
|
| 401 | + # $statementParts['where'][] = 'FIND_IN_SET(?,' . $tableName . '.' . $columnName . ')'; |
|
| 402 | + # $parameters[] = intval($this->getPlainValue($operand2)); |
|
| 403 | + # } |
|
| 404 | + #} else { |
|
| 405 | + # throw new Exception\RepositoryException('Unsupported or non-existing property name "' . $propertyName . '" used in relation matching.', 1327065745); |
|
| 406 | + #} |
|
| 407 | + } |
|
| 408 | + } else { |
|
| 409 | + if ($operand2 === null) { |
|
| 410 | + if ($operator === QueryInterface::OPERATOR_EQUAL_TO) { |
|
| 411 | + $operator = self::OPERATOR_EQUAL_TO_NULL; |
|
| 412 | + } elseif ($operator === QueryInterface::OPERATOR_NOT_EQUAL_TO) { |
|
| 413 | + $operator = self::OPERATOR_NOT_EQUAL_TO_NULL; |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + $this->parseDynamicOperand($operand1, $operator, $source, $statementParts, $parameters); |
|
| 417 | + $parameters[] = $this->getPlainValue($operand2); |
|
| 418 | + } |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * Returns a plain value, i.e. objects are flattened if possible. |
|
| 423 | + * |
|
| 424 | + * @param mixed $input |
|
| 425 | + * @return mixed |
|
| 426 | + * @throws UnexpectedTypeException |
|
| 427 | + */ |
|
| 428 | + protected function getPlainValue($input) |
|
| 429 | + { |
|
| 430 | + if (is_array($input)) { |
|
| 431 | + throw new UnexpectedTypeException('An array could not be converted to a plain value.', 1274799932); |
|
| 432 | + } |
|
| 433 | + if ($input instanceof \DateTime) { |
|
| 434 | + return $input->format('U'); |
|
| 435 | + } elseif (is_object($input)) { |
|
| 436 | + if ($input instanceof LazyLoadingProxy) { |
|
| 437 | + $realInput = $input->_loadRealInstance(); |
|
| 438 | + } else { |
|
| 439 | + $realInput = $input; |
|
| 440 | + } |
|
| 441 | + if ($realInput instanceof DomainObjectInterface) { |
|
| 442 | + return $realInput->getUid(); |
|
| 443 | + } else { |
|
| 444 | + throw new UnexpectedTypeException('An object of class "' . get_class($realInput) . '" could not be converted to a plain value.', 1274799934); |
|
| 445 | + } |
|
| 446 | + } elseif (is_bool($input)) { |
|
| 447 | + return $input === true ? 1 : 0; |
|
| 448 | + } else { |
|
| 449 | + return $input; |
|
| 450 | + } |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + /** |
|
| 454 | + * Parse a DynamicOperand into SQL and parameter arrays. |
|
| 455 | + * |
|
| 456 | + * @param DynamicOperandInterface $operand |
|
| 457 | + * @param string $operator One of the JCR_OPERATOR_* constants |
|
| 458 | + * @param SourceInterface $source The source |
|
| 459 | + * @param array &$statementParts The query parts |
|
| 460 | + * @param array &$parameters The parameters that will replace the markers |
|
| 461 | + * @param string $valueFunction an optional SQL function to apply to the operand value |
|
| 462 | + * @return void |
|
| 463 | + */ |
|
| 464 | + protected function parseDynamicOperand(DynamicOperandInterface $operand, $operator, SourceInterface $source, array &$statementParts, array &$parameters, $valueFunction = null) |
|
| 465 | + { |
|
| 466 | + if ($operand instanceof LowerCaseInterface) { |
|
| 467 | + $this->parseDynamicOperand($operand->getOperand(), $operator, $source, $statementParts, $parameters, 'LOWER'); |
|
| 468 | + } elseif ($operand instanceof UpperCaseInterface) { |
|
| 469 | + $this->parseDynamicOperand($operand->getOperand(), $operator, $source, $statementParts, $parameters, 'UPPER'); |
|
| 470 | + } elseif ($operand instanceof PropertyValueInterface) { |
|
| 471 | + $propertyName = $operand->getPropertyName(); |
|
| 472 | + |
|
| 473 | + // Reset value. |
|
| 474 | + $this->currentChildTableNameAlias = ''; |
|
| 475 | + |
|
| 476 | + if ($source instanceof SelectorInterface) { |
|
| 477 | + $tableName = $this->query->getType(); |
|
| 478 | + while (strpos($propertyName, '.') !== false) { |
|
| 479 | + $this->addUnionStatement($tableName, $propertyName, $statementParts); |
|
| 480 | + } |
|
| 481 | + } elseif ($source instanceof JoinInterface) { |
|
| 482 | + $tableName = $source->getJoinCondition()->getSelector1Name(); |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + $columnName = $propertyName; |
|
| 486 | + $resolvedOperator = $this->resolveOperator($operator); |
|
| 487 | + $constraintSQL = ''; |
|
| 488 | + |
|
| 489 | + $marker = $operator === QueryInterface::OPERATOR_IN |
|
| 490 | + ? '(?)' |
|
| 491 | + : '?'; |
|
| 492 | + |
|
| 493 | + if ($valueFunction === null) { |
|
| 494 | + $constraintSQL .= (!empty($tableName) ? $tableName . '.' : '') . $columnName . ' ' . $resolvedOperator . ' ' . $marker; |
|
| 495 | + } else { |
|
| 496 | + $constraintSQL .= $valueFunction . '(' . (!empty($tableName) ? $tableName . '.' : '') . $columnName . ') ' . $resolvedOperator . ' ' . $marker; |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + if (isset($tableName) && !empty($this->currentChildTableNameAlias)) { |
|
| 500 | + $constraintSQL = $this->replaceTableNameByAlias($tableName, $this->currentChildTableNameAlias, $constraintSQL); |
|
| 501 | + } |
|
| 502 | + $statementParts['where'][] = $constraintSQL; |
|
| 503 | + } |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * @param string &$tableName |
|
| 508 | + * @param string &$propertyPath |
|
| 509 | + * @param array &$statementParts |
|
| 510 | + */ |
|
| 511 | + protected function addUnionStatement(&$tableName, &$propertyPath, array &$statementParts) |
|
| 512 | + { |
|
| 513 | + $table = Tca::table($tableName); |
|
| 514 | + |
|
| 515 | + $explodedPropertyPath = explode('.', $propertyPath, 2); |
|
| 516 | + $fieldName = $explodedPropertyPath[0]; |
|
| 517 | + |
|
| 518 | + // Field of type "group" are special because property path must contain the table name |
|
| 519 | + // to determine the relation type. Example for sys_category, property path will look like "items.sys_file" |
|
| 520 | + $parts = explode('.', $propertyPath, 3); |
|
| 521 | + if ($table->field($fieldName)->isGroup() && count($parts) > 2) { |
|
| 522 | + $explodedPropertyPath[0] = $parts[0] . '.' . $parts[1]; |
|
| 523 | + $explodedPropertyPath[1] = $parts[2]; |
|
| 524 | + $fieldName = $explodedPropertyPath[0]; |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + $parentKeyFieldName = $table->field($fieldName)->getForeignField(); |
|
| 528 | + $childTableName = $table->field($fieldName)->getForeignTable(); |
|
| 529 | + |
|
| 530 | + if ($childTableName === null) { |
|
| 531 | + throw new InvalidRelationConfigurationException('The relation information for property "' . $fieldName . '" of class "' . $tableName . '" is missing.', 1353170925); |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + if ($table->field($fieldName)->hasOne()) { // includes relation "one-to-one" and "many-to-one" |
|
| 535 | + // sometimes the opposite relation is not defined. We don't want to force this config for backward compatibility reasons. |
|
| 536 | + // $parentKeyFieldName === null does the trick somehow. Before condition was if (isset($parentKeyFieldName)) |
|
| 537 | + if ($table->field($fieldName)->hasRelationManyToOne() || $parentKeyFieldName === null) { |
|
| 538 | + $statementParts['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.' . $fieldName . '=' . $childTableName . '.uid'; |
|
| 539 | + } else { |
|
| 540 | + $statementParts['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.uid=' . $childTableName . '.' . $parentKeyFieldName; |
|
| 541 | + } |
|
| 542 | + } elseif ($table->field($fieldName)->hasRelationManyToMany()) { |
|
| 543 | + $relationTableName = $table->field($fieldName)->getManyToManyTable(); |
|
| 544 | + |
|
| 545 | + $parentKeyFieldName = $table->field($fieldName)->isOppositeRelation() ? 'uid_foreign' : 'uid_local'; |
|
| 546 | + $childKeyFieldName = !$table->field($fieldName)->isOppositeRelation() ? 'uid_foreign' : 'uid_local'; |
|
| 547 | + |
|
| 548 | + // MM table e.g sys_category_record_mm |
|
| 549 | + $relationTableNameAlias = $this->generateAlias($relationTableName); |
|
| 550 | + $join = sprintf( |
|
| 551 | + 'LEFT JOIN %s AS %s ON %s.uid=%s.%s', |
|
| 552 | + $relationTableName, |
|
| 553 | + $relationTableNameAlias, |
|
| 554 | + $tableName, |
|
| 555 | + $relationTableNameAlias, |
|
| 556 | + $parentKeyFieldName |
|
| 557 | + ); |
|
| 558 | + $statementParts['unions'][$relationTableNameAlias] = $join; |
|
| 559 | + |
|
| 560 | + // Foreign table e.g sys_category |
|
| 561 | + $childTableNameAlias = $this->generateAlias($childTableName); |
|
| 562 | + $this->currentChildTableNameAlias = $childTableNameAlias; |
|
| 563 | + $join = sprintf( |
|
| 564 | + 'LEFT JOIN %s AS %s ON %s.%s=%s.uid', |
|
| 565 | + $childTableName, |
|
| 566 | + $childTableNameAlias, |
|
| 567 | + $relationTableNameAlias, |
|
| 568 | + $childKeyFieldName, |
|
| 569 | + $childTableNameAlias |
|
| 570 | + ); |
|
| 571 | + $statementParts['unions'][$childTableNameAlias] = $join; |
|
| 572 | + |
|
| 573 | + // Find a possible table name for a MM condition. |
|
| 574 | + $tableNameCondition = $table->field($fieldName)->getAdditionalTableNameCondition(); |
|
| 575 | + if ($tableNameCondition) { |
|
| 576 | + // If we can find a source file name, we can then retrieve more MM conditions from the TCA such as a field name. |
|
| 577 | + $sourceFileName = $this->query->getSourceFieldName(); |
|
| 578 | + if (empty($sourceFileName)) { |
|
| 579 | + $additionalMMConditions = array( |
|
| 580 | + 'tablenames' => $tableNameCondition, |
|
| 581 | + ); |
|
| 582 | + } else { |
|
| 583 | + $additionalMMConditions = Tca::table($tableNameCondition)->field($sourceFileName)->getAdditionalMMCondition(); |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + foreach ($additionalMMConditions as $additionalFieldName => $additionalMMCondition) { |
|
| 587 | + $additionalJoin = sprintf(' AND %s.%s = "%s"', $relationTableNameAlias, $additionalFieldName, $additionalMMCondition); |
|
| 588 | + $statementParts['unions'][$relationTableNameAlias] .= $additionalJoin; |
|
| 589 | + |
|
| 590 | + $additionalJoin = sprintf(' AND %s.%s = "%s"', $relationTableNameAlias, $additionalFieldName, $additionalMMCondition); |
|
| 591 | + $statementParts['unions'][$childTableNameAlias] .= $additionalJoin; |
|
| 592 | + } |
|
| 593 | + } |
|
| 594 | + } elseif ($table->field($fieldName)->hasMany()) { // includes relations "many-to-one" and "csv" relations |
|
| 595 | + $childTableNameAlias = $this->generateAlias($childTableName); |
|
| 596 | + $this->currentChildTableNameAlias = $childTableNameAlias; |
|
| 597 | + |
|
| 598 | + if (isset($parentKeyFieldName)) { |
|
| 599 | + $join = sprintf( |
|
| 600 | + 'LEFT JOIN %s AS %s ON %s.uid=%s.%s', |
|
| 601 | + $childTableName, |
|
| 602 | + $childTableNameAlias, |
|
| 603 | + $tableName, |
|
| 604 | + $childTableNameAlias, |
|
| 605 | + $parentKeyFieldName |
|
| 606 | + ); |
|
| 607 | + $statementParts['unions'][$childTableNameAlias] = $join; |
|
| 608 | + } else { |
|
| 609 | + $join = sprintf( |
|
| 610 | + 'LEFT JOIN %s AS %s ON (FIND_IN_SET(%s.uid, %s.%s))', |
|
| 611 | + $childTableName, |
|
| 612 | + $childTableNameAlias, |
|
| 613 | + $childTableNameAlias, |
|
| 614 | + $tableName, |
|
| 615 | + $fieldName |
|
| 616 | + ); |
|
| 617 | + $statementParts['unions'][$childTableNameAlias] = $join; |
|
| 618 | + } |
|
| 619 | + } else { |
|
| 620 | + throw new Exception('Could not determine type of relation.', 1252502725); |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + $statementParts['keywords']['distinct'] = 'DISTINCT'; |
|
| 624 | + $propertyPath = $explodedPropertyPath[1]; |
|
| 625 | + $tableName = $childTableName; |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + /** |
|
| 629 | + * Returns the SQL operator for the given JCR operator type. |
|
| 630 | + * |
|
| 631 | + * @param string $operator One of the JCR_OPERATOR_* constants |
|
| 632 | + * @return string an SQL operator |
|
| 633 | + * @throws Exception |
|
| 634 | + */ |
|
| 635 | + protected function resolveOperator($operator) |
|
| 636 | + { |
|
| 637 | + switch ($operator) { |
|
| 638 | + case self::OPERATOR_EQUAL_TO_NULL: |
|
| 639 | + $operator = 'IS'; |
|
| 640 | + break; |
|
| 641 | + case self::OPERATOR_NOT_EQUAL_TO_NULL: |
|
| 642 | + $operator = 'IS NOT'; |
|
| 643 | + break; |
|
| 644 | + case QueryInterface::OPERATOR_IN: |
|
| 645 | + $operator = 'IN'; |
|
| 646 | + break; |
|
| 647 | + case QueryInterface::OPERATOR_EQUAL_TO: |
|
| 648 | + $operator = '='; |
|
| 649 | + break; |
|
| 650 | + case QueryInterface::OPERATOR_NOT_EQUAL_TO: |
|
| 651 | + $operator = '!='; |
|
| 652 | + break; |
|
| 653 | + case QueryInterface::OPERATOR_LESS_THAN: |
|
| 654 | + $operator = '<'; |
|
| 655 | + break; |
|
| 656 | + case QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO: |
|
| 657 | + $operator = '<='; |
|
| 658 | + break; |
|
| 659 | + case QueryInterface::OPERATOR_GREATER_THAN: |
|
| 660 | + $operator = '>'; |
|
| 661 | + break; |
|
| 662 | + case QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO: |
|
| 663 | + $operator = '>='; |
|
| 664 | + break; |
|
| 665 | + case QueryInterface::OPERATOR_LIKE: |
|
| 666 | + $operator = 'LIKE'; |
|
| 667 | + break; |
|
| 668 | + default: |
|
| 669 | + throw new Exception('Unsupported operator encountered.', 1242816073); |
|
| 670 | + } |
|
| 671 | + return $operator; |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + /** |
|
| 675 | + * Adds additional WHERE statements according to the query settings. |
|
| 676 | + * |
|
| 677 | + * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings |
|
| 678 | + * @param string $tableNameOrAlias The table name to add the additional where clause for |
|
| 679 | + * @param array &$statementParts |
|
| 680 | + * @return void |
|
| 681 | + */ |
|
| 682 | + protected function addAdditionalWhereClause(QuerySettingsInterface $querySettings, $tableNameOrAlias, &$statementParts) |
|
| 683 | + { |
|
| 684 | + $this->addVisibilityConstraintStatement($querySettings, $tableNameOrAlias, $statementParts); |
|
| 685 | + if ($querySettings->getRespectSysLanguage()) { |
|
| 686 | + $this->addSysLanguageStatement($tableNameOrAlias, $statementParts, $querySettings); |
|
| 687 | + } |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + /** |
|
| 691 | + * Adds enableFields and deletedClause to the query if necessary |
|
| 692 | + * |
|
| 693 | + * @param QuerySettingsInterface $querySettings |
|
| 694 | + * @param string $tableNameOrAlias The database table name |
|
| 695 | + * @param array &$statementParts The query parts |
|
| 696 | + * @return void |
|
| 697 | + */ |
|
| 698 | + protected function addVisibilityConstraintStatement(QuerySettingsInterface $querySettings, $tableNameOrAlias, array &$statementParts) |
|
| 699 | + { |
|
| 700 | + $statement = ''; |
|
| 701 | + $tableName = $this->resolveTableNameAlias($tableNameOrAlias); |
|
| 702 | + if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) { |
|
| 703 | + $ignoreEnableFields = $querySettings->getIgnoreEnableFields(); |
|
| 704 | + $enableFieldsToBeIgnored = $querySettings->getEnableFieldsToBeIgnored(); |
|
| 705 | + $includeDeleted = $querySettings->getIncludeDeleted(); |
|
| 706 | + if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend()) { |
|
| 707 | + $statement .= $this->getFrontendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $enableFieldsToBeIgnored, $includeDeleted); |
|
| 708 | + } else { |
|
| 709 | + // 'BE' case |
|
| 710 | + $statement .= $this->getBackendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $includeDeleted); |
|
| 711 | + } |
|
| 712 | + |
|
| 713 | + // Remove the prefixing "AND" if any. |
|
| 714 | + if (!empty($statement)) { |
|
| 715 | + $statement = strtolower(substr($statement, 1, 3)) === 'and' ? substr($statement, 5) : $statement; |
|
| 716 | + $statementParts['additionalWhereClause'][$tableNameOrAlias][] = $statement; |
|
| 717 | + } |
|
| 718 | + } |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + /** |
|
| 722 | + * Returns constraint statement for frontend context |
|
| 723 | + * |
|
| 724 | + * @param string $tableNameOrAlias |
|
| 725 | + * @param boolean $ignoreEnableFields A flag indicating whether the enable fields should be ignored |
|
| 726 | + * @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. |
|
| 727 | + * @param boolean $includeDeleted A flag indicating whether deleted records should be included |
|
| 728 | + * @return string |
|
| 729 | + * @throws Exception\InconsistentQuerySettingsException |
|
| 730 | + */ |
|
| 731 | + protected function getFrontendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $enableFieldsToBeIgnored, $includeDeleted) |
|
| 732 | + { |
|
| 733 | + $statement = ''; |
|
| 734 | + $tableName = $this->resolveTableNameAlias($tableNameOrAlias); |
|
| 735 | + if ($ignoreEnableFields && !$includeDeleted) { |
|
| 736 | + if (count($enableFieldsToBeIgnored)) { |
|
| 737 | + // array_combine() is necessary because of the way \TYPO3\CMS\Frontend\Page\PageRepository::enableFields() is implemented |
|
| 738 | + $statement .= $this->getPageRepository()->enableFields($tableName, -1, array_combine($enableFieldsToBeIgnored, $enableFieldsToBeIgnored)); |
|
| 739 | + } else { |
|
| 740 | + $statement .= $this->getPageRepository()->deleteClause($tableName); |
|
| 741 | + } |
|
| 742 | + } elseif (!$ignoreEnableFields && !$includeDeleted) { |
|
| 743 | + $statement .= $this->getPageRepository()->enableFields($tableName); |
|
| 744 | + } elseif (!$ignoreEnableFields && $includeDeleted) { |
|
| 745 | + throw new InconsistentQuerySettingsException('Query setting "ignoreEnableFields=false" can not be used together with "includeDeleted=true" in frontend context.', 1327678173); |
|
| 746 | + } |
|
| 747 | + return $this->replaceTableNameByAlias($tableName, $tableNameOrAlias, $statement); |
|
| 748 | + } |
|
| 749 | + |
|
| 750 | + /** |
|
| 751 | + * Returns constraint statement for backend context |
|
| 752 | + * |
|
| 753 | + * @param string $tableNameOrAlias |
|
| 754 | + * @param boolean $ignoreEnableFields A flag indicating whether the enable fields should be ignored |
|
| 755 | + * @param boolean $includeDeleted A flag indicating whether deleted records should be included |
|
| 756 | + * @return string |
|
| 757 | + */ |
|
| 758 | + protected function getBackendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $includeDeleted) |
|
| 759 | + { |
|
| 760 | + $tableName = $this->resolveTableNameAlias($tableNameOrAlias); |
|
| 761 | + $statement = ''; |
|
| 762 | + if (!$ignoreEnableFields) { |
|
| 763 | + $statement .= BackendUtility::BEenableFields($tableName); |
|
| 764 | + } |
|
| 765 | + |
|
| 766 | + // If the table is found to have "workspace" support, add the corresponding fields in the statement. |
|
| 767 | + if (Tca::table($tableName)->hasWorkspaceSupport()) { |
|
| 768 | + if ($this->getBackendUser()->workspace === 0) { |
|
| 769 | + $statement .= ' AND ' . $tableName . '.t3ver_state<=' . new VersionState(VersionState::DEFAULT_STATE); |
|
| 770 | + } else { |
|
| 771 | + // Show only records of live and of the current workspace |
|
| 772 | + // In case we are in a Versioning preview |
|
| 773 | + $statement .= ' AND (' . |
|
| 774 | + $tableName . '.t3ver_wsid=0 OR ' . |
|
| 775 | + $tableName . '.t3ver_wsid=' . (int)$this->getBackendUser()->workspace . |
|
| 776 | + ')'; |
|
| 777 | + } |
|
| 778 | + |
|
| 779 | + // Check if this segment make sense here or whether it should be in the "if" part when we have workspace = 0 |
|
| 780 | + $statement .= ' AND ' . $tableName . '.pid<>-1'; |
|
| 781 | + } |
|
| 782 | + |
|
| 783 | + if (!$includeDeleted) { |
|
| 784 | + $statement .= BackendUtility::deleteClause($tableName); |
|
| 785 | + } |
|
| 786 | + |
|
| 787 | + return $this->replaceTableNameByAlias($tableName, $tableNameOrAlias, $statement); |
|
| 788 | + } |
|
| 789 | + |
|
| 790 | + /** |
|
| 791 | + * Builds the language field statement |
|
| 792 | + * |
|
| 793 | + * @param string $tableNameOrAlias The database table name |
|
| 794 | + * @param array &$statementParts The query parts |
|
| 795 | + * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings |
|
| 796 | + * @return void |
|
| 797 | + * @throws Exception |
|
| 798 | + */ |
|
| 799 | + protected function addSysLanguageStatement($tableNameOrAlias, array &$statementParts, $querySettings) |
|
| 800 | + { |
|
| 801 | + $tableName = $this->resolveTableNameAlias($tableNameOrAlias); |
|
| 802 | + if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) { |
|
| 803 | + if (!empty($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])) { |
|
| 804 | + // Select all entries for the current language |
|
| 805 | + $additionalWhereClause = $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . ' IN (' . intval($querySettings->getLanguageUid()) . ',-1)'; |
|
| 806 | + // If any language is set -> get those entries which are not translated yet |
|
| 807 | + // They will be removed by t3lib_page::getRecordOverlay if not matching overlay mode |
|
| 808 | + if (isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']) |
|
| 809 | + && $querySettings->getLanguageUid() > 0 |
|
| 810 | + ) { |
|
| 811 | + $additionalWhereClause .= ' OR (' . $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=0' . |
|
| 812 | + ' AND ' . $tableNameOrAlias . '.uid NOT IN (SELECT ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] . |
|
| 813 | + ' FROM ' . $tableName . |
|
| 814 | + ' WHERE ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] . '>0' . |
|
| 815 | + ' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '>0'; |
|
| 816 | + |
|
| 817 | + // Add delete clause to ensure all entries are loaded |
|
| 818 | + if (isset($GLOBALS['TCA'][$tableName]['ctrl']['delete'])) { |
|
| 819 | + $additionalWhereClause .= ' AND ' . $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['delete'] . '=0'; |
|
| 820 | + } |
|
| 821 | + $additionalWhereClause .= '))'; |
|
| 822 | + } |
|
| 823 | + $statementParts['additionalWhereClause'][$tableNameOrAlias][] = '(' . $additionalWhereClause . ')'; |
|
| 824 | + } |
|
| 825 | + } |
|
| 826 | + } |
|
| 827 | + |
|
| 828 | + /** |
|
| 829 | + * Transforms orderings into SQL. |
|
| 830 | + * |
|
| 831 | + * @param array $orderings An array of orderings (Tx_Extbase_Persistence_QOM_Ordering) |
|
| 832 | + * @param SourceInterface $source The source |
|
| 833 | + * @param array &$statementParts The query parts |
|
| 834 | + * @return void |
|
| 835 | + * @throws Exception\UnsupportedOrderException |
|
| 836 | + */ |
|
| 837 | + protected function parseOrderings(array $orderings, SourceInterface $source, array &$statementParts) |
|
| 838 | + { |
|
| 839 | + foreach ($orderings as $fieldNameAndPath => $order) { |
|
| 840 | + switch ($order) { |
|
| 841 | + case QueryInterface::ORDER_ASCENDING: |
|
| 842 | + $order = 'ASC'; |
|
| 843 | + break; |
|
| 844 | + case QueryInterface::ORDER_DESCENDING: |
|
| 845 | + $order = 'DESC'; |
|
| 846 | + break; |
|
| 847 | + default: |
|
| 848 | + throw new UnsupportedOrderException('Unsupported order encountered.', 1456845126); |
|
| 849 | + } |
|
| 850 | + |
|
| 851 | + $tableName = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->query->getType()); |
|
| 852 | + $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $tableName); |
|
| 853 | + $statementParts['orderings'][] = sprintf('%s.%s %s', $tableName, $fieldName, $order); |
|
| 854 | + } |
|
| 855 | + } |
|
| 856 | + |
|
| 857 | + /** |
|
| 858 | + * Transforms limit and offset into SQL |
|
| 859 | + * |
|
| 860 | + * @param int $limit |
|
| 861 | + * @param int $offset |
|
| 862 | + * @param array &$statementParts |
|
| 863 | + * @return void |
|
| 864 | + */ |
|
| 865 | + protected function parseLimitAndOffset($limit, $offset, array &$statementParts) |
|
| 866 | + { |
|
| 867 | + if ($limit !== null && $offset !== null) { |
|
| 868 | + $statementParts['limit'] = intval($offset) . ', ' . intval($limit); |
|
| 869 | + } elseif ($limit !== null) { |
|
| 870 | + $statementParts['limit'] = intval($limit); |
|
| 871 | + } |
|
| 872 | + } |
|
| 873 | + |
|
| 874 | + /** |
|
| 875 | + * @param array $rows |
|
| 876 | + * @return array |
|
| 877 | + */ |
|
| 878 | + protected function getContentObjects(array $rows): array |
|
| 879 | + { |
|
| 880 | + $contentObjects = []; |
|
| 881 | + foreach ($rows as $row) { |
|
| 882 | + // Get language uid from querySettings. |
|
| 883 | + // Ensure the backend handling is not broken (fallback to Get parameter 'L' if needed) |
|
| 884 | + $overlaidRow = $this->doLanguageAndWorkspaceOverlay( |
|
| 885 | + $row, |
|
| 886 | + $this->query->getTypo3QuerySettings() |
|
| 887 | + ); |
|
| 888 | + |
|
| 889 | + $contentObjects[] = GeneralUtility::makeInstance( |
|
| 890 | + Content::class, |
|
| 891 | + $this->query->getType(), |
|
| 892 | + $overlaidRow |
|
| 893 | + ); |
|
| 894 | + } |
|
| 895 | + |
|
| 896 | + return $contentObjects; |
|
| 897 | + } |
|
| 898 | + |
|
| 899 | + /** |
|
| 900 | + * Performs workspace and language overlay on the given row array. The language and workspace id is automatically |
|
| 901 | + * detected (depending on FE or BE context). You can also explicitly set the language/workspace id. |
|
| 902 | + * |
|
| 903 | + * @param array $row |
|
| 904 | + * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings |
|
| 905 | + * @return array |
|
| 906 | + */ |
|
| 907 | + protected function doLanguageAndWorkspaceOverlay(array $row, $querySettings) |
|
| 908 | + { |
|
| 909 | + $tableName = $this->getTableName(); |
|
| 910 | + |
|
| 911 | + $pageRepository = $this->getPageRepository(); |
|
| 912 | + if (is_object($GLOBALS['TSFE'])) { |
|
| 913 | + $languageMode = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('language', 'legacyLanguageMode'); |
|
| 914 | + #if ($this->isBackendUserLogged() && $this->getBackendUser()->workspace !== 0) { |
|
| 915 | + # $pageRepository->versioningWorkspaceId = $this->getBackendUser()->workspace; |
|
| 916 | + #} |
|
| 917 | + } else { |
|
| 918 | + $languageMode = ''; |
|
| 919 | + $workspaceUid = $this->getBackendUser()->workspace; |
|
| 920 | + #$pageRepository->versioningWorkspaceId = $workspaceUid; |
|
| 921 | + #if ($this->getBackendUser()->workspace !== 0) { |
|
| 922 | + # $pageRepository->versioningPreview = 1; |
|
| 923 | + #} |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + // If current row is a translation select its parent |
|
| 927 | + if (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) |
|
| 928 | + && isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']) |
|
| 929 | + ) { |
|
| 930 | + if (isset($row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']]) |
|
| 931 | + && $row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] > 0 |
|
| 932 | + ) { |
|
| 933 | + $queryBuilder = $this->getQueryBuilder(); |
|
| 934 | + $row = $queryBuilder |
|
| 935 | + ->select($tableName . '.*') |
|
| 936 | + ->from($tableName) |
|
| 937 | + ->andWhere( |
|
| 938 | + $tableName . '.uid=' . (int)$row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']], |
|
| 939 | + $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . ' = 0' |
|
| 940 | + ) |
|
| 941 | + ->execute() |
|
| 942 | + ->fetch(); |
|
| 943 | + } |
|
| 944 | + } |
|
| 945 | + |
|
| 946 | + // Retrieve the original uid; Used for Workspaces! |
|
| 947 | + if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend()) { |
|
| 948 | + $pageRepository->versionOL($tableName, $row, true, true); |
|
| 949 | + } else { |
|
| 950 | + \TYPO3\CMS\Backend\Utility\BackendUtility::workspaceOL($tableName, $row); |
|
| 951 | + } |
|
| 952 | + if (isset($row['_ORIG_uid'])) { |
|
| 953 | + $row['uid'] = $row['_ORIG_uid']; |
|
| 954 | + } |
|
| 955 | + |
|
| 956 | + // Special case for table "pages" |
|
| 957 | + if ($tableName == 'pages') { |
|
| 958 | + $row = $pageRepository->getPageOverlay($row, $querySettings->getLanguageUid()); |
|
| 959 | + } elseif (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) |
|
| 960 | + && $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== '' |
|
| 961 | + ) { |
|
| 962 | + if (in_array($row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']], array(-1, 0))) { |
|
| 963 | + $overlayMode = $languageMode === 'strict' ? 'hideNonTranslated' : ''; |
|
| 964 | + $row = $pageRepository->getRecordOverlay($tableName, $row, $querySettings->getLanguageUid(), $overlayMode); |
|
| 965 | + } |
|
| 966 | + } |
|
| 967 | + |
|
| 968 | + return $row; |
|
| 969 | + } |
|
| 970 | + |
|
| 971 | + /** |
|
| 972 | + * Return a resolved table name given a possible table name alias. |
|
| 973 | + * |
|
| 974 | + * @param string $tableNameOrAlias |
|
| 975 | + * @return string |
|
| 976 | + */ |
|
| 977 | + protected function resolveTableNameAlias($tableNameOrAlias) |
|
| 978 | + { |
|
| 979 | + $resolvedTableName = $tableNameOrAlias; |
|
| 980 | + if (!empty($this->tableNameAliases['aliases'][$tableNameOrAlias])) { |
|
| 981 | + $resolvedTableName = $this->tableNameAliases['aliases'][$tableNameOrAlias]; |
|
| 982 | + } |
|
| 983 | + return $resolvedTableName; |
|
| 984 | + } |
|
| 985 | + |
|
| 986 | + /** |
|
| 987 | + * Generate a unique table name alias for the given table name. |
|
| 988 | + * |
|
| 989 | + * @param string $tableName |
|
| 990 | + * @return string |
|
| 991 | + */ |
|
| 992 | + protected function generateAlias($tableName) |
|
| 993 | + { |
|
| 994 | + if (!isset($this->tableNameAliases['aliasIncrement'][$tableName])) { |
|
| 995 | + $this->tableNameAliases['aliasIncrement'][$tableName] = 0; |
|
| 996 | + } |
|
| 997 | + |
|
| 998 | + $numberOfAliases = $this->tableNameAliases['aliasIncrement'][$tableName]; |
|
| 999 | + $tableNameAlias = $tableName . $numberOfAliases; |
|
| 1000 | + |
|
| 1001 | + $this->tableNameAliases['aliasIncrement'][$tableName]++; |
|
| 1002 | + $this->tableNameAliases['aliases'][$tableNameAlias] = $tableName; |
|
| 1003 | + |
|
| 1004 | + return $tableNameAlias; |
|
| 1005 | + } |
|
| 1006 | + |
|
| 1007 | + /** |
|
| 1008 | + * Replace the table names by its table name alias within the given statement. |
|
| 1009 | + * |
|
| 1010 | + * @param string $tableName |
|
| 1011 | + * @param string $tableNameAlias |
|
| 1012 | + * @param string $statement |
|
| 1013 | + * @return string |
|
| 1014 | + */ |
|
| 1015 | + protected function replaceTableNameByAlias($tableName, $tableNameAlias, $statement) |
|
| 1016 | + { |
|
| 1017 | + if ($statement && $tableName !== $tableNameAlias) { |
|
| 1018 | + $statement = str_replace($tableName, $tableNameAlias, $statement); |
|
| 1019 | + } |
|
| 1020 | + return $statement; |
|
| 1021 | + } |
|
| 1022 | + |
|
| 1023 | + /** |
|
| 1024 | + * Returns an instance of the current Backend User. |
|
| 1025 | + * |
|
| 1026 | + * @return BackendUserAuthentication |
|
| 1027 | + */ |
|
| 1028 | + protected function getBackendUser() |
|
| 1029 | + { |
|
| 1030 | + return $GLOBALS['BE_USER']; |
|
| 1031 | + } |
|
| 1032 | + |
|
| 1033 | + /** |
|
| 1034 | + * Tell whether a Backend User is logged in. |
|
| 1035 | + * |
|
| 1036 | + * @return bool |
|
| 1037 | + */ |
|
| 1038 | + protected function isBackendUserLogged() |
|
| 1039 | + { |
|
| 1040 | + return is_object($GLOBALS['BE_USER']); |
|
| 1041 | + } |
|
| 1042 | + |
|
| 1043 | + /** |
|
| 1044 | + * @return PageRepository|object |
|
| 1045 | + */ |
|
| 1046 | + protected function getPageRepository() |
|
| 1047 | + { |
|
| 1048 | + if (!$this->pageRepository instanceof PageRepository) { |
|
| 1049 | + if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend() && is_object($GLOBALS['TSFE'])) { |
|
| 1050 | + $this->pageRepository = $GLOBALS['TSFE']->sys_page; |
|
| 1051 | + } else { |
|
| 1052 | + $this->pageRepository = GeneralUtility::makeInstance(PageRepository::class); |
|
| 1053 | + } |
|
| 1054 | + } |
|
| 1055 | + |
|
| 1056 | + return $this->pageRepository; |
|
| 1057 | + } |
|
| 1058 | + |
|
| 1059 | + /** |
|
| 1060 | + * @return FieldPathResolver|object |
|
| 1061 | + */ |
|
| 1062 | + protected function getFieldPathResolver() |
|
| 1063 | + { |
|
| 1064 | + return GeneralUtility::makeInstance(FieldPathResolver::class); |
|
| 1065 | + } |
|
| 1066 | + |
|
| 1067 | + /** |
|
| 1068 | + * @return object|Connection |
|
| 1069 | + */ |
|
| 1070 | + protected function getConnection(): Connection |
|
| 1071 | + { |
|
| 1072 | + /** @var ConnectionPool $connectionPool */ |
|
| 1073 | + return GeneralUtility::makeInstance(ConnectionPool::class) |
|
| 1074 | + ->getConnectionForTable($this->getTableName()); |
|
| 1075 | + } |
|
| 1076 | + |
|
| 1077 | + /** |
|
| 1078 | + * @return object|QueryBuilder |
|
| 1079 | + */ |
|
| 1080 | + protected function getQueryBuilder(): QueryBuilder |
|
| 1081 | + { |
|
| 1082 | + /** @var ConnectionPool $connectionPool */ |
|
| 1083 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
| 1084 | + return $connectionPool->getQueryBuilderForTable($this->getTableName()); |
|
| 1085 | + } |
|
| 1086 | + |
|
| 1087 | + /** |
|
| 1088 | + * @return string |
|
| 1089 | + */ |
|
| 1090 | + public function getTableName(): string |
|
| 1091 | + { |
|
| 1092 | + return $this->query->getSource()->getNodeTypeName(); // getSelectorName() |
|
| 1093 | + } |
|
| 1094 | 1094 | } |
@@ -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 | } |
@@ -41,626 +41,626 @@ |
||
| 41 | 41 | */ |
| 42 | 42 | class Query implements QueryInterface |
| 43 | 43 | { |
| 44 | - /** |
|
| 45 | - * An inner join. |
|
| 46 | - */ |
|
| 47 | - public const JCR_JOIN_TYPE_INNER = '{http://www.jcp.org/jcr/1.0}joinTypeInner'; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * A left-outer join. |
|
| 51 | - */ |
|
| 52 | - public const JCR_JOIN_TYPE_LEFT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeLeftOuter'; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * A right-outer join. |
|
| 56 | - */ |
|
| 57 | - public const JCR_JOIN_TYPE_RIGHT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeRightOuter'; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Charset of strings in QOM |
|
| 61 | - */ |
|
| 62 | - public const CHARSET = 'utf-8'; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @var string |
|
| 66 | - */ |
|
| 67 | - protected $sourceFieldName; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @var string |
|
| 71 | - */ |
|
| 72 | - protected $type; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @var PersistenceManagerInterface |
|
| 76 | - */ |
|
| 77 | - protected $persistenceManager; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @var QueryObjectModelFactory |
|
| 81 | - */ |
|
| 82 | - protected $qomFactory; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @var SourceInterface |
|
| 86 | - */ |
|
| 87 | - protected $source; |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @var ConstraintInterface |
|
| 91 | - */ |
|
| 92 | - protected $constraint; |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @var Statement |
|
| 96 | - */ |
|
| 97 | - protected $statement; |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @var array |
|
| 101 | - */ |
|
| 102 | - protected $orderings = []; |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * @var int |
|
| 106 | - */ |
|
| 107 | - protected $limit; |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @var int |
|
| 111 | - */ |
|
| 112 | - protected $offset; |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Apply DISTINCT upon property. |
|
| 116 | - * |
|
| 117 | - * @var string |
|
| 118 | - */ |
|
| 119 | - protected $distinct; |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * The query settings. |
|
| 123 | - * |
|
| 124 | - * @var Typo3QuerySettings |
|
| 125 | - */ |
|
| 126 | - public Typo3QuerySettings $typo3QuerySettings; |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Constructs a query object working on the given class name |
|
| 130 | - * |
|
| 131 | - * @param string $type |
|
| 132 | - */ |
|
| 133 | - public function __construct($type) |
|
| 134 | - { |
|
| 135 | - $this->type = $type; |
|
| 136 | - $this->persistenceManager = GeneralUtility::makeInstance(PersistenceManagerInterface::class); |
|
| 137 | - $this->qomFactory = GeneralUtility::makeInstance(QueryObjectModelFactory::class); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - public function injectTypo3QuerySettings(Typo3QuerySettings $querySettings): void |
|
| 141 | - { |
|
| 142 | - $this->typo3QuerySettings = $querySettings; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Sets the Query Settings. These Query settings must match the settings expected by |
|
| 147 | - * the specific Storage Backend. |
|
| 148 | - * |
|
| 149 | - * @param QuerySettingsInterface $typo3QuerySettings The Query Settings |
|
| 150 | - * @return void |
|
| 151 | - */ |
|
| 152 | - public function setTypo3QuerySettings(QuerySettingsInterface $typo3QuerySettings) |
|
| 153 | - { |
|
| 154 | - $this->typo3QuerySettings = $typo3QuerySettings; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Returns the Query Settings. |
|
| 159 | - * |
|
| 160 | - * @throws \Exception |
|
| 161 | - * @return Typo3QuerySettings $querySettings The Query Settings |
|
| 162 | - * @api This method is not part of FLOW3 API |
|
| 163 | - */ |
|
| 164 | - public function getTypo3QuerySettings() |
|
| 165 | - { |
|
| 166 | - if (!$this->typo3QuerySettings instanceof QuerySettingsInterface) { |
|
| 167 | - throw new Exception('Tried to get the query settings without setting them before.', 1248689115); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - // Apply possible settings to the query. |
|
| 171 | - if ($this->isBackendMode()) { |
|
| 172 | - /** @var BackendConfigurationManager $backendConfigurationManager */ |
|
| 173 | - $backendConfigurationManager = GeneralUtility::makeInstance(BackendConfigurationManager::class); |
|
| 174 | - $configuration = $backendConfigurationManager->getTypoScriptSetup(); |
|
| 175 | - $querySettings = array('respectSysLanguage'); |
|
| 176 | - foreach ($querySettings as $setting) { |
|
| 177 | - if (isset($configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting])) { |
|
| 178 | - $value = (bool)$configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting]; |
|
| 179 | - ObjectAccess::setProperty($this->typo3QuerySettings, $setting, $value); |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - return $this->typo3QuerySettings; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Returns the type this query cares for. |
|
| 189 | - * |
|
| 190 | - * @return string |
|
| 191 | - * @api |
|
| 192 | - */ |
|
| 193 | - public function getType() |
|
| 194 | - { |
|
| 195 | - return $this->type; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * Sets the source to fetch the result from |
|
| 200 | - * |
|
| 201 | - * @param SourceInterface $source |
|
| 202 | - */ |
|
| 203 | - public function setSource(SourceInterface $source) |
|
| 204 | - { |
|
| 205 | - $this->source = $source; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Returns the selectorn name or an empty string, if the source is not a selector |
|
| 210 | - * TODO This has to be checked at another place |
|
| 211 | - * |
|
| 212 | - * @return string The selector name |
|
| 213 | - */ |
|
| 214 | - protected function getSelectorName() |
|
| 215 | - { |
|
| 216 | - if ($this->getSource() instanceof SelectorInterface) { |
|
| 217 | - return $this->source->getSelectorName(); |
|
| 218 | - } else { |
|
| 219 | - return ''; |
|
| 220 | - } |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * Gets the node-tuple source for this query. |
|
| 225 | - * |
|
| 226 | - * @return SourceInterface the node-tuple source; non-null |
|
| 227 | - */ |
|
| 228 | - public function getSource() |
|
| 229 | - { |
|
| 230 | - if ($this->source === null) { |
|
| 231 | - $this->source = $this->qomFactory->selector($this->getType()); |
|
| 232 | - } |
|
| 233 | - return $this->source; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * Executes the query against the database and returns the result |
|
| 238 | - * |
|
| 239 | - * @return QueryResultInterface|array The query result object or an array if $this->getQuerySettings()->getReturnRawQueryResult() is true |
|
| 240 | - * @api |
|
| 241 | - */ |
|
| 242 | - public function execute($returnRawQueryResult = false) |
|
| 243 | - { |
|
| 244 | - /** @var VidiDbBackend $backend */ |
|
| 245 | - $backend = GeneralUtility::makeInstance(VidiDbBackend::class, $this); |
|
| 246 | - return $backend->fetchResult(); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * Sets the property names to order the result by. Expected like this: |
|
| 251 | - * array( |
|
| 252 | - * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING, |
|
| 253 | - * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING |
|
| 254 | - * ) |
|
| 255 | - * where 'foo' and 'bar' are property names. |
|
| 256 | - * |
|
| 257 | - * @param array $orderings The property names to order by |
|
| 258 | - * @return QueryInterface |
|
| 259 | - * @api |
|
| 260 | - */ |
|
| 261 | - public function setOrderings(array $orderings) |
|
| 262 | - { |
|
| 263 | - $this->orderings = $orderings; |
|
| 264 | - return $this; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * Returns the property names to order the result by. Like this: |
|
| 269 | - * array( |
|
| 270 | - * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING, |
|
| 271 | - * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING |
|
| 272 | - * ) |
|
| 273 | - * |
|
| 274 | - * @return array |
|
| 275 | - */ |
|
| 276 | - public function getOrderings() |
|
| 277 | - { |
|
| 278 | - return $this->orderings; |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * Sets the maximum size of the result set to limit. Returns $this to allow |
|
| 283 | - * for chaining (fluid interface) |
|
| 284 | - * |
|
| 285 | - * @param integer $limit |
|
| 286 | - * @throws \InvalidArgumentException |
|
| 287 | - * @return QueryInterface |
|
| 288 | - * @api |
|
| 289 | - */ |
|
| 290 | - public function setLimit($limit) |
|
| 291 | - { |
|
| 292 | - if (!is_int($limit) || $limit < 1) { |
|
| 293 | - throw new \InvalidArgumentException('The limit must be an integer >= 1', 1245071870); |
|
| 294 | - } |
|
| 295 | - $this->limit = $limit; |
|
| 296 | - return $this; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * Resets a previously set maximum size of the result set. Returns $this to allow |
|
| 301 | - * for chaining (fluid interface) |
|
| 302 | - * |
|
| 303 | - * @return QueryInterface |
|
| 304 | - * @api |
|
| 305 | - */ |
|
| 306 | - public function unsetLimit() |
|
| 307 | - { |
|
| 308 | - unset($this->limit); |
|
| 309 | - return $this; |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * Returns the maximum size of the result set to limit. |
|
| 314 | - * |
|
| 315 | - * @return integer |
|
| 316 | - * @api |
|
| 317 | - */ |
|
| 318 | - public function getLimit() |
|
| 319 | - { |
|
| 320 | - return $this->limit; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * Sets the start offset of the result set to offset. Returns $this to |
|
| 325 | - * allow for chaining (fluid interface) |
|
| 326 | - * |
|
| 327 | - * @param integer $offset |
|
| 328 | - * @throws \InvalidArgumentException |
|
| 329 | - * @return QueryInterface |
|
| 330 | - * @api |
|
| 331 | - */ |
|
| 332 | - public function setOffset($offset) |
|
| 333 | - { |
|
| 334 | - if (!is_int($offset) || $offset < 0) { |
|
| 335 | - throw new \InvalidArgumentException('The offset must be a positive integer', 1245071872); |
|
| 336 | - } |
|
| 337 | - $this->offset = $offset; |
|
| 338 | - return $this; |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * Returns the start offset of the result set. |
|
| 343 | - * |
|
| 344 | - * @return integer |
|
| 345 | - * @api |
|
| 346 | - */ |
|
| 347 | - public function getOffset() |
|
| 348 | - { |
|
| 349 | - return $this->offset; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * The constraint used to limit the result set. Returns $this to allow |
|
| 354 | - * for chaining (fluid interface) |
|
| 355 | - * |
|
| 356 | - * @param ConstraintInterface $constraint |
|
| 357 | - * @return QueryInterface |
|
| 358 | - * @api |
|
| 359 | - */ |
|
| 360 | - public function matching($constraint) |
|
| 361 | - { |
|
| 362 | - $this->constraint = $constraint; |
|
| 363 | - return $this; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - /** |
|
| 367 | - * Gets the constraint for this query. |
|
| 368 | - * |
|
| 369 | - * @return ConstraintInterface the constraint, or null if none |
|
| 370 | - * @api |
|
| 371 | - */ |
|
| 372 | - public function getConstraint() |
|
| 373 | - { |
|
| 374 | - return $this->constraint; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * Performs a logical conjunction of the given constraints. The method takes one or more contraints and concatenates them with a boolean AND. |
|
| 379 | - * It also scepts a single array of constraints to be concatenated. |
|
| 380 | - * |
|
| 381 | - * @param mixed $constraint1 The first of multiple constraints or an array of constraints. |
|
| 382 | - * @throws InvalidNumberOfConstraintsException |
|
| 383 | - * @return AndInterface |
|
| 384 | - * @api |
|
| 385 | - */ |
|
| 386 | - public function logicalAnd($constraint1) |
|
| 387 | - { |
|
| 388 | - if (is_array($constraint1)) { |
|
| 389 | - $resultingConstraint = array_shift($constraint1); |
|
| 390 | - $constraints = $constraint1; |
|
| 391 | - } else { |
|
| 392 | - $constraints = func_get_args(); |
|
| 393 | - $resultingConstraint = array_shift($constraints); |
|
| 394 | - } |
|
| 395 | - if ($resultingConstraint === null) { |
|
| 396 | - throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289500); |
|
| 397 | - } |
|
| 398 | - foreach ($constraints as $constraint) { |
|
| 399 | - $resultingConstraint = $this->qomFactory->_and($resultingConstraint, $constraint); |
|
| 400 | - } |
|
| 401 | - return $resultingConstraint; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * Performs a logical disjunction of the two given constraints |
|
| 406 | - * |
|
| 407 | - * @param mixed $constraint1 The first of multiple constraints or an array of constraints. |
|
| 408 | - * @throws InvalidNumberOfConstraintsException |
|
| 409 | - * @return OrInterface |
|
| 410 | - * @api |
|
| 411 | - */ |
|
| 412 | - public function logicalOr($constraint1) |
|
| 413 | - { |
|
| 414 | - if (is_array($constraint1)) { |
|
| 415 | - $resultingConstraint = array_shift($constraint1); |
|
| 416 | - $constraints = $constraint1; |
|
| 417 | - } else { |
|
| 418 | - $constraints = func_get_args(); |
|
| 419 | - $resultingConstraint = array_shift($constraints); |
|
| 420 | - } |
|
| 421 | - if ($resultingConstraint === null) { |
|
| 422 | - throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289501); |
|
| 423 | - } |
|
| 424 | - foreach ($constraints as $constraint) { |
|
| 425 | - $resultingConstraint = $this->qomFactory->_or($resultingConstraint, $constraint); |
|
| 426 | - } |
|
| 427 | - return $resultingConstraint; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * Performs a logical negation of the given constraint |
|
| 432 | - * |
|
| 433 | - * @param ConstraintInterface $constraint Constraint to negate |
|
| 434 | - * @throws \RuntimeException |
|
| 435 | - * @return NotInterface |
|
| 436 | - * @api |
|
| 437 | - */ |
|
| 438 | - public function logicalNot(ConstraintInterface $constraint) |
|
| 439 | - { |
|
| 440 | - return $this->qomFactory->not($constraint); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * Returns an equals criterion used for matching objects against a query |
|
| 445 | - * |
|
| 446 | - * @param string $propertyName The name of the property to compare against |
|
| 447 | - * @param mixed $operand The value to compare with |
|
| 448 | - * @param boolean $caseSensitive Whether the equality test should be done case-sensitive |
|
| 449 | - * @return ComparisonInterface |
|
| 450 | - * @api |
|
| 451 | - */ |
|
| 452 | - public function equals($propertyName, $operand, $caseSensitive = true) |
|
| 453 | - { |
|
| 454 | - if (is_object($operand) || $caseSensitive) { |
|
| 455 | - $comparison = $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_EQUAL_TO, $operand); |
|
| 456 | - } else { |
|
| 457 | - $comparison = $this->qomFactory->comparison($this->qomFactory->lowerCase($this->qomFactory->propertyValue($propertyName, $this->getSelectorName())), QueryInterface::OPERATOR_EQUAL_TO, mb_strtolower($operand, \TYPO3\CMS\Extbase\Persistence\Generic\Query::CHARSET)); |
|
| 458 | - } |
|
| 459 | - return $comparison; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - /** |
|
| 463 | - * Returns a like criterion used for matching objects against a query |
|
| 464 | - * |
|
| 465 | - * @param string $propertyName The name of the property to compare against |
|
| 466 | - * @param mixed $operand The value to compare with |
|
| 467 | - * @param boolean $caseSensitive Whether the matching should be done case-sensitive |
|
| 468 | - * @return ComparisonInterface |
|
| 469 | - * @api |
|
| 470 | - */ |
|
| 471 | - public function like($propertyName, $operand, $caseSensitive = true) |
|
| 472 | - { |
|
| 473 | - return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LIKE, $operand); |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - /** |
|
| 477 | - * Returns a "contains" criterion used for matching objects against a query. |
|
| 478 | - * It matches if the multivalued property contains the given operand. |
|
| 479 | - * |
|
| 480 | - * @param string $propertyName The name of the (multivalued) property to compare against |
|
| 481 | - * @param mixed $operand The value to compare with |
|
| 482 | - * @return ComparisonInterface |
|
| 483 | - * @api |
|
| 484 | - */ |
|
| 485 | - public function contains($propertyName, $operand) |
|
| 486 | - { |
|
| 487 | - return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_CONTAINS, $operand); |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - /** |
|
| 491 | - * Returns an "in" criterion used for matching objects against a query. It |
|
| 492 | - * matches if the property's value is contained in the multivalued operand. |
|
| 493 | - * |
|
| 494 | - * @param string $propertyName The name of the property to compare against |
|
| 495 | - * @param mixed $operand The value to compare with, multivalued |
|
| 496 | - * @throws UnexpectedTypeException |
|
| 497 | - * @return ComparisonInterface |
|
| 498 | - * @api |
|
| 499 | - */ |
|
| 500 | - public function in($propertyName, $operand) |
|
| 501 | - { |
|
| 502 | - if (!is_array($operand) && !$operand instanceof \ArrayAccess && !$operand instanceof \Traversable) { |
|
| 503 | - throw new UnexpectedTypeException('The "in" operator must be given a mutlivalued operand (array, ArrayAccess, Traversable).', 1264678095); |
|
| 504 | - } |
|
| 505 | - return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_IN, $operand); |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - /** |
|
| 509 | - * Returns a less than criterion used for matching objects against a query |
|
| 510 | - * |
|
| 511 | - * @param string $propertyName The name of the property to compare against |
|
| 512 | - * @param mixed $operand The value to compare with |
|
| 513 | - * @return ComparisonInterface |
|
| 514 | - * @api |
|
| 515 | - */ |
|
| 516 | - public function lessThan($propertyName, $operand) |
|
| 517 | - { |
|
| 518 | - return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN, $operand); |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * Returns a less or equal than criterion used for matching objects against a query |
|
| 523 | - * |
|
| 524 | - * @param string $propertyName The name of the property to compare against |
|
| 525 | - * @param mixed $operand The value to compare with |
|
| 526 | - * @return ComparisonInterface |
|
| 527 | - * @api |
|
| 528 | - */ |
|
| 529 | - public function lessThanOrEqual($propertyName, $operand) |
|
| 530 | - { |
|
| 531 | - return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO, $operand); |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - /** |
|
| 535 | - * Returns a greater than criterion used for matching objects against a query |
|
| 536 | - * |
|
| 537 | - * @param string $propertyName The name of the property to compare against |
|
| 538 | - * @param mixed $operand The value to compare with |
|
| 539 | - * @return ComparisonInterface |
|
| 540 | - * @api |
|
| 541 | - */ |
|
| 542 | - public function greaterThan($propertyName, $operand) |
|
| 543 | - { |
|
| 544 | - return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN, $operand); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - /** |
|
| 548 | - * Returns a greater than or equal criterion used for matching objects against a query |
|
| 549 | - * |
|
| 550 | - * @param string $propertyName The name of the property to compare against |
|
| 551 | - * @param mixed $operand The value to compare with |
|
| 552 | - * @return ComparisonInterface |
|
| 553 | - * @api |
|
| 554 | - */ |
|
| 555 | - public function greaterThanOrEqual($propertyName, $operand) |
|
| 556 | - { |
|
| 557 | - return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO, $operand); |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - /** |
|
| 561 | - * Returns the query result count. |
|
| 562 | - * |
|
| 563 | - * @return integer The query result count |
|
| 564 | - * @api |
|
| 565 | - */ |
|
| 566 | - public function count() |
|
| 567 | - { |
|
| 568 | - /** @var VidiDbBackend $backend */ |
|
| 569 | - $backend = GeneralUtility::makeInstance(VidiDbBackend::class, $this); |
|
| 570 | - return $backend->countResult(); |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - /** |
|
| 574 | - * Returns an "isEmpty" criterion used for matching objects against a query. |
|
| 575 | - * It matches if the multivalued property contains no values or is null. |
|
| 576 | - * |
|
| 577 | - * @param string $propertyName The name of the multivalued property to compare against |
|
| 578 | - * @throws NotImplementedException |
|
| 579 | - * @throws InvalidQueryException if used on a single-valued property |
|
| 580 | - * @api |
|
| 581 | - */ |
|
| 582 | - public function isEmpty($propertyName) |
|
| 583 | - { |
|
| 584 | - throw new NotImplementedException(__METHOD__); |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * @return string |
|
| 589 | - */ |
|
| 590 | - public function getDistinct() |
|
| 591 | - { |
|
| 592 | - return $this->distinct; |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * @param string $distinct |
|
| 597 | - * @return $this |
|
| 598 | - */ |
|
| 599 | - public function setDistinct($distinct) |
|
| 600 | - { |
|
| 601 | - $this->distinct = $distinct; |
|
| 602 | - return $this; |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - /** |
|
| 606 | - * Sets the statement of this query. If you use this, you will lose the abstraction from a concrete storage |
|
| 607 | - * backend (database). |
|
| 608 | - * |
|
| 609 | - * @param string|\TYPO3\CMS\Core\Database\PreparedStatement $statement The statement |
|
| 610 | - * @param array $parameters An array of parameters. These will be bound to placeholders '?' in the $statement. |
|
| 611 | - * @return QueryInterface |
|
| 612 | - */ |
|
| 613 | - public function statement($statement, array $parameters = array()) |
|
| 614 | - { |
|
| 615 | - $this->statement = $this->qomFactory->statement($statement, $parameters); |
|
| 616 | - return $this; |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - /** |
|
| 620 | - * Returns the statement of this query. |
|
| 621 | - * |
|
| 622 | - * @return Statement |
|
| 623 | - */ |
|
| 624 | - public function getStatement() |
|
| 625 | - { |
|
| 626 | - return $this->statement; |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - /** |
|
| 630 | - * Returns whether the current mode is Backend. |
|
| 631 | - * |
|
| 632 | - * @return bool |
|
| 633 | - */ |
|
| 634 | - protected function isBackendMode() |
|
| 635 | - { |
|
| 636 | - return ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend(); |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - /** |
|
| 640 | - * @return string |
|
| 641 | - */ |
|
| 642 | - public function getSourceFieldName() |
|
| 643 | - { |
|
| 644 | - return $this->sourceFieldName; |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - /** |
|
| 648 | - * @param string $sourceFieldName |
|
| 649 | - * @return $this |
|
| 650 | - */ |
|
| 651 | - public function setSourceFieldName($sourceFieldName) |
|
| 652 | - { |
|
| 653 | - $this->sourceFieldName = $sourceFieldName; |
|
| 654 | - return $this; |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - public function setQuerySettings(QuerySettingsInterface $querySettings) |
|
| 658 | - { |
|
| 659 | - $this->typo3QuerySettings = $querySettings; |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - public function getQuerySettings() |
|
| 663 | - { |
|
| 664 | - return $this->typo3QuerySettings; |
|
| 665 | - } |
|
| 44 | + /** |
|
| 45 | + * An inner join. |
|
| 46 | + */ |
|
| 47 | + public const JCR_JOIN_TYPE_INNER = '{http://www.jcp.org/jcr/1.0}joinTypeInner'; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * A left-outer join. |
|
| 51 | + */ |
|
| 52 | + public const JCR_JOIN_TYPE_LEFT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeLeftOuter'; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * A right-outer join. |
|
| 56 | + */ |
|
| 57 | + public const JCR_JOIN_TYPE_RIGHT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeRightOuter'; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Charset of strings in QOM |
|
| 61 | + */ |
|
| 62 | + public const CHARSET = 'utf-8'; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @var string |
|
| 66 | + */ |
|
| 67 | + protected $sourceFieldName; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @var string |
|
| 71 | + */ |
|
| 72 | + protected $type; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @var PersistenceManagerInterface |
|
| 76 | + */ |
|
| 77 | + protected $persistenceManager; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @var QueryObjectModelFactory |
|
| 81 | + */ |
|
| 82 | + protected $qomFactory; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @var SourceInterface |
|
| 86 | + */ |
|
| 87 | + protected $source; |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @var ConstraintInterface |
|
| 91 | + */ |
|
| 92 | + protected $constraint; |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @var Statement |
|
| 96 | + */ |
|
| 97 | + protected $statement; |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @var array |
|
| 101 | + */ |
|
| 102 | + protected $orderings = []; |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * @var int |
|
| 106 | + */ |
|
| 107 | + protected $limit; |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @var int |
|
| 111 | + */ |
|
| 112 | + protected $offset; |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Apply DISTINCT upon property. |
|
| 116 | + * |
|
| 117 | + * @var string |
|
| 118 | + */ |
|
| 119 | + protected $distinct; |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * The query settings. |
|
| 123 | + * |
|
| 124 | + * @var Typo3QuerySettings |
|
| 125 | + */ |
|
| 126 | + public Typo3QuerySettings $typo3QuerySettings; |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Constructs a query object working on the given class name |
|
| 130 | + * |
|
| 131 | + * @param string $type |
|
| 132 | + */ |
|
| 133 | + public function __construct($type) |
|
| 134 | + { |
|
| 135 | + $this->type = $type; |
|
| 136 | + $this->persistenceManager = GeneralUtility::makeInstance(PersistenceManagerInterface::class); |
|
| 137 | + $this->qomFactory = GeneralUtility::makeInstance(QueryObjectModelFactory::class); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + public function injectTypo3QuerySettings(Typo3QuerySettings $querySettings): void |
|
| 141 | + { |
|
| 142 | + $this->typo3QuerySettings = $querySettings; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Sets the Query Settings. These Query settings must match the settings expected by |
|
| 147 | + * the specific Storage Backend. |
|
| 148 | + * |
|
| 149 | + * @param QuerySettingsInterface $typo3QuerySettings The Query Settings |
|
| 150 | + * @return void |
|
| 151 | + */ |
|
| 152 | + public function setTypo3QuerySettings(QuerySettingsInterface $typo3QuerySettings) |
|
| 153 | + { |
|
| 154 | + $this->typo3QuerySettings = $typo3QuerySettings; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Returns the Query Settings. |
|
| 159 | + * |
|
| 160 | + * @throws \Exception |
|
| 161 | + * @return Typo3QuerySettings $querySettings The Query Settings |
|
| 162 | + * @api This method is not part of FLOW3 API |
|
| 163 | + */ |
|
| 164 | + public function getTypo3QuerySettings() |
|
| 165 | + { |
|
| 166 | + if (!$this->typo3QuerySettings instanceof QuerySettingsInterface) { |
|
| 167 | + throw new Exception('Tried to get the query settings without setting them before.', 1248689115); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + // Apply possible settings to the query. |
|
| 171 | + if ($this->isBackendMode()) { |
|
| 172 | + /** @var BackendConfigurationManager $backendConfigurationManager */ |
|
| 173 | + $backendConfigurationManager = GeneralUtility::makeInstance(BackendConfigurationManager::class); |
|
| 174 | + $configuration = $backendConfigurationManager->getTypoScriptSetup(); |
|
| 175 | + $querySettings = array('respectSysLanguage'); |
|
| 176 | + foreach ($querySettings as $setting) { |
|
| 177 | + if (isset($configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting])) { |
|
| 178 | + $value = (bool)$configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting]; |
|
| 179 | + ObjectAccess::setProperty($this->typo3QuerySettings, $setting, $value); |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + return $this->typo3QuerySettings; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Returns the type this query cares for. |
|
| 189 | + * |
|
| 190 | + * @return string |
|
| 191 | + * @api |
|
| 192 | + */ |
|
| 193 | + public function getType() |
|
| 194 | + { |
|
| 195 | + return $this->type; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * Sets the source to fetch the result from |
|
| 200 | + * |
|
| 201 | + * @param SourceInterface $source |
|
| 202 | + */ |
|
| 203 | + public function setSource(SourceInterface $source) |
|
| 204 | + { |
|
| 205 | + $this->source = $source; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Returns the selectorn name or an empty string, if the source is not a selector |
|
| 210 | + * TODO This has to be checked at another place |
|
| 211 | + * |
|
| 212 | + * @return string The selector name |
|
| 213 | + */ |
|
| 214 | + protected function getSelectorName() |
|
| 215 | + { |
|
| 216 | + if ($this->getSource() instanceof SelectorInterface) { |
|
| 217 | + return $this->source->getSelectorName(); |
|
| 218 | + } else { |
|
| 219 | + return ''; |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * Gets the node-tuple source for this query. |
|
| 225 | + * |
|
| 226 | + * @return SourceInterface the node-tuple source; non-null |
|
| 227 | + */ |
|
| 228 | + public function getSource() |
|
| 229 | + { |
|
| 230 | + if ($this->source === null) { |
|
| 231 | + $this->source = $this->qomFactory->selector($this->getType()); |
|
| 232 | + } |
|
| 233 | + return $this->source; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * Executes the query against the database and returns the result |
|
| 238 | + * |
|
| 239 | + * @return QueryResultInterface|array The query result object or an array if $this->getQuerySettings()->getReturnRawQueryResult() is true |
|
| 240 | + * @api |
|
| 241 | + */ |
|
| 242 | + public function execute($returnRawQueryResult = false) |
|
| 243 | + { |
|
| 244 | + /** @var VidiDbBackend $backend */ |
|
| 245 | + $backend = GeneralUtility::makeInstance(VidiDbBackend::class, $this); |
|
| 246 | + return $backend->fetchResult(); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Sets the property names to order the result by. Expected like this: |
|
| 251 | + * array( |
|
| 252 | + * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING, |
|
| 253 | + * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING |
|
| 254 | + * ) |
|
| 255 | + * where 'foo' and 'bar' are property names. |
|
| 256 | + * |
|
| 257 | + * @param array $orderings The property names to order by |
|
| 258 | + * @return QueryInterface |
|
| 259 | + * @api |
|
| 260 | + */ |
|
| 261 | + public function setOrderings(array $orderings) |
|
| 262 | + { |
|
| 263 | + $this->orderings = $orderings; |
|
| 264 | + return $this; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * Returns the property names to order the result by. Like this: |
|
| 269 | + * array( |
|
| 270 | + * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING, |
|
| 271 | + * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING |
|
| 272 | + * ) |
|
| 273 | + * |
|
| 274 | + * @return array |
|
| 275 | + */ |
|
| 276 | + public function getOrderings() |
|
| 277 | + { |
|
| 278 | + return $this->orderings; |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * Sets the maximum size of the result set to limit. Returns $this to allow |
|
| 283 | + * for chaining (fluid interface) |
|
| 284 | + * |
|
| 285 | + * @param integer $limit |
|
| 286 | + * @throws \InvalidArgumentException |
|
| 287 | + * @return QueryInterface |
|
| 288 | + * @api |
|
| 289 | + */ |
|
| 290 | + public function setLimit($limit) |
|
| 291 | + { |
|
| 292 | + if (!is_int($limit) || $limit < 1) { |
|
| 293 | + throw new \InvalidArgumentException('The limit must be an integer >= 1', 1245071870); |
|
| 294 | + } |
|
| 295 | + $this->limit = $limit; |
|
| 296 | + return $this; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * Resets a previously set maximum size of the result set. Returns $this to allow |
|
| 301 | + * for chaining (fluid interface) |
|
| 302 | + * |
|
| 303 | + * @return QueryInterface |
|
| 304 | + * @api |
|
| 305 | + */ |
|
| 306 | + public function unsetLimit() |
|
| 307 | + { |
|
| 308 | + unset($this->limit); |
|
| 309 | + return $this; |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * Returns the maximum size of the result set to limit. |
|
| 314 | + * |
|
| 315 | + * @return integer |
|
| 316 | + * @api |
|
| 317 | + */ |
|
| 318 | + public function getLimit() |
|
| 319 | + { |
|
| 320 | + return $this->limit; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * Sets the start offset of the result set to offset. Returns $this to |
|
| 325 | + * allow for chaining (fluid interface) |
|
| 326 | + * |
|
| 327 | + * @param integer $offset |
|
| 328 | + * @throws \InvalidArgumentException |
|
| 329 | + * @return QueryInterface |
|
| 330 | + * @api |
|
| 331 | + */ |
|
| 332 | + public function setOffset($offset) |
|
| 333 | + { |
|
| 334 | + if (!is_int($offset) || $offset < 0) { |
|
| 335 | + throw new \InvalidArgumentException('The offset must be a positive integer', 1245071872); |
|
| 336 | + } |
|
| 337 | + $this->offset = $offset; |
|
| 338 | + return $this; |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * Returns the start offset of the result set. |
|
| 343 | + * |
|
| 344 | + * @return integer |
|
| 345 | + * @api |
|
| 346 | + */ |
|
| 347 | + public function getOffset() |
|
| 348 | + { |
|
| 349 | + return $this->offset; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * The constraint used to limit the result set. Returns $this to allow |
|
| 354 | + * for chaining (fluid interface) |
|
| 355 | + * |
|
| 356 | + * @param ConstraintInterface $constraint |
|
| 357 | + * @return QueryInterface |
|
| 358 | + * @api |
|
| 359 | + */ |
|
| 360 | + public function matching($constraint) |
|
| 361 | + { |
|
| 362 | + $this->constraint = $constraint; |
|
| 363 | + return $this; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + /** |
|
| 367 | + * Gets the constraint for this query. |
|
| 368 | + * |
|
| 369 | + * @return ConstraintInterface the constraint, or null if none |
|
| 370 | + * @api |
|
| 371 | + */ |
|
| 372 | + public function getConstraint() |
|
| 373 | + { |
|
| 374 | + return $this->constraint; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * Performs a logical conjunction of the given constraints. The method takes one or more contraints and concatenates them with a boolean AND. |
|
| 379 | + * It also scepts a single array of constraints to be concatenated. |
|
| 380 | + * |
|
| 381 | + * @param mixed $constraint1 The first of multiple constraints or an array of constraints. |
|
| 382 | + * @throws InvalidNumberOfConstraintsException |
|
| 383 | + * @return AndInterface |
|
| 384 | + * @api |
|
| 385 | + */ |
|
| 386 | + public function logicalAnd($constraint1) |
|
| 387 | + { |
|
| 388 | + if (is_array($constraint1)) { |
|
| 389 | + $resultingConstraint = array_shift($constraint1); |
|
| 390 | + $constraints = $constraint1; |
|
| 391 | + } else { |
|
| 392 | + $constraints = func_get_args(); |
|
| 393 | + $resultingConstraint = array_shift($constraints); |
|
| 394 | + } |
|
| 395 | + if ($resultingConstraint === null) { |
|
| 396 | + throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289500); |
|
| 397 | + } |
|
| 398 | + foreach ($constraints as $constraint) { |
|
| 399 | + $resultingConstraint = $this->qomFactory->_and($resultingConstraint, $constraint); |
|
| 400 | + } |
|
| 401 | + return $resultingConstraint; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * Performs a logical disjunction of the two given constraints |
|
| 406 | + * |
|
| 407 | + * @param mixed $constraint1 The first of multiple constraints or an array of constraints. |
|
| 408 | + * @throws InvalidNumberOfConstraintsException |
|
| 409 | + * @return OrInterface |
|
| 410 | + * @api |
|
| 411 | + */ |
|
| 412 | + public function logicalOr($constraint1) |
|
| 413 | + { |
|
| 414 | + if (is_array($constraint1)) { |
|
| 415 | + $resultingConstraint = array_shift($constraint1); |
|
| 416 | + $constraints = $constraint1; |
|
| 417 | + } else { |
|
| 418 | + $constraints = func_get_args(); |
|
| 419 | + $resultingConstraint = array_shift($constraints); |
|
| 420 | + } |
|
| 421 | + if ($resultingConstraint === null) { |
|
| 422 | + throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289501); |
|
| 423 | + } |
|
| 424 | + foreach ($constraints as $constraint) { |
|
| 425 | + $resultingConstraint = $this->qomFactory->_or($resultingConstraint, $constraint); |
|
| 426 | + } |
|
| 427 | + return $resultingConstraint; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * Performs a logical negation of the given constraint |
|
| 432 | + * |
|
| 433 | + * @param ConstraintInterface $constraint Constraint to negate |
|
| 434 | + * @throws \RuntimeException |
|
| 435 | + * @return NotInterface |
|
| 436 | + * @api |
|
| 437 | + */ |
|
| 438 | + public function logicalNot(ConstraintInterface $constraint) |
|
| 439 | + { |
|
| 440 | + return $this->qomFactory->not($constraint); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * Returns an equals criterion used for matching objects against a query |
|
| 445 | + * |
|
| 446 | + * @param string $propertyName The name of the property to compare against |
|
| 447 | + * @param mixed $operand The value to compare with |
|
| 448 | + * @param boolean $caseSensitive Whether the equality test should be done case-sensitive |
|
| 449 | + * @return ComparisonInterface |
|
| 450 | + * @api |
|
| 451 | + */ |
|
| 452 | + public function equals($propertyName, $operand, $caseSensitive = true) |
|
| 453 | + { |
|
| 454 | + if (is_object($operand) || $caseSensitive) { |
|
| 455 | + $comparison = $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_EQUAL_TO, $operand); |
|
| 456 | + } else { |
|
| 457 | + $comparison = $this->qomFactory->comparison($this->qomFactory->lowerCase($this->qomFactory->propertyValue($propertyName, $this->getSelectorName())), QueryInterface::OPERATOR_EQUAL_TO, mb_strtolower($operand, \TYPO3\CMS\Extbase\Persistence\Generic\Query::CHARSET)); |
|
| 458 | + } |
|
| 459 | + return $comparison; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + /** |
|
| 463 | + * Returns a like criterion used for matching objects against a query |
|
| 464 | + * |
|
| 465 | + * @param string $propertyName The name of the property to compare against |
|
| 466 | + * @param mixed $operand The value to compare with |
|
| 467 | + * @param boolean $caseSensitive Whether the matching should be done case-sensitive |
|
| 468 | + * @return ComparisonInterface |
|
| 469 | + * @api |
|
| 470 | + */ |
|
| 471 | + public function like($propertyName, $operand, $caseSensitive = true) |
|
| 472 | + { |
|
| 473 | + return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LIKE, $operand); |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + /** |
|
| 477 | + * Returns a "contains" criterion used for matching objects against a query. |
|
| 478 | + * It matches if the multivalued property contains the given operand. |
|
| 479 | + * |
|
| 480 | + * @param string $propertyName The name of the (multivalued) property to compare against |
|
| 481 | + * @param mixed $operand The value to compare with |
|
| 482 | + * @return ComparisonInterface |
|
| 483 | + * @api |
|
| 484 | + */ |
|
| 485 | + public function contains($propertyName, $operand) |
|
| 486 | + { |
|
| 487 | + return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_CONTAINS, $operand); |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + /** |
|
| 491 | + * Returns an "in" criterion used for matching objects against a query. It |
|
| 492 | + * matches if the property's value is contained in the multivalued operand. |
|
| 493 | + * |
|
| 494 | + * @param string $propertyName The name of the property to compare against |
|
| 495 | + * @param mixed $operand The value to compare with, multivalued |
|
| 496 | + * @throws UnexpectedTypeException |
|
| 497 | + * @return ComparisonInterface |
|
| 498 | + * @api |
|
| 499 | + */ |
|
| 500 | + public function in($propertyName, $operand) |
|
| 501 | + { |
|
| 502 | + if (!is_array($operand) && !$operand instanceof \ArrayAccess && !$operand instanceof \Traversable) { |
|
| 503 | + throw new UnexpectedTypeException('The "in" operator must be given a mutlivalued operand (array, ArrayAccess, Traversable).', 1264678095); |
|
| 504 | + } |
|
| 505 | + return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_IN, $operand); |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + /** |
|
| 509 | + * Returns a less than criterion used for matching objects against a query |
|
| 510 | + * |
|
| 511 | + * @param string $propertyName The name of the property to compare against |
|
| 512 | + * @param mixed $operand The value to compare with |
|
| 513 | + * @return ComparisonInterface |
|
| 514 | + * @api |
|
| 515 | + */ |
|
| 516 | + public function lessThan($propertyName, $operand) |
|
| 517 | + { |
|
| 518 | + return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN, $operand); |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * Returns a less or equal than criterion used for matching objects against a query |
|
| 523 | + * |
|
| 524 | + * @param string $propertyName The name of the property to compare against |
|
| 525 | + * @param mixed $operand The value to compare with |
|
| 526 | + * @return ComparisonInterface |
|
| 527 | + * @api |
|
| 528 | + */ |
|
| 529 | + public function lessThanOrEqual($propertyName, $operand) |
|
| 530 | + { |
|
| 531 | + return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO, $operand); |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + /** |
|
| 535 | + * Returns a greater than criterion used for matching objects against a query |
|
| 536 | + * |
|
| 537 | + * @param string $propertyName The name of the property to compare against |
|
| 538 | + * @param mixed $operand The value to compare with |
|
| 539 | + * @return ComparisonInterface |
|
| 540 | + * @api |
|
| 541 | + */ |
|
| 542 | + public function greaterThan($propertyName, $operand) |
|
| 543 | + { |
|
| 544 | + return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN, $operand); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + /** |
|
| 548 | + * Returns a greater than or equal criterion used for matching objects against a query |
|
| 549 | + * |
|
| 550 | + * @param string $propertyName The name of the property to compare against |
|
| 551 | + * @param mixed $operand The value to compare with |
|
| 552 | + * @return ComparisonInterface |
|
| 553 | + * @api |
|
| 554 | + */ |
|
| 555 | + public function greaterThanOrEqual($propertyName, $operand) |
|
| 556 | + { |
|
| 557 | + return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO, $operand); |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + /** |
|
| 561 | + * Returns the query result count. |
|
| 562 | + * |
|
| 563 | + * @return integer The query result count |
|
| 564 | + * @api |
|
| 565 | + */ |
|
| 566 | + public function count() |
|
| 567 | + { |
|
| 568 | + /** @var VidiDbBackend $backend */ |
|
| 569 | + $backend = GeneralUtility::makeInstance(VidiDbBackend::class, $this); |
|
| 570 | + return $backend->countResult(); |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + /** |
|
| 574 | + * Returns an "isEmpty" criterion used for matching objects against a query. |
|
| 575 | + * It matches if the multivalued property contains no values or is null. |
|
| 576 | + * |
|
| 577 | + * @param string $propertyName The name of the multivalued property to compare against |
|
| 578 | + * @throws NotImplementedException |
|
| 579 | + * @throws InvalidQueryException if used on a single-valued property |
|
| 580 | + * @api |
|
| 581 | + */ |
|
| 582 | + public function isEmpty($propertyName) |
|
| 583 | + { |
|
| 584 | + throw new NotImplementedException(__METHOD__); |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * @return string |
|
| 589 | + */ |
|
| 590 | + public function getDistinct() |
|
| 591 | + { |
|
| 592 | + return $this->distinct; |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * @param string $distinct |
|
| 597 | + * @return $this |
|
| 598 | + */ |
|
| 599 | + public function setDistinct($distinct) |
|
| 600 | + { |
|
| 601 | + $this->distinct = $distinct; |
|
| 602 | + return $this; |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + /** |
|
| 606 | + * Sets the statement of this query. If you use this, you will lose the abstraction from a concrete storage |
|
| 607 | + * backend (database). |
|
| 608 | + * |
|
| 609 | + * @param string|\TYPO3\CMS\Core\Database\PreparedStatement $statement The statement |
|
| 610 | + * @param array $parameters An array of parameters. These will be bound to placeholders '?' in the $statement. |
|
| 611 | + * @return QueryInterface |
|
| 612 | + */ |
|
| 613 | + public function statement($statement, array $parameters = array()) |
|
| 614 | + { |
|
| 615 | + $this->statement = $this->qomFactory->statement($statement, $parameters); |
|
| 616 | + return $this; |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + /** |
|
| 620 | + * Returns the statement of this query. |
|
| 621 | + * |
|
| 622 | + * @return Statement |
|
| 623 | + */ |
|
| 624 | + public function getStatement() |
|
| 625 | + { |
|
| 626 | + return $this->statement; |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + /** |
|
| 630 | + * Returns whether the current mode is Backend. |
|
| 631 | + * |
|
| 632 | + * @return bool |
|
| 633 | + */ |
|
| 634 | + protected function isBackendMode() |
|
| 635 | + { |
|
| 636 | + return ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend(); |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + /** |
|
| 640 | + * @return string |
|
| 641 | + */ |
|
| 642 | + public function getSourceFieldName() |
|
| 643 | + { |
|
| 644 | + return $this->sourceFieldName; |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + /** |
|
| 648 | + * @param string $sourceFieldName |
|
| 649 | + * @return $this |
|
| 650 | + */ |
|
| 651 | + public function setSourceFieldName($sourceFieldName) |
|
| 652 | + { |
|
| 653 | + $this->sourceFieldName = $sourceFieldName; |
|
| 654 | + return $this; |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + public function setQuerySettings(QuerySettingsInterface $querySettings) |
|
| 658 | + { |
|
| 659 | + $this->typo3QuerySettings = $querySettings; |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + public function getQuerySettings() |
|
| 663 | + { |
|
| 664 | + return $this->typo3QuerySettings; |
|
| 665 | + } |
|
| 666 | 666 | } |
@@ -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 | } |