示例#1
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);
 }
示例#2
0
 /**
  * @covers QueryBuilder::buildRelationQuery
  * @todo   Implement testBuildRelationQuery().
  */
 public function testBuildRelationQuery()
 {
     $ovni = new Ovni();
     $ovni->setId(1);
     $ovni->setName("martian");
     $weapon1 = new Weapon(1, "lazer");
     $weapon2 = new Weapon(2, "rifle");
     $ovni->addWeapon($weapon1);
     $ovni->addWeapon($weapon2);
     $rel = new Relation();
     $rel->setCardinality("many-to-many");
     $rel->setEntity("weapon");
     $rel->setForeignColumn("id_weapon");
     $rel->setLocalColumn("id_ovni");
     $rel->setName("Weapons");
     $rel->setTable("ovni_weapon");
     $expected = "INSERT INTO ovni_weapon (id_ovni, id_weapon) VALUES (:id_ovni, :id_weapon);";
     $buildedQuery = $this->object->getRelationQuery($ovni, $rel);
     $this->assertEquals($expected, $buildedQuery);
 }