public function createAnnotationFullText($data) { $annotationSet = new AnnotationSet(); $annotationSet->setIdSubCorpus($data->idSubCorpus); $annotationSet->setIdSentence($data->idSentence); $annotationSet->setIdAnnotationStatus('ast_manual'); $annotationSet->save(); }
protected static function cacheEntityClass($classname, $reflection_classname = null) { $rc_name = $reflection_classname !== null ? $reflection_classname : $classname; try { $reflection = new \ReflectionClass($rc_name); $annotationset = new AnnotationSet($reflection->getDocComment()); if (!$annotationset->hasAnnotations()) { throw new Exception('Empty annotationset!'); } } catch (\Exception $e) { throw new Exception("An error occured when trying to load the database details for class {$classname}: " . $e->getMessage()); } if ($reflection_classname === null) { self::$_cached_entity_classes[$classname] = array('columns' => array(), 'relations' => array(), 'foreign_columns' => array()); if (!($annotation = $annotationset->getAnnotation('Table'))) { throw new Exception("The class '{$classname}' is missing a valid @Table annotation"); } else { $tablename = $annotation->getProperty('name'); } if (!\class_exists($tablename)) { throw new Exception("The class table class '{$tablename}' for class '{$classname}' does not exist"); } self::$_cached_entity_classes[$classname]['table'] = $tablename; self::_populateCachedTableClassFiles($tablename); if (($re = $reflection->getExtension()) && ($classnames = $re->getClassNames())) { foreach ($classnames as $extends_classname) { self::cacheEntityClass($classname, $extends_classname); } } } if (!\array_key_exists('name', self::$_cached_table_classes[self::$_cached_entity_classes[$classname]['table']])) { throw new Exception("The class @Table annotation in '" . self::$_cached_entity_classes[$classname]['table'] . "' is missing required 'name' property"); } $column_prefix = self::$_cached_table_classes[self::$_cached_entity_classes[$classname]['table']]['name'] . '.'; foreach ($reflection->getProperties() as $property) { if ($property instanceof \ReflectionProperty) { } $annotationset = new AnnotationSet($property->getDocComment()); if ($annotationset->hasAnnotations()) { $property_name = $property->getName(); if ($column_annotation = $annotationset->getAnnotation('Column')) { $column_name = $column_prefix . ($column_annotation->hasProperty('name') ? $column_annotation->getProperty('name') : substr($property_name, 1)); $column = array('property' => $property_name, 'default_value' => $column_annotation->hasProperty('default') ? $column_annotation->getProperty('default') : null, 'not_null' => $column_annotation->hasProperty('not_null') ? $column_annotation->getProperty('not_null') : false, 'name' => $column_name, 'type' => $column_annotation->getProperty('type')); switch ($column['type']) { case 'varchar': case 'string': $column['type'] = 'varchar'; $column['length'] = $column_annotation->hasProperty('length') ? $column_annotation->getProperty('length') : null; break; case 'float': $column['precision'] = $column_annotation->hasProperty('precision') ? $column_annotation->getProperty('precision') : 2; case 'integer': $column['auto_inc'] = $column_annotation->hasProperty('auto_increment') ? $column_annotation->getProperty('auto_increment') : false; $column['unsigned'] = $column_annotation->hasProperty('unsigned') ? $column_annotation->getProperty('unsigned') : false; $column['length'] = $column_annotation->hasProperty('length') ? $column_annotation->getProperty('length') : 10; if ($column['type'] != 'float') { $column['default_value'] = $column_annotation->hasProperty('default') ? $column_annotation->getProperty('default') : 0; } break; } self::$_cached_entity_classes[$classname]['columns'][$column_name] = $column; } if ($annotation = $annotationset->getAnnotation('Id')) { self::$_cached_entity_classes[$classname]['id_column'] = $column_name; } if ($annotation = $annotationset->getAnnotation('Relates')) { $value = $annotation->getProperty('class'); $collection = (bool) $annotation->getProperty('collection'); $manytomany = (bool) $annotation->getProperty('manytomany'); $joinclass = $annotation->getProperty('joinclass'); $foreign_column = $annotation->getProperty('foreign_column'); $orderby = $annotation->getProperty('orderby'); $f_column = $annotation->getProperty('column'); self::$_cached_entity_classes[$classname]['relations'][$property_name] = array('collection' => $collection, 'property' => $property_name, 'foreign_column' => $foreign_column, 'manytomany' => $manytomany, 'joinclass' => $joinclass, 'class' => $annotation->getProperty('class'), 'column' => $f_column, 'orderby' => $orderby); if (!$collection) { if (!$column_annotation) { throw new Exception("The property '{$property_name}' in class '{$classname}' is missing an @Column annotation, or is improperly marked as not being a collection"); } $column_name = $column_prefix . ($annotation->hasProperty('name') ? $annotation->getProperty('name') : substr($property_name, 1)); $column['class'] = self::getCachedB2DBTableClass($value); $column['key'] = $annotation->hasProperty('key') ? $annotation->getProperty('key') : null; self::$_cached_entity_classes[$classname]['foreign_columns'][$column_name] = $column; } } } } if (self::$_cache_enabled && !self::$_debug_mode) { $key = 'b2db_cache_' . $classname; \TBGCache::add($key, self::$_cached_entity_classes[$classname], false); \TBGCache::fileAdd($key, self::$_cached_entity_classes[$classname], false); } }
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()); } }