/** * Builds a data map by adding column maps for all the configured columns in the $TCA. * It also resolves the type of values the column is holding and the typo of relation the column * represents. * * @param string $className The class name you want to fetch the Data Map for * @return Tx_Extbase_Persistence_Mapper_DataMap The data map */ public function buildDataMap($className) { if (!class_exists($className)) { throw new Tx_Extbase_Persistence_Exception_InvalidClass('Could not find class definition for name "' . $className . '". This could be caused by a mis-spelling of the class name in the class definition.'); } $recordType = NULL; $subclasses = array(); $tableName = strtolower($className); $columnMapping = array(); $extbaseFrameworkConfiguration = Tx_Extbase_Dispatcher::getExtbaseFrameworkConfiguration(); $classSettings = $extbaseFrameworkConfiguration['persistence']['classes'][$className]; if ($classSettings !== NULL) { if (isset($classSettings['subclasses']) && is_array($classSettings['subclasses'])) { $subclasses = $classSettings['subclasses']; } if (isset($classSettings['mapping']['recordType']) && strlen($classSettings['mapping']['recordType']) > 0) { $recordType = $classSettings['mapping']['recordType']; } if (isset($classSettings['mapping']['tableName']) && strlen($classSettings['mapping']['tableName']) > 0) { $tableName = $classSettings['mapping']['tableName']; } $classHierachy = array_merge(array($className), class_parents($className)); foreach ($classHierachy as $currentClassName) { if (in_array($currentClassName, array('Tx_Extbase_DomainObject_AbstractEntity', 'Tx_Extbase_DomainObject_AbstractValueObject'))) { break; } $currentTableName = strtolower($currentClassName); $currentClassSettings = $extbaseFrameworkConfiguration['persistence']['classes'][$currentClassName]; if ($currentClassSettings !== NULL) { if (isset($currentClassSettings['mapping']['columns']) && is_array($currentClassSettings['mapping']['columns'])) { $columnMapping = t3lib_div::array_merge_recursive_overrule($columnMapping, $currentClassSettings['mapping']['columns'], 0, FALSE); // FALSE means: do not include empty values form 2nd array } } } } $dataMap = t3lib_div::makeInstance('Tx_Extbase_Persistence_Mapper_DataMap', $className, $tableName, $recordType, $subclasses); $dataMap = $this->addMetaDataColumnNames($dataMap, $tableName); // $classPropertyNames = $this->reflectionService->getClassPropertyNames($className); $tcaColumnsDefinition = $this->getColumnsDefinition($tableName); $tcaColumnsDefinition = t3lib_div::array_merge_recursive_overrule($tcaColumnsDefinition, $columnMapping); // TODO Is this is too powerful? foreach ($tcaColumnsDefinition as $columnName => $columnDefinition) { if (isset($columnDefinition['mapOnProperty'])) { $propertyName = $columnDefinition['mapOnProperty']; } else { $propertyName = Tx_Extbase_Utility_Extension::convertUnderscoredToLowerCamelCase($columnName); } // if (in_array($propertyName, $classPropertyNames)) { // TODO Enable check for property existance $columnMap = new Tx_Extbase_Persistence_Mapper_ColumnMap($columnName, $propertyName); $propertyMetaData = $this->reflectionService->getClassSchema($className)->getProperty($propertyName); $columnMap = $this->setRelations($columnMap, $columnDefinition['config'], $propertyMetaData); $dataMap->addColumnMap($columnMap); // } } // debug($dataMap); return $dataMap; }