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 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());
     }
 }