public function save($data)
 {
     $transaction = $this->beginTransaction();
     try {
         if ($this->isPersistent()) {
             $this->setActive(true);
         } else {
             $schema = new Construction($data->idConstruction);
             $entity = new Entity();
             $entity->setAlias($this->getEntry());
             $entity->setType('CE');
             $entity->save();
             $entry = new Entry();
             $entry->newEntry($this->getEntry());
             Base::createEntityRelation($entity->getId(), 'rel_elementof', $schema->getIdEntity());
             $this->setIdEntity($entity->getId());
             $this->setActive(true);
         }
         parent::save();
         $transaction->commit();
     } catch (\Exception $e) {
         $transaction->rollback();
         throw new \Exception($e->getMessage());
     }
 }
 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 newLU()
 {
     try {
         $lu = new LU();
         $this->data->lu->idLemma = $this->data->gridSearchLemma->data->checked[0];
         $this->data->lu->active = '1';
         $this->data->lu->name = $this->data->lemma;
         $lu->save($this->data->lu);
         $frame = Frame::create($this->data->lu->idFrame);
         Base::createEntityRelation($lu->getIdEntity(), 'rel_evokes', $frame->getIdEntity());
         $this->renderPrompt('information', 'OK', "!\$('#formNewLU_dialog').dialog('close'); structure.reloadFrame()");
     } catch (\Exception $e) {
         $this->renderPrompt('error', $e->getMessage());
     }
 }
 public function createNew($data, $inheritsFromBase)
 {
     $relations = $this->getRelations(true);
     $transaction = $this->beginTransaction();
     try {
         $this->save($data);
         if ($data->idTemplate) {
             if ($inheritsFromBase) {
                 $template = new Template($data->idTemplate);
                 $base = $template->getBaseFrame()->asQuery()->getResult();
                 if (count($base)) {
                     $idFrameBase = $base[0]['idFrame'];
                     $frameBase = new Frame($idFrameBase);
                     $relations = $frameBase->getRelations();
                     Base::createEntityRelation($frameBase->getIdEntity(), 'rel_inheritance', $this->getIdEntity());
                 }
             }
         }
         $transaction->commit();
         return $relations;
     } catch (\Exception $e) {
         $transaction->rollback();
         throw new \Exception($e->getMessage());
     }
 }
 public function addEntity($idEntity)
 {
     Base::createEntityRelation($idEntity, 'rel_hassemtype', $this->getIdEntity());
 }
 public function addManualSubCorpusCxn($data)
 {
     $transaction = $this->beginTransaction();
     try {
         $entity = Base::createEntity('SC', 'sco_manually-added');
         $this->setName('manually-added');
         $this->setRank(0);
         $this->setIdEntity($entity->getId());
         $this->save();
         $cxn = Construction::create($data->idConstruction);
         Base::createEntityRelation($cxn->getIdEntity(), 'rel_hassubcorpus', $this->getIdEntity());
         $annotationSet = new AnnotationSet();
         $annotationSet->setIdSubCorpus($this->getId());
         $annotationSet->setIdSentence($data->idSentence);
         $annotationSet->setIdAnnotationStatus('ast_manual');
         $annotationSet->save();
         $annotationSet->createLayersForCxn($cxn, $data);
         $transaction->commit();
     } catch (\Exception $ex) {
         $transaction->rollback();
         throw new \Exception($ex->getMessage());
     }
 }
 public function createRelationsFromData($fe)
 {
     if ($fe->idFrame) {
         $frame = new Frame($fe->idFrame);
         Base::createEntityRelation($this->getIdEntity(), 'rel_elementof', $frame->getIdEntity());
     }
     $feRelated = new FrameElement();
     if ($fe->coreset) {
         foreach ($fe->coreset as $coreset) {
             $feRelated->getByEntry($coreset->entry);
             Base::createEntityRelation($this->getIdEntity(), 'rel_coreset', $feRelated->getIdEntity());
         }
     }
     if ($fe->excludes) {
         foreach ($fe->excludes as $excludes) {
             $feRelated->getByEntry($excludes->entry);
             Base::createEntityRelation($this->getIdEntity(), 'rel_excludes', $feRelated->getIdEntity());
         }
     }
     if ($fe->requires) {
         foreach ($fe->requires as $requires) {
             $feRelated->getByEntry($requires->entry);
             Base::createEntityRelation($this->getIdEntity(), 'rel_requires', $feRelated->getIdEntity());
         }
     }
 }