/** * On initialization, get the columns mapping configuration */ public function initializeObject() { parent::initializeObject(); $this->tableName = ModelUtility::getModelMapping('SJBR\\StaticInfoTables\\Domain\\Model\\Country', ModelUtility::MAPPING_TABLENAME); $this->columnsMapping = ModelUtility::getModelMapping('SJBR\\StaticInfoTables\\Domain\\Model\\Country', ModelUtility::MAPPING_COLUMNS); $this->countryZones = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage'); }
/** * On initialization, get the columns mapping configuration */ public function initializeObject() { parent::initializeObject(); $this->tableName = ModelUtility::getModelMapping('SJBR\\StaticInfoTables\\Domain\\Model\\CountryZone', ModelUtility::MAPPING_TABLENAME); $this->columnsMapping = ModelUtility::getModelMapping('SJBR\\StaticInfoTables\\Domain\\Model\\CountryZone', ModelUtility::MAPPING_COLUMNS); }
/** * Replace the selector's uid index with configured indexField * * @param array $PA: TCA select field parameters array * @return array The new $items array */ protected function replaceSelectorIndexField($PA) { $items = $PA['items']; $indexFields = GeneralUtility::trimExplode(',', $PA['config']['itemsProcFunc_config']['indexField'], TRUE); if (!empty($indexFields)) { $rows = array(); // Collect items uid's $uids = array(); foreach ($items as $key => $item) { if ($items[$key][1]) { $uids[] = $item[1]; } } $uidList = implode(',', $uids); if (!empty($uidList)) { /** @var \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager */ $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'); switch ($PA['config']['foreign_table']) { case 'static_territories': /** @var $territoryRepository SJBR\StaticInfoTables\Domain\Repository\TerritoryRepository */ $territoryRepository = $objectManager->get('SJBR\\StaticInfoTables\\Domain\\Repository\\TerritoryRepository'); $objects = $territoryRepository->findAllByUidInList($uidList)->toArray(); $columnsMapping = ModelUtility::getModelMapping('SJBR\\StaticInfoTables\\Domain\\Model\\Territory', ModelUtility::MAPPING_COLUMNS); break; case 'static_countries': /** @var $countryRepository SJBR\StaticInfoTables\Domain\Repository\CountryRepository */ $countryRepository = $objectManager->get('SJBR\\StaticInfoTables\\Domain\\Repository\\CountryRepository'); $objects = $countryRepository->findAllByUidInList($uidList)->toArray(); $columnsMapping = ModelUtility::getModelMapping('SJBR\\StaticInfoTables\\Domain\\Model\\Country', ModelUtility::MAPPING_COLUMNS); break; case 'static_country_zones': /** @var $countryZoneRepository SJBR\StaticInfoTables\Domain\Repository\CountryZoneRepository */ $countryZoneRepository = $objectManager->get('SJBR\\StaticInfoTables\\Domain\\Repository\\CountryZoneRepository'); $objects = $countryZoneRepository->findAllByUidInList($uidList)->toArray(); $columnsMapping = ModelUtility::getModelMapping('SJBR\\StaticInfoTables\\Domain\\Model\\CountryZone', ModelUtility::MAPPING_COLUMNS); break; case 'static_languages': /** @var $languageRepository SJBR\StaticInfoTables\Domain\Repository\LanguageRepository */ $languageRepository = $objectManager->get('SJBR\\StaticInfoTables\\Domain\\Repository\\LanguageRepository'); $objects = $languageRepository->findAllByUidInList($uidList)->toArray(); $columnsMapping = ModelUtility::getModelMapping('SJBR\\StaticInfoTables\\Domain\\Model\\Language', ModelUtility::MAPPING_COLUMNS); break; case 'static_currencies': /** @var $currencyRepository SJBR\StaticInfoTables\Domain\Repository\CurrencyRepository */ $currencyRepository = $objectManager->get('SJBR\\StaticInfoTables\\Domain\\Repository\\CurrencyRepository'); $objects = $currencyRepository->findAllByUidInList($uidList)->toArray(); $columnsMapping = ModelUtility::getModelMapping('SJBR\\StaticInfoTables\\Domain\\Model\\Currency', ModelUtility::MAPPING_COLUMNS); break; default: break; } if (!empty($objects)) { // Map table column to object property $indexProperties = array(); foreach ($indexFields as $indexField) { if ($columnsMapping[$indexField]['mapOnProperty']) { $indexProperties[] = $columnsMapping[$indexField]['mapOnProperty']; } else { $indexProperties[] = GeneralUtility::underscoredToUpperCamelCase($indexField); } } // Index rows by uid $uidIndexedRows = array(); foreach ($objects as $object) { $uidIndexedObjects[$object->getUid()] = $object; } // Replace the items index field foreach ($items as $key => $item) { if ($items[$key][1]) { $object = $uidIndexedObjects[$items[$key][1]]; $items[$key][1] = $object->_getProperty($indexProperties[0]); if ($indexFields[1] && $object->_getProperty($indexProperties[1])) { $items[$key][1] .= '_' . $object->_getProperty($indexProperties[1]); } } } } } } return $items; }