public function createFromFrame($idFrame) { $transaction = $this->beginTransaction(); try { $frame = new Frame($idFrame); $this->setEntry('tpl_' . strtolower(str_replace('frm_', '', $frame->getEntry()))); $this->save(); Base::createEntityRelation($this->getIdEntity(), 'rel_createdfrom', $frame->getIdEntity()); $fes = $frame->listFE()->asQuery()->asObjectArray(); $fe = new FrameElement(); foreach ($fes as $feData) { $fe->setPersistent(false); $feEntry = $this->getEntry() . '_' . $feData->entry; $entry = new Entry(); $entry->cloneEntry($feData->entry, $feEntry); $fe->setEntry($feData->entry); $entity = new Entity(); $entity->setAlias($feEntry); $entity->setType('FE'); $entity->save(); Base::createEntityRelation($entity->getId(), 'rel_elementof', $this->getIdEntity()); $coreType = new TypeInstance($feData->idCoreType); Base::createEntityRelation($entity->getId(), 'rel_hastype', $coreType->getIdEntity()); $fe->setIdEntity($entity->getId()); $fe->setActive(true); $fe->setIdColor($feData->idColor); $fe->saveModel(); } $transaction->commit(); } catch (\Exception $e) { $transaction->rollback(); throw new \Exception($e->getMessage()); } }
public function registerTemplate($idTemplate) { $template = new Template($idTemplate); $fes = $template->listFEforNewFrame()->asQuery()->getResult(); Base::createEntityRelation($this->getIdEntity(), 'rel_hastemplate', $template->getIdEntity()); $frameElement = new FrameElement(); foreach ($fes as $fe) { $newFE = new \StdClass(); $newFE->entry = $this->getEntry() . '_' . $fe['entry'] . '_' . $template->getEntry(); $newFE->idCoreType = $fe['idCoreType']; $newFE->idColor = $fe['idColor']; $newFE->idEntity = $fe['idEntity']; $newFE->idFrame = $this->getId(); $frameElement->setPersistent(false); $frameElement->setData($newFE); $frameElement->save($newFE); Base::createEntityRelation($frameElement->getIdEntity(), 'rel_hastemplate', $newFE->idEntity); } }