mirror of
https://github.com/Codappix/search_core.git
synced 2024-11-22 21:16:11 +01:00
CLEANUP: Refactor code
This commit is contained in:
parent
9bf2657318
commit
dc489d6bb8
1 changed files with 62 additions and 25 deletions
|
@ -22,6 +22,7 @@ namespace Leonmrni\SearchCore\Domain\Index\TcaIndexer;
|
||||||
|
|
||||||
use TYPO3\CMS\Backend\Utility\BackendUtility;
|
use TYPO3\CMS\Backend\Utility\BackendUtility;
|
||||||
use TYPO3\CMS\Core\SingletonInterface as Singleton;
|
use TYPO3\CMS\Core\SingletonInterface as Singleton;
|
||||||
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||||
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
|
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,41 +86,20 @@ class RelationResolver implements Singleton
|
||||||
*/
|
*/
|
||||||
protected function resolveValue($value, array $config)
|
protected function resolveValue($value, array $config)
|
||||||
{
|
{
|
||||||
$newValue = [];
|
|
||||||
if ($value === '' || $value === '0') {
|
if ($value === '' || $value === '0') {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Select
|
|
||||||
if (strpos($value, '|') !== false) {
|
if (strpos($value, '|') !== false) {
|
||||||
foreach (\TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $value) as $value) {
|
return $this->resolveSelectValue($value);
|
||||||
$value = substr($value, strpos($value, '|') + 1);
|
|
||||||
$value = rawurldecode($value);
|
|
||||||
$newValue[] = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $newValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inline
|
|
||||||
if (strpos($value, ',') !== false) {
|
if (strpos($value, ',') !== false) {
|
||||||
foreach ($GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', $config['foreign_table'], 'uid in (' . $value . ')') as $record) {
|
return $this->resolveInlineValue($value, $config['foreign_table']);
|
||||||
$newValue[] = BackendUtility::getRecordTitle($config['foreign_table'], $record);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $newValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Static select items
|
|
||||||
if ($config['type'] === 'select' && is_array($config['items'])) {
|
if ($config['type'] === 'select' && is_array($config['items'])) {
|
||||||
foreach ($config['items'] as $item) {
|
return $this->resolveSelectItemValue($value, $config['items']);
|
||||||
if ($item[1] === $value) {
|
|
||||||
return LocalizationUtility::translate($item[0], '');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $newValue;
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -133,4 +113,61 @@ class RelationResolver implements Singleton
|
||||||
|| (isset($config['internal_type']) && strtolower($config['internal_type']) === 'db')
|
|| (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 '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue