Beispiel #1
0
 /**
  * Return the insert relation query.
  * @param type $entity
  * @param Relation $relation
  * @return string $query.
  */
 public static function buildRelationQuery($entity, Relation $relation)
 {
     $relQuery = "";
     $getid = "getId";
     if ($relation->getCardinality() == Relation::$manyToMany) {
         $m = "get" . $relation->getName();
         $relQuery .= "INSERT INTO " . $relation->getTable() . " (" . $relation->getLocalColumn() . ", " . $relation->getForeignColumn() . ") ";
         $relQuery .= "VALUES (:" . $relation->getLocalColumn() . ", :" . $relation->getForeignColumn() . ");";
     }
     if ($relation->getCardinality() == Relation::$oneToMany) {
         $relMapper = MapperBuilder::buildFromName($this->mapping, $relation->getEntity());
         $m = "get" . $relation->getName();
         foreach ($entity->{$m}() as $rel) {
             $setid = "set" . $relMapper->getNameForColumn($relation->getForeignColumn());
             $rel->{$setid}($entity->{$getid}());
             $relQuery .= $this->buildInsertQuery($rel);
         }
     }
     return $relQuery;
 }
Beispiel #2
0
 public static function populateInstance(Mapper $instance, $mappedEntity)
 {
     $class = $mappedEntity->attributes()->class;
     $instance->setTable($mappedEntity->attributes()->table->__toString());
     $instance->setClass($class->__toString());
     // propertys
     $props = $mappedEntity->property;
     $propertys = array();
     foreach ($props as $property) {
         $name = $property->attributes()->name->__toString();
         $column = $property->attributes()->column ? $property->attributes()->column->__toString() : null;
         $type = $property->attributes()->type ? $property->attributes()->type->__toString() : null;
         $propertys[$name] = new Property($name, $column, $type);
     }
     $instance->setPropertys($propertys);
     // relations
     $rels = $mappedEntity->relation;
     $relations = array();
     foreach ($rels as $relation) {
         $relInstance = new Relation();
         $relInstance->setCardinality($relation->attributes()->cardinality->__toString());
         $relInstance->setEntity($relation->attributes()->entity->__toString());
         $relInstance->setName($relation->attributes()->name->__toString());
         $relInstance->setTable($relation->attributes()->table->__toString());
         if (is_object($relation->attributes()->lazy)) {
             $relInstance->setLazy($relation->attributes()->lazy->__toString());
         }
         $relInstance->setLocalColumn($relation->attributes()->localColumn->__toString());
         $relInstance->setForeignColumn($relation->attributes()->foreignColumn->__toString());
         $relations[$relInstance->getName()] = $relInstance;
     }
     $instance->setRelations($relations);
     // filters
     $fils = $mappedEntity->filter;
     $filters = array();
     foreach ($fils as $filter) {
         $filInstance = new Filter();
         $filInstance->setName($filter->attributes()->name->__toString());
         $filInstance->setItemsPerPage($filter->attributes()->perPage->__toString());
         $filteredColumns = $filter->attributes()->columns->__toString();
         $columList = explode(",", $filteredColumns);
         foreach ($columList as $columnName) {
             $filInstance->addFilteredColumn($columnName);
         }
         $filters[$filInstance->getName()] = $filInstance;
     }
     $instance->setFilters($filters);
 }