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); } }
public function save($data) { $transaction = $this->beginTransaction(); try { if ($this->isPersistent()) { $coreType = new TypeInstance($this->getIdCoreType()); Base::updateEntityRelation($this->getIdEntity(), 'rel_hastype', $coreType->getIdEntity()); $this->setActive(true); $criteria = $this->getCriteria()->select('fe1.idFrameElement'); Base::relation($criteria, 'frameelement fe1', 'frameelement fe2', 'rel_hastemplate'); $criteria->where("fe2.idEntity = {$this->getIdEntity()}"); $fes = $criteria->asQuery()->getResult(); foreach ($fes as $fe) { $feTemplated = new FrameElement($fe['idFrameElement']); $feTemplated->setIdColor($this->getIdColor()); $feTemplated->save(); } } else { if ($data->idFrame) { $schema = new Frame($data->idFrame); } else { if ($data->idTemplate) { $schema = new Template($data->idTemplate); } } $entity = new Entity(); $entity->setAlias($this->getEntry()); $entity->setType('FE'); $entity->save(); $entry = new Entry(); $entry->newEntry($this->getEntry()); Base::createEntityRelation($entity->getId(), 'rel_elementof', $schema->getIdEntity()); $coreType = new TypeInstance($data->idCoreType); Base::createEntityRelation($entity->getId(), 'rel_hastype', $coreType->getIdEntity()); $this->setIdEntity($entity->getId()); $this->setActive(true); } parent::save(); $transaction->commit(); } catch (\Exception $e) { $transaction->rollback(); throw new \Exception($e->getMessage()); } }