public static function addCIRValidations(TableMap $map, array $columns = null)
 {
     $foreigns = $map->getForeignKeys();
     foreach ($foreigns as $currentForeign) {
         $columnName = $currentForeign->getColumnName();
         if (!isset($columns) || array_key_exists($columnName, $columns)) {
             if (isset($columns)) {
                 $message = $columns[$columnName];
                 CIRPeerUtils::addCIRValidation($map, $currentForeign, $message);
             } else {
                 CIRPeerUtils::addCIRValidation($map, $currentForeign);
             }
         }
     }
 }
Esempio n. 2
0
 /**
  * @param string $class
  * @param string $property
  * @param array $choices
  * @param \ModelCriteria $queryObject
  */
 public function __construct($class, $property = null, $choices = array(), $queryObject = null)
 {
     $this->class = $class;
     $queryClass = $this->class . 'Query';
     $query = new $queryClass();
     $this->table = $query->getTableMap();
     $this->identifier = $this->table->getPrimaryKeys();
     $this->query = $queryObject ?: $query;
     // The property option defines, which property (path) is used for
     // displaying models as strings
     if ($property) {
         $this->propertyPath = new PropertyPath($property);
     }
     parent::__construct($choices);
 }
Esempio n. 3
0
 /**
  * Method from the TableMap API
  */
 public function getRelations()
 {
     // table maps
     $authorTable = new \TableMap();
     $authorTable->setClassName('\\Foo\\Author');
     $resellerTable = new \TableMap();
     $resellerTable->setClassName('\\Foo\\Reseller');
     // relations
     $mainAuthorRelation = new \RelationMap('MainAuthor');
     $mainAuthorRelation->setType(\RelationMap::MANY_TO_ONE);
     $mainAuthorRelation->setForeignTable($authorTable);
     $authorRelation = new \RelationMap('Author');
     $authorRelation->setType(\RelationMap::ONE_TO_MANY);
     $authorRelation->setForeignTable($authorTable);
     $resellerRelation = new \RelationMap('Reseller');
     $resellerRelation->setType(\RelationMap::MANY_TO_MANY);
     $resellerRelation->setLocalTable($resellerTable);
     return array($mainAuthorRelation, $authorRelation, $resellerRelation);
 }
 public function testColumns()
 {
     $this->assertEquals(array(), $this->rmap->getLocalColumns(), 'A new relation has no local columns');
     $this->assertEquals(array(), $this->rmap->getForeignColumns(), 'A new relation has no foreign columns');
     $tmap1 = new TableMap('foo', $this->databaseMap);
     $col1 = $tmap1->addColumn('FOO1', 'Foo1PhpName', 'INTEGER');
     $tmap2 = new TableMap('bar', $this->databaseMap);
     $col2 = $tmap2->addColumn('BAR1', 'Bar1PhpName', 'INTEGER');
     $this->rmap->addColumnMapping($col1, $col2);
     $this->assertEquals(array($col1), $this->rmap->getLocalColumns(), 'addColumnMapping() adds a local table');
     $this->assertEquals(array($col2), $this->rmap->getForeignColumns(), 'addColumnMapping() adds a foreign table');
     $expected = array('foo.FOO1' => 'bar.BAR1');
     $this->assertEquals($expected, $this->rmap->getColumnMappings(), 'getColumnMappings() returns an associative array of column mappings');
     $col3 = $tmap1->addColumn('FOOFOO', 'FooFooPhpName', 'INTEGER');
     $col4 = $tmap2->addColumn('BARBAR', 'BarBarPhpName', 'INTEGER');
     $this->rmap->addColumnMapping($col3, $col4);
     $this->assertEquals(array($col1, $col3), $this->rmap->getLocalColumns(), 'addColumnMapping() adds a local table');
     $this->assertEquals(array($col2, $col4), $this->rmap->getForeignColumns(), 'addColumnMapping() adds a foreign table');
     $expected = array('foo.FOO1' => 'bar.BAR1', 'foo.FOOFOO' => 'bar.BARBAR');
     $this->assertEquals($expected, $this->rmap->getColumnMappings(), 'getColumnMappings() returns an associative array of column mappings');
 }
