/**
  * Helper function to find the parents class recordType
  * @param Tx_ExtensionBuilder_Domain_Model_DomainObject $domainObject
  * @return string
  */
 public function render(Tx_ExtensionBuilder_Domain_Model_DomainObject $domainObject)
 {
     $classSettings = $this->configurationManager->getExtbaseClassConfiguration($domainObject->getParentClass());
     if (isset($classSettings['recordType'])) {
         $parentRecordType = $classSettings['recordType'];
     } else {
         $parentRecordType = str_replace('Domain_Model_', '', $domainObject->getParentClass());
         if (!isset($TCA[$domainObject->getDatabaseTableName()]['types'][$parentRecordType])) {
             $parentRecordType = 1;
         }
     }
     $this->templateVariableContainer->add('parentRecordType', $parentRecordType);
     $content = $this->renderChildren();
     $this->templateVariableContainer->remove('parentRecordType');
     return $content;
 }
 /**
  *
  * @param array $extensionBuildConfiguration
  * @return Tx_ExtensionBuilder_Domain_Model_Extension $extension
  */
 public function build(array $extensionBuildConfiguration)
 {
     $extension = t3lib_div::makeInstance('Tx_ExtensionBuilder_Domain_Model_Extension');
     $globalProperties = $extensionBuildConfiguration['properties'];
     if (!is_array($globalProperties)) {
         t3lib_div::devlog('Error: Extension properties not submitted! ' . $extension->getOriginalExtensionKey(), 'builder', 3, $globalProperties);
         throw new Exception('Extension properties not submitted!');
     }
     $this->setExtensionProperties($extension, $globalProperties);
     foreach ($globalProperties['persons'] as $personValues) {
         $person = $this->buildPerson($personValues);
         $extension->addPerson($person);
     }
     foreach ($globalProperties['plugins'] as $pluginValues) {
         $plugin = $this->buildPlugin($pluginValues);
         $extension->addPlugin($plugin);
     }
     foreach ($globalProperties['backendModules'] as $backendModuleValues) {
         $backendModule = $this->buildBackendModule($backendModuleValues);
         $extension->addBackendModule($backendModule);
     }
     // classes
     if (is_array($extensionBuildConfiguration['modules'])) {
         foreach ($extensionBuildConfiguration['modules'] as $singleModule) {
             $domainObject = $this->objectSchemaBuilder->build($singleModule['value']);
             if ($domainObject->isSubClass() && !$domainObject->isMappedToExistingTable()) {
                 // we try to get the table from Extbase configuration
                 $classSettings = $this->configurationManager->getExtbaseClassConfiguration($domainObject->getParentClass());
                 //t3lib_div::devlog('!isMappedToExistingTable:' . strtolower($domainObject->getParentClass()), 'extension_builder', 0, $classSettings);
                 if (isset($classSettings['tableName'])) {
                     $tableName = $classSettings['tableName'];
                 } else {
                     // we use the default table name
                     $tableName = strtolower($domainObject->getParentClass());
                 }
                 if (!isset($GLOBALS['TCA'][$tableName])) {
                     throw new Exception('Table definitions for table ' . $tableName . ' could not be loaded. You can only map to tables with existing TCA or extend classes of installed extensions!');
                 }
                 $domainObject->setMapToTable($tableName);
             }
             $extension->addDomainObject($domainObject);
         }
         $classHierarchy = $extension->getClassHierarchy();
         foreach ($extension->getDomainObjects() as $domainObject) {
             if (isset($classHierarchy[$domainObject->getClassName()])) {
                 foreach ($classHierarchy[$domainObject->getClassName()] as $directChild) {
                     $domainObject->addChildObject($directChild);
                 }
             }
         }
     }
     // relations
     if (is_array($extensionBuildConfiguration['wires'])) {
         $this->setExtensionRelations($extensionBuildConfiguration, $extension);
     }
     return $extension;
 }
 /**
  *
  * @param array $jsonDomainObject
  * @return Tx_ExtensionBuilder_Domain_Model_DomainObject $domainObject
  */
 public function build(array $jsonDomainObject)
 {
     //t3lib_div::devlog('Building domain object '.$jsonDomainObject['name'],'extension_builder',0,$jsonDomainObject);
     $domainObject = t3lib_div::makeInstance('Tx_ExtensionBuilder_Domain_Model_DomainObject');
     $domainObject->setUniqueIdentifier($jsonDomainObject['objectsettings']['uid']);
     $domainObject->setName($jsonDomainObject['name']);
     $domainObject->setDescription($jsonDomainObject['objectsettings']['description']);
     if ($jsonDomainObject['objectsettings']['type'] === 'Entity') {
         $domainObject->setEntity(TRUE);
     } else {
         $domainObject->setEntity(FALSE);
     }
     $domainObject->setAggregateRoot($jsonDomainObject['objectsettings']['aggregateRoot']);
     $domainObject->setSorting($jsonDomainObject['objectsettings']['sorting']);
     // extended settings
     if (!empty($jsonDomainObject['objectsettings']['mapToTable'])) {
         $domainObject->setMapToTable($jsonDomainObject['objectsettings']['mapToTable']);
     }
     if (!empty($jsonDomainObject['objectsettings']['parentClass'])) {
         $domainObject->setParentClass($jsonDomainObject['objectsettings']['parentClass']);
     }
     // properties
     foreach ($jsonDomainObject['propertyGroup']['properties'] as $jsonProperty) {
         $propertyType = $jsonProperty['propertyType'];
         $propertyClassName = 'Tx_ExtensionBuilder_Domain_Model_DomainObject_' . $propertyType . 'Property';
         if (!class_exists($propertyClassName)) {
             t3lib_div::devlog('Property of type ' . $propertyType . ' not found', 'extension_builder', 2, $jsonProperty);
             throw new Exception('Property of type ' . $propertyType . ' not found');
         }
         $property = t3lib_div::makeInstance($propertyClassName);
         $property->setUniqueIdentifier($jsonProperty['uid']);
         $property->setName($jsonProperty['propertyName']);
         $property->setDescription($jsonProperty['propertyDescription']);
         if (isset($jsonProperty['propertyIsRequired'])) {
             $property->setRequired($jsonProperty['propertyIsRequired']);
         }
         if (isset($jsonProperty['propertyIsExcludeField'])) {
             $property->setExcludeField($jsonProperty['propertyIsExcludeField']);
         }
         //t3lib_div::devlog('Adding property ' . $jsonProperty['propertyName'] . ' to domain object '.$jsonDomainObject['name'],'extension_builder',0,$jsonDomainObject);
         $domainObject->addProperty($property);
     }
     $relatedForeignTables = array();
     foreach ($jsonDomainObject['relationGroup']['relations'] as $jsonRelation) {
         $relation = self::buildRelation($jsonRelation);
         if (!empty($jsonRelation['foreignRelationClass'])) {
             // relations without wires
             $relation->setForeignClassName($jsonRelation['foreignRelationClass']);
             $relation->setRelatedToExternalModel(TRUE);
             $extbaseClassConfiguration = $this->configurationManager->getExtbaseClassConfiguration($jsonRelation['foreignRelationClass']);
             if (isset($extbaseClassConfiguration['tableName'])) {
                 $foreignDatabaseTableName = $extbaseClassConfiguration['tableName'];
             } else {
                 $foreignDatabaseTableName = strtolower($jsonRelation['foreignRelationClass']);
             }
             $relation->setForeignDatabaseTableName($foreignDatabaseTableName);
             if (is_a($relation, Tx_ExtensionBuilder_Domain_Model_DomainObject_Relation_ZeroToManyRelation)) {
                 $foreignKeyName = strtolower($domainObject->getName());
                 if (isset($relatedForeignTables[$foreignDatabaseTableName])) {
                     $foreignKeyName .= $relatedForeignTables[$foreignDatabaseTableName];
                     $relatedForeignTables[$foreignDatabaseTableName] += 1;
                 } else {
                     $relatedForeignTables[$foreignDatabaseTableName] = 1;
                 }
                 $relation->setForeignKeyName($foreignKeyName);
             }
         }
         //t3lib_div::devlog('Adding relation ' . $jsonRelation['relationName'] . ' to domain object '.$jsonDomainObject['name'],'extension_builder',0,$jsonRelation);
         $domainObject->addProperty($relation);
     }
     //actions
     foreach ($jsonDomainObject['actionGroup'] as $jsonActionName => $actionValue) {
         if ($jsonActionName == 'customActions' && !empty($actionValue)) {
             $actionNames = $actionValue;
         } else {
             if ($actionValue == 1) {
                 $jsonActionName = preg_replace('/^_default[0-9]_*/', '', $jsonActionName);
                 if ($jsonActionName == 'edit_update' || $jsonActionName == 'new_create') {
                     $actionNames = explode('_', $jsonActionName);
                 } else {
                     $actionNames = array($jsonActionName);
                 }
             } else {
                 $actionNames = array();
             }
         }
         if (!empty($actionNames)) {
             foreach ($actionNames as $actionName) {
                 $action = t3lib_div::makeInstance('Tx_ExtensionBuilder_Domain_Model_DomainObject_Action');
                 $action->setName($actionName);
                 $domainObject->addAction($action);
             }
         }
     }
     return $domainObject;
 }