/** * changeTemplate * @param integer $intNewTemplateId * @author Thomas Schedler <*****@*****.**> * @version 1.0 */ public function changeTemplate($intNewTemplateId) { $this->core->logger->debug('massiveart->generic->data->GenericData->changeTemplate(' . $intNewTemplateId . ')'); try { $objTemplateData = $this->getModelTemplates()->loadTemplateById($intNewTemplateId); if (count($objTemplateData) == 1) { $objTemplate = $objTemplateData->current(); /** * set form id from template */ $strNewFormId = $objTemplate->genericFormId; $intNewFormVersion = $objTemplate->version; $intNewFormTypeId = $objTemplate->formTypeId; } else { throw new Exception('Not able to change template, because there is no new form id!'); } /** * check, if the new and the old form type are the same */ if ($intNewFormTypeId != $this->setup->getFormTypeId()) { throw new Exception('Not able to change template, because there are different form types!'); } /** * load the "old" generic data */ $this->initDataTypeObject(); $this->setup->loadGenericForm(); $this->setup->loadGenericFormStructure(); $this->objDataType->load(); /** * check, if the new template is based on another form */ if ($strNewFormId != $this->setup->getFormId() || $intNewFormVersion != $this->setup->getFormVersion()) { /** * clone the old generic setup object and change some properties */ $objNewGenericSetup = clone $this->setup; $objNewGenericSetup->setFormId($strNewFormId); $objNewGenericSetup->setFormVersion($intNewFormVersion); $objNewGenericSetup->setFormTypeId($intNewFormTypeId); $objNewGenericSetup->setTemplateId($intNewTemplateId); $objNewGenericSetup->setActionType($this->core->sysConfig->generic->actions->change_template); $objNewGenericSetup->loadGenericForm(); $objNewGenericSetup->resetGenericStructure(); $objNewGenericSetup->loadGenericFormStructure(); /** * get new data object */ $objNewDataType = GenericSetup::getDataTypeObject($objNewGenericSetup->getFormTypeId()); $objNewDataType->setGenericSetup($objNewGenericSetup); $objNewDataType->load(); /** * now compare values of the fields */ $this->compareGenericFieldValues($objNewGenericSetup); $objNewDataType->save(); $this->setup = $objNewGenericSetup; } else { $this->setup->setActionType($this->core->sysConfig->generic->actions->change_template_id); $this->setup->setTemplateId($intNewTemplateId); $this->setup->resetGenericStructure(); $this->setup->loadGenericFormStructure(); $this->objDataType->load(); $this->objDataType->save(); } } catch (Exception $exc) { $this->core->logger->err($exc); } }