Esempio n. 5
0
File: Helper.php Progetto: dafik/dfi
 public static function findAutoLabel(TableMap $map)
 {
     if (count(self::$scores) == 0) {
         self::$scores = array('VARCHAR' => 6, 'LONGVARCHAR' => 5, 'ENUM' => 4, 'CHAR' => 4, 'DATE' => 3, 'DATETIME' => 3, 'TIMESTAMP' => 3, 'TIME' => 3, 'YEAR' => 3, 'TEXT' => 2, 'BLOB' => 2, 'CLOB' => 2, 'TINYBLOB' => 2, 'TINYTEXT' => 2, 'MEDIUMBLOB' => 2, 'MEDIUMTEXT' => 2, 'LONGTEXT' => 2, 'BOOLEAN' => 1, 'INT' => 1, 'INTEGER' => 1, 'TINYINT' => 1, 'SMALLINT' => 1, 'MEDIUMINT' => 1, 'BIGINT' => 1, 'FLOAT' => 1, 'DOUBLE' => 1, 'DECIMAL' => 1);
     }
     /** @var $column ColumnMap */
     $scoreTable = array();
     foreach ($map->getColumns() as $column) {
         if (isset(self::$scores[$column->getType()])) {
             $score = self::$scores[$column->getType()];
         } else {
             //todo $x = 'tablenotfound';
             $score = 0;
         }
         if (!isset($scoreTable[$score])) {
             $scoreTable[$score] = $column;
         }
     }
     $key = max(array_keys($scoreTable));
     $map->autoLabel = $scoreTable[$key];
 }
