From dc489d6bb8418a1761e7eec958c5e0a1c8847758 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 20 Dec 2016 12:10:28 +0100 Subject: [PATCH] CLEANUP: Refactor code --- .../Index/TcaIndexer/RelationResolver.php | 87 +++++++++++++------ 1 file changed, 62 insertions(+), 25 deletions(-) diff --git a/Classes/Domain/Index/TcaIndexer/RelationResolver.php b/Classes/Domain/Index/TcaIndexer/RelationResolver.php index d6ce94c..1ece8ec 100644 --- a/Classes/Domain/Index/TcaIndexer/RelationResolver.php +++ b/Classes/Domain/Index/TcaIndexer/RelationResolver.php @@ -22,6 +22,7 @@ namespace Leonmrni\SearchCore\Domain\Index\TcaIndexer; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\SingletonInterface as Singleton; +use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Utility\LocalizationUtility; /** @@ -85,41 +86,20 @@ class RelationResolver implements Singleton */ protected function resolveValue($value, array $config) { - $newValue = []; if ($value === '' || $value === '0') { return ''; } - - // Select if (strpos($value, '|') !== false) { - foreach (\TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $value) as $value) { - $value = substr($value, strpos($value, '|') + 1); - $value = rawurldecode($value); - $newValue[] = $value; - } - - return $newValue; + return $this->resolveSelectValue($value); } - - // Inline if (strpos($value, ',') !== false) { - foreach ($GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', $config['foreign_table'], 'uid in (' . $value . ')') as $record) { - $newValue[] = BackendUtility::getRecordTitle($config['foreign_table'], $record); - } - - return $newValue; + return $this->resolveInlineValue($value, $config['foreign_table']); } - - // Static select items if ($config['type'] === 'select' && is_array($config['items'])) { - foreach ($config['items'] as $item) { - if ($item[1] === $value) { - return LocalizationUtility::translate($item[0], ''); - } - } + return $this->resolveSelectItemValue($value, $config['items']); } - return $newValue; + return ''; } /** @@ -133,4 +113,61 @@ class RelationResolver implements Singleton || (isset($config['internal_type']) && strtolower($config['internal_type']) === 'db') ; } + + /** + * Resolves internal representation of select to array of labels. + * + * @param string $value + * @return array + */ + protected function resolveSelectValue($value) + { + $newValue = []; + + foreach (GeneralUtility::trimExplode(',', $value) as $value) { + $value = substr($value, strpos($value, '|') + 1); + $value = rawurldecode($value); + $newValue[] = $value; + } + + return $newValue; + } + + /** + * @param string $value + * @param string $table + * + * @return array + */ + protected function resolveInlineValue($value, $table) + { + $newValue = []; + $records = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', $table, 'uid in (' . $value . ')'); + if ($records === null) { + return $newValue; + } + + foreach ($records as $record) { + $newValue[] = BackendUtility::getRecordTitle($table, $record); + } + + return $newValue; + } + + /** + * @param string $value + * @param array $items + * + * @return string + */ + protected function resolveSelectItemValue($value, array $items) + { + foreach ($items as $item) { + if ($item[1] === $value) { + return LocalizationUtility::translate($item[0], ''); + } + } + + return ''; + } }