Esempio n. 6
0
 /**
  * Get row properties.
  *
  * @param BaseObject $obj
  * @return array
  */
 protected function getRow($obj)
 {
     $columnToPhpName = array();
     foreach ($this->tableMap->getColumns() as $name => $column) {
         $columnToPhpName[strtolower($name)] = $column->getPhpName();
     }
     $celldata = array();
     foreach ($this->columns as $column => $opts) {
         if (isset($this->callbacks[$column])) {
             $value = call_user_func($this->callbacks[$column], $obj);
         } else {
             try {
                 if (isset($columnToPhpName[$column])) {
                     $phpName = $columnToPhpName[$column];
                 } else {
                     $tmp = $this->query->getAsColumns();
                     if (isset($tmp[$column])) {
                         $phpName = $column;
                     }
                 }
                 $value = $obj->{'get' . $phpName}();
             } catch (Exception $e) {
                 throw new Exception("Unable to fetch value from column '{$column}'.");
             }
         }
         if (is_null($value)) {
             $value = 'Ø';
         } else {
             if (is_bool($value)) {
                 $value = $value ? 'true' : 'false';
             } else {
                 if (is_array($value)) {
                     $value = join(', ', $value);
                 }
             }
         }
         $escape = !isset($opts['escape']) ? true : (bool) $opts['escape'];
         $value = str_replace(PHP_EOL, "", $value);
         $celldata[] = $escape ? htmlspecialchars($value) : $value;
     }
     return array("id" => "_" . $obj->getPrimaryKey(), "cell" => $celldata);
 }
 public function testGetTableByPhpName()
 {
     try {
         $this->databaseMap->getTableByPhpName('Foo1');
         $this->fail('getTableByPhpName() throws an exception when called on an inexistent table');
     } catch (PropelException $e) {
         $this->assertTrue(true, 'getTableByPhpName() throws an exception when called on an inexistent table');
     }
     $tmap = $this->databaseMap->addTable('foo1');
     try {
         $this->databaseMap->getTableByPhpName('Foo1');
         $this->fail('getTableByPhpName() throws an exception when called on a table with no phpName');
     } catch (PropelException $e) {
         $this->assertTrue(true, 'getTableByPhpName() throws an exception when called on a table with no phpName');
     }
     $tmap2 = new TableMap('foo2');
     $tmap2->setPhpName('Foo2');
     $this->databaseMap->addTableObject($tmap2);
     $this->assertEquals($tmap2, $this->databaseMap->getTableByPhpName('Foo2'), 'getTableByPhpName() returns tableMap when phpName was set by way of TableMap::setPhpName()');
 }
 /**
  * @dataProvider phpNameData
  */
 public function testGetTableByPhpNameNamespaced($name, $phpName, $classname)
 {
     try {
         $this->databaseMap->getTableByPhpName($classname);
         $this->fail('getTableByPhpName() throws an exception when called on an inexistent table');
     } catch (PropelException $e) {
         $this->assertTrue(true, 'getTableByPhpName() throws an exception when called on an inexistent table');
     }
     $tmap2 = new TableMap($name);
     $tmap2->setPhpName($phpName);
     $tmap2->setClassname($classname);
     $this->databaseMap->addTableObject($tmap2);
     $this->assertEquals($tmap2, $this->databaseMap->getTableByPhpName($classname), 'getTableByPhpName() returns tableMap when phpName was set by way of TableMap::setPhpName()');
 }
 public function validFieldNameProvider()
 {
     $className = '\\Foo\\Book';
     $options = array('foo' => 'bar');
     // table maps
     $emptyTableMap = new \TableMap();
     $authorTable = new \TableMap();
     $authorTable->setClassName('\\Foo\\Author');
     $resellerTable = new \TableMap();
     $resellerTable->setClassName('\\Foo\\Reseller');
     $relationsTableMap = $this->getMock('\\TableMap');
     // relations
     $mainAuthorRelation = new \RelationMap('MainAuthor');
     $mainAuthorRelation->setType(\RelationMap::MANY_TO_ONE);
     $mainAuthorRelation->setForeignTable($authorTable);
     $authorRelation = new \RelationMap('Author');
     $authorRelation->setType(\RelationMap::ONE_TO_MANY);
     $authorRelation->setForeignTable($authorTable);
     $resellerRelation = new \RelationMap('Reseller');
     $resellerRelation->setType(\RelationMap::MANY_TO_MANY);
     $resellerRelation->setLocalTable($resellerTable);
     // configure table maps mocks
     $relationsTableMap->expects($this->any())->method('getRelations')->will($this->returnValue(array($mainAuthorRelation, $authorRelation, $resellerRelation)));
     // columns
     $titleColumn = new \ColumnMap('Title', $emptyTableMap);
     $titleColumn->setType('text');
     $titleColumn->setPhpName('Title');
     $titleFieldMapping = array('id' => false, 'type' => 'text', 'fieldName' => 'Title');
     return array(array(null, array(), $className, 'Title', $options, array('type' => null, 'association_mapping' => null, 'field_mapping' => null)), array($emptyTableMap, array(), $className, 'Title', $options, array('type' => null, 'association_mapping' => null, 'field_mapping' => null)), array($emptyTableMap, array($titleColumn), $className, 'Title', $options, array('type' => 'text', 'association_mapping' => null, 'field_mapping' => $titleFieldMapping)), array($relationsTableMap, array($titleColumn), $className, 'MainAuthor', $options, array('type' => \RelationMap::MANY_TO_ONE, 'association_mapping' => array('targetEntity' => '\\Foo\\Author', 'type' => \RelationMap::MANY_TO_ONE), 'field_mapping' => null)), array($relationsTableMap, array($titleColumn), $className, 'Authors', $options, array('type' => \RelationMap::ONE_TO_MANY, 'association_mapping' => array('targetEntity' => '\\Foo\\Author', 'type' => \RelationMap::ONE_TO_MANY), 'field_mapping' => null)), array($relationsTableMap, array($titleColumn), $className, 'Resellers', $options, array('type' => \RelationMap::MANY_TO_MANY, 'association_mapping' => array('targetEntity' => '\\Foo\\Reseller', 'type' => \RelationMap::MANY_TO_MANY), 'field_mapping' => null)));
 }
Esempio n. 10
0
 /**
  * Return the specified behavior properties
  * 
  * @param string $behavior
  * @param TableMap $tableMap
  * @return array
  */
 public static function getBehavior($behavior, TableMap $tableMap)
 {
     $behaviors = $tableMap->getBehaviors();
     return (array) $behaviors[strtolower($behavior)];
 }
Esempio n. 11
0
 /**
  * Create field from relation.
  *
  * @param $name
  */
 public function withRelation($name)
 {
     $this->createFieldFromRelation($this->modelMap->getRelation($name));
 }
Esempio n. 12
0
 protected function getI18nTableName(\TableMap $tableMap)
 {
     $behaviors = $tableMap->getBehaviors();
     if (!array_key_exists('i18n', $behaviors)) {
         return null;
     }
     return str_replace('%PHPNAME%', $tableMap->getPhpName(), $behaviors['i18n']['i18n_phpname']);
 }
Esempio n. 13
0
 /**
  * Create element from relation.
  *
  * @param $name
  */
 public function withRelation($name)
 {
     $this->addElement($this->createElementFromRelation($this->modelMap->getRelation($name)));
 }
Esempio n. 14
0
 /**
  * Add a new table object to the database.
  *
  * @param      TableMap $table The table to add
  */
 public function addTableObject(TableMap $table)
 {
     $table->setDatabaseMap($this);
     $this->tables[$table->getName()] = $table;
     $this->tablesByPhpName[$table->getClassname()] = $table;
 }
Esempio n. 15
0
 public function testAddRelation()
 {
     $foreigntmap1 = new TableMap('bar');
     $foreigntmap1->setClassname('Bar');
     $this->databaseMap->addTableObject($foreigntmap1);
     $foreigntmap2 = new TableMap('baz');
     $foreigntmap2->setClassname('Baz');
     $this->databaseMap->addTableObject($foreigntmap2);
     $this->rmap1 = $this->tmap->addRelation('Bar', 'Bar', RelationMap::MANY_TO_ONE);
     $this->rmap2 = $this->tmap->addRelation('Bazz', 'Baz', RelationMap::ONE_TO_MANY);
     $this->tmap->getRelations();
     // now on to the test
     $this->assertEquals($this->rmap1->getLocalTable(), $this->tmap, 'adding a relation with HAS_ONE sets the local table to the current table');
     $this->assertEquals($this->rmap1->getForeignTable(), $foreigntmap1, 'adding a relation with HAS_ONE sets the foreign table according to the name given');
     $this->assertEquals(RelationMap::MANY_TO_ONE, $this->rmap1->getType(), 'adding a relation with HAS_ONE sets the foreign table type accordingly');
     $this->assertEquals($this->rmap2->getForeignTable(), $this->tmap, 'adding a relation with HAS_MANY sets the foreign table to the current table');
     $this->assertEquals($this->rmap2->getLocalTable(), $foreigntmap2, 'adding a relation with HAS_MANY sets the local table according to the name given');
     $this->assertEquals(RelationMap::ONE_TO_MANY, $this->rmap2->getType(), 'adding a relation with HAS_MANY sets the foreign table type accordingly');
     $expectedRelations = array('Bar' => $this->rmap1, 'Bazz' => $this->rmap2);
     $this->assertEquals($expectedRelations, $this->tmap->getRelations(), 'getRelations() returns an associative array of all the relations');
 }
 public function normalizeColName($name)
 {
     return parent::normalizeColName($name);
 }
Esempio n. 17
0
 protected function getHashableColumns(MeshingBaseObject $object, TableMap $tableMap)
 {
     return $tableMap->getColumns();
 }