Ejemplo n.º 1
0
 public function getPrimaryKeys()
 {
     $cm = new \ColumnMap('id', new \TableMap());
     $cm->setType('INTEGER');
     $cm->setPhpName('Id');
     return array('id' => $cm);
 }
 public static function addCIRValidation(TableMap $map, ColumnMap $column, $message = null)
 {
     $columnName = $column->getColumnName();
     $value = $column->getRelatedTableName();
     if (!isset($message)) {
         $message = $value . " non trouvé";
     }
     $map->addValidator($columnName, "class", "utils.CIRValidator", $value, $message);
 }
Ejemplo n.º 3
0
 /**
  * @see        DBAdapter::bindValue()
  */
 public function bindValue(PDOStatement $stmt, $parameter, $value, ColumnMap $cMap)
 {
     if ($cMap->isTemporal()) {
         $value = $this->formatTemporalValue($value, $cMap);
     } elseif (is_resource($value) && $cMap->isLob()) {
         // we always need to make sure that the stream is rewound, otherwise nothing will
         // get written to database.
         rewind($value);
         // pdo_sqlsrv must have bind binaries using bindParam so that the PDO::SQLSRV_ENCODING_BINARY
         // driver option can be utilized. This requires a unique blob parameter because the bindParam
         // value is passed by reference and if we didn't do this then the referenced parameter value
         // would change on the next loop
         $blob = "blob" . $position;
         ${$blob} = $value;
         return $stmt->bindParam($parameter, ${$blob}, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);
     }
     return $stmt->bindValue($parameter, $value, $cMap->getPdoType());
 }
Ejemplo n.º 4
0
 /**
  * Create a new instance.
  *
  * @param      Criteria $parent The outer class (this is an "inner" class).
  * @param      ColumnMap $column A Column object to help escaping the value
  * @param      mixed $value
  * @param      string $comparison, among ModelCriteria::MODEL_CLAUSE
  * @param      string $clause A simple pseudo-SQL clause, e.g. 'foo.BAR LIKE ?'
  */
 public function __construct(Criteria $outer, $column, $value = null, $comparison = ModelCriteria::MODEL_CLAUSE, $clause)
 {
     $this->value = $value;
     if ($column instanceof ColumnMap) {
         $this->column = $column->getName();
         $this->table = $column->getTable()->getName();
     } else {
         $dotPos = strrpos($column, '.');
         if ($dotPos === false) {
             // no dot => aliased column
             $this->table = null;
             $this->column = $column;
         } else {
             $this->table = substr($column, 0, $dotPos);
             $this->column = substr($column, $dotPos + 1, strlen($column));
         }
     }
     $this->comparison = $comparison === null ? Criteria::EQUAL : $comparison;
     $this->clause = $clause;
     $this->init($outer);
 }
Ejemplo n.º 5
0
 /**
  * Returns a PHP string representing options to pass to a validator for a given column.
  *
  * @param  ColumnMap $column  A ColumnMap object
  *
  * @return string    The options to pass to the validator as a PHP string
  */
 public function getValidatorOptionsForColumn(ColumnMap $column)
 {
     $options = array();
     if ($column->isForeignKey()) {
         $options[] = sprintf('\'model\' => \'%s\', \'column\' => \'%s\'', $this->getForeignTable($column)->getClassname(), $this->translateColumnName($column, true));
     } else {
         if ($column->isPrimaryKey()) {
             $options[] = sprintf('\'model\' => \'%s\', \'column\' => \'%s\'', $column->getTable()->getClassname(), $this->translateColumnName($column));
         } else {
             switch ($column->getType()) {
                 case PropelColumnTypes::CLOB:
                 case PropelColumnTypes::CHAR:
                 case PropelColumnTypes::VARCHAR:
                 case PropelColumnTypes::LONGVARCHAR:
                     if ($column->getSize()) {
                         $options[] = sprintf('\'max_length\' => %s', $column->getSize());
                     }
                     break;
             }
         }
     }
     if (!$column->isNotNull() || $column->isPrimaryKey()) {
         $options[] = '\'required\' => false';
     }
     return count($options) ? sprintf('array(%s)', implode(', ', $options)) : '';
 }
Ejemplo n.º 6
0
 public function testPrimaryStringAddConfiguredColumn()
 {
     $this->assertFalse($this->tmap->hasPrimaryStringColumn(), 'hasPrimaryStringColumn() returns false while none set.');
     $column = new ColumnMap('BAR', $this->tmap);
     $column->setPhpName('Bar');
     $column->setType('VARCHAR');
     $column->setPrimaryString(true);
     $this->tmap->addConfiguredColumn($column);
     $this->assertTrue($this->tmap->hasPrimaryStringColumn(), 'hasPrimaryStringColumn() returns true after adding pkStr column.');
     $this->assertEquals($column, $this->tmap->getPrimaryStringColumn(), 'getPrimaryStringColumn() returns correct column.');
 }
Ejemplo n.º 7
0
 /**
  * Converts value for some column types
  *
  * @param  mixed     $value  The value to convert
  * @param  ColumnMap $colMap The ColumnMap object
  * @return mixed     The converted value
  */
 protected function convertValueForColumn($value, ColumnMap $colMap)
 {
     if ($colMap->getType() == 'OBJECT' && is_object($value)) {
         if (is_array($value)) {
             $value = array_map('serialize', $value);
         } else {
             $value = serialize($value);
         }
     } elseif ($colMap->getType() == 'ARRAY' && is_array($value)) {
         $value = '| ' . implode(' | ', $value) . ' |';
     } elseif ($colMap->getType() == 'ENUM') {
         if (is_array($value)) {
             $value = array_map(array($colMap, 'getValueSetKey'), $value);
         } else {
             $value = $colMap->getValueSetKey($value);
         }
     }
     return $value;
 }
Ejemplo n.º 8
0
 /**
  * @return Column[]
  */
 public function getColumns()
 {
     return $this->columnMap->getColumns();
 }
Ejemplo n.º 9
0
 /**
  * Adds a given column map to the data map.
  *
  * @param \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap $columnMap The column map
  * @return void
  */
 public function addColumnMap(ColumnMap $columnMap)
 {
     $this->columnMaps[$columnMap->getPropertyName()] = $columnMap;
 }
 /**
  * Returns a PHP string representing options to pass to a validator for a given column.
  *
  * @param  ColumnMap $column  A ColumnMap object
  *
  * @return string    The options to pass to the validator as a PHP string
  */
 public function getValidatorOptionsForColumn(ColumnMap $column)
 {
     $options = array();
     if ($column->isForeignKey()) {
         $map = call_user_func(array(constant($this->getForeignTable($column)->getClassname() . '::PEER'), 'getTableMap'));
         foreach ($map->getColumns() as $primaryKey) {
             if ($primaryKey->isPrimaryKey()) {
                 break;
             }
         }
         $options[] = sprintf('\'model\' => \'%s\', \'column\' => \'%s\'', $this->getForeignTable($column)->getClassname(), strtolower($primaryKey->getColumnName()));
     } else {
         if ($column->isPrimaryKey()) {
             $options[] = sprintf('\'model\' => \'%s\', \'column\' => \'%s\'', $column->getTable()->getClassname(), strtolower($column->getColumnName()));
         } else {
             switch ($column->getType()) {
                 case PropelColumnTypes::CLOB:
                 case PropelColumnTypes::CHAR:
                 case PropelColumnTypes::VARCHAR:
                 case PropelColumnTypes::LONGVARCHAR:
                     if ($column->getSize()) {
                         $options[] = sprintf('\'max_length\' => %s', $column->getSize());
                     }
                     break;
             }
         }
     }
     if (!$column->isNotNull() || $column->isPrimaryKey()) {
         $options[] = '\'required\' => false';
     }
     return count($options) ? sprintf('array(%s)', implode(', ', $options)) : '';
 }
 /**
  * Returns a PHP string representing options to pass to a validator for a given column.
  *
  * @param  ColumnMap $column  A ColumnMap object
  *
  * @return string    The options to pass to the validator as a PHP string
  */
 public function getValidatorOptionsForColumn(ColumnMap $column)
 {
     $options = array();
     if ($column->isForeignKey()) {
         $options[] = sprintf('\'model\' => \'%s\', \'column\' => \'%s\'', $this->getForeignTable($column)->getClassname(), $this->translateColumnName($column, true));
     } else {
         if ($column->isPrimaryKey()) {
             $options[] = sprintf('\'model\' => \'%s\', \'column\' => \'%s\'', $column->getTable()->getClassname(), $this->translateColumnName($column));
         } else {
             switch ($column->getType()) {
                 case PropelColumnTypes::CLOB:
                 case PropelColumnTypes::CHAR:
                 case PropelColumnTypes::VARCHAR:
                 case PropelColumnTypes::LONGVARCHAR:
                     if ($column->getSize()) {
                         $options[] = sprintf('\'max_length\' => %s', $column->getSize());
                     }
                     break;
                 case PropelColumnTypes::TINYINT:
                     $options[] = sprintf('\'min\' => %s, \'max\' => %s', -128, 127);
                     break;
                 case PropelColumnTypes::SMALLINT:
                     $options[] = sprintf('\'min\' => %s, \'max\' => %s', -32768, 32767);
                     break;
                 case PropelColumnTypes::INTEGER:
                     $options[] = sprintf('\'min\' => %s, \'max\' => %s', -2147483648, 2147483647);
                     break;
                 case PropelColumnTypes::BIGINT:
                     $options[] = sprintf('\'min\' => %s, \'max\' => %s', -9.223372036854776E+18, 9223372036854775807);
                     break;
             }
         }
     }
     if (!$column->isNotNull() || $column->isPrimaryKey()) {
         $options[] = '\'required\' => false';
     }
     if (null !== $column->getDefaultValue()) {
         $options[] = sprintf('\'empty_value\' => \'%s\'', $column->getDefaultValue());
     }
     return count($options) ? sprintf('array(%s)', implode(', ', $options)) : '';
 }
Ejemplo n.º 12
0
 protected function getColumnName(\ColumnMap $column)
 {
     return strtolower($column->getName());
 }
Ejemplo n.º 13
0
 protected function getColumnNameAndOptions(ColumnMap $column)
 {
     $name = strtolower($column->getName());
     $relation = $column->getRelation();
     $options = array('label' => $relation ? $relation->getName() : ucfirst(str_replace("_", " ", $name)), 'id' => 'table-' . str_replace('_', '-', $column->getTableName()) . '-column-' . str_replace("_", "-", $name) . rand());
     return array($name, $options);
 }
 /**
  * Extract the value method and the required parameters for it, for given a ColumnMap's type.
  * Return an Array holding the value method as first value and its parameters as the second one.
  *
  * @param ColumnMap $column
  * @return Array
  */
 public static function extractValueMethod(ColumnMap $column)
 {
     $value_method = 'get' . $column->getPhpName();
     $params = null;
     if (in_array($column->getType(), array(PropelColumnTypes::BU_DATE, PropelColumnTypes::DATE))) {
         $params = ncChangeLogConfigHandler::getDateFormat();
     } elseif (in_array($column->getType(), array(PropelColumnTypes::BU_TIMESTAMP, PropelColumnTypes::TIMESTAMP))) {
         $params = ncChangeLogConfigHandler::getDateTimeFormat();
     } elseif ($column->getType() == PropelColumnTypes::TIME) {
         $params = ncChangeLogConfigHandler::getTimeFormat();
     }
     return array($value_method, $params);
 }
 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)));
 }
Ejemplo n.º 16
0
 /**
  * @see       DBAdapter::bindValue()
  *
  * @param PDOStatement $stmt
  * @param string       $parameter
  * @param mixed        $value
  * @param ColumnMap    $cMap
  * @param null|integer $position
  *
  * @return boolean
  */
 public function bindValue(PDOStatement $stmt, $parameter, $value, ColumnMap $cMap, $position = null)
 {
     $pdoType = $cMap->getPdoType();
     // FIXME - This is a temporary hack to get around apparent bugs w/ PDO+MYSQL
     // See http://pecl.php.net/bugs/bug.php?id=9919
     if ($pdoType == PDO::PARAM_BOOL) {
         $value = (int) $value;
         $pdoType = PDO::PARAM_INT;
         return $stmt->bindValue($parameter, $value, $pdoType);
     } elseif ($cMap->isTemporal()) {
         $value = $this->formatTemporalValue($value, $cMap);
     } elseif (is_resource($value) && $cMap->isLob()) {
         // we always need to make sure that the stream is rewound, otherwise nothing will
         // get written to database.
         rewind($value);
     }
     return $stmt->bindValue($parameter, $value, $pdoType);
 }
  /**
   * Returns HTML code for a column in edit mode.
   *
   * @param ColumnMap $column  The column name
   * @param array  $params  The parameters
   *
   * @return string HTML code
   */
  public function getCrudColumnEditTag($column, $params = array())
  {
    $type = $column->getCreoleType();

    if ($column->isForeignKey())
    {
      if (!$column->isNotNull() && !isset($params['include_blank']))
      {
        $params['include_blank'] = true;
      }
      return $this->getPHPObjectHelper('select_tag', $column, $params, array('related_class' => $this->getRelatedClassName($column)));
    }
    else if ($type == CreoleTypes::DATE)
    {
      // rich=false not yet implemented
      return $this->getPHPObjectHelper('input_date_tag', $column, $params, array('rich' => true));
    }
    else if ($type == CreoleTypes::TIMESTAMP)
    {
      // rich=false not yet implemented
      return $this->getPHPObjectHelper('input_date_tag', $column, $params, array('rich' => true, 'withtime' => true));
    }
    else if ($type == CreoleTypes::BOOLEAN)
    {
      return $this->getPHPObjectHelper('checkbox_tag', $column, $params);
    }
    else if ($type == CreoleTypes::CHAR || $type == CreoleTypes::VARCHAR)
    {
      $fieldMin = $this->getParameterValue('defaults.edit.char_min', 20);
      $fieldMax = $this->getParameterValue('defaults.edit.char_max', 80);
      $size = ($column->getSize() > $fieldMin ? ($column->getSize() < $fieldMax ? $column->getSize() : $fieldMax) : $fieldMin);
      return $this->getPHPObjectHelper('input_tag', $column, $params, array('size' => $size));
    }
    else if ($type == CreoleTypes::INTEGER || $type == CreoleTypes::TINYINT || $type == CreoleTypes::SMALLINT || $type == CreoleTypes::BIGINT)
    {
      $size = $this->getParameterValue('defaults.edit.int_size', 7);
      return $this->getPHPObjectHelper('input_tag', $column, $params, array('size' => $size));
    }
    else if ($type == CreoleTypes::FLOAT || $type == CreoleTypes::DOUBLE || $type == CreoleTypes::DECIMAL || $type == CreoleTypes::NUMERIC || $type == CreoleTypes::REAL)
    {
      $size = $this->getParameterValue('defaults.edit.float_size', 7);
      return $this->getPHPObjectHelper('input_tag', $column, $params, array('size' => $size));
    }
    else if ($type == CreoleTypes::TEXT || $type == CreoleTypes::LONGVARCHAR)
    {
      $size = $this->getParameterValue('defaults.edit.text_size', '80x5');
      return $this->getPHPObjectHelper('textarea_tag', $column, $params, array('size' => $size));
    }
    else
    {
      return $this->getPHPObjectHelper('input_tag', $column, $params, array('disabled' => true));
    }
  }
Ejemplo n.º 18
0
 protected static function _getColumnRawValue(ColumnMap $column, $value)
 {
     if ($value === null) {
         return null;
     }
     switch ($column->getType()) {
         case PropelColumnTypes::ENUM:
             $valueSet = $column->getValueSet();
             return array_search($value, $valueSet);
         case PropelColumnTypes::PHP_ARRAY:
             return '| ' . implode(' | ', $value) . ' |';
         case PropelColumnTypes::OBJECT:
             return serialize($value);
     }
     return $value;
 }
Ejemplo n.º 19
0
 /**
  * This method sets the configuration for a m:n relation based on
  * the $TCA column configuration
  *
  * @param string|ColumnMap $columnMap The column map
  * @param string $columnConfiguration The column configuration from $TCA
  * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedRelationException
  * @return ColumnMap
  */
 protected function setManyToManyRelation(ColumnMap $columnMap, $columnConfiguration)
 {
     if (isset($columnConfiguration['MM'])) {
         $columnMap->setTypeOfRelation(ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY);
         $columnMap->setChildTableName($columnConfiguration['foreign_table']);
         $columnMap->setChildTableWhereStatement($columnConfiguration['foreign_table_where']);
         $columnMap->setRelationTableName($columnConfiguration['MM']);
         if (is_array($columnConfiguration['MM_match_fields'])) {
             $columnMap->setRelationTableMatchFields($columnConfiguration['MM_match_fields']);
         }
         if (is_array($columnConfiguration['MM_insert_fields'])) {
             $columnMap->setRelationTableInsertFields($columnConfiguration['MM_insert_fields']);
         }
         $columnMap->setRelationTableWhereStatement($columnConfiguration['MM_table_where']);
         if (!empty($columnConfiguration['MM_opposite_field'])) {
             $columnMap->setParentKeyFieldName('uid_foreign');
             $columnMap->setChildKeyFieldName('uid_local');
             $columnMap->setChildSortByFieldName('sorting_foreign');
         } else {
             $columnMap->setParentKeyFieldName('uid_local');
             $columnMap->setChildKeyFieldName('uid_foreign');
             $columnMap->setChildSortByFieldName('sorting');
         }
     } else {
         throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedRelationException('The given information to build a many-to-many-relation was not sufficient. Check your TCA definitions. mm-relations with IRRE must have at least a defined "MM" or "foreign_selector".', 1268817963);
     }
     if ($this->getControlSection($columnMap->getRelationTableName()) !== null) {
         $columnMap->setRelationTablePageIdColumnName('pid');
     }
     return $columnMap;
 }
 public function getType(ColumnMap $column)
 {
     if ($column->isForeignKey()) {
         return 'ForeignKey';
     }
     switch ($column->getType()) {
         case PropelColumnTypes::BOOLEAN:
             return 'Boolean';
         case PropelColumnTypes::DATE:
         case PropelColumnTypes::TIME:
         case PropelColumnTypes::TIMESTAMP:
             return 'Date';
         case PropelColumnTypes::DOUBLE:
         case PropelColumnTypes::FLOAT:
         case PropelColumnTypes::NUMERIC:
         case PropelColumnTypes::DECIMAL:
         case PropelColumnTypes::REAL:
         case PropelColumnTypes::INTEGER:
         case PropelColumnTypes::SMALLINT:
         case PropelColumnTypes::TINYINT:
         case PropelColumnTypes::BIGINT:
             return 'Number';
         default:
             return 'Text';
     }
 }
Ejemplo n.º 21
0
 /**
  * Get value for column to use in database dump.
  * 
  * @param BaseObject $obj
  * @param ColumnMap $column
  * @return mixed
  */
 protected static function getColumnValue(BaseObject $obj, ColumnMap $column)
 {
     switch ($column->getType()) {
         case PropelColumnTypes::DATE:
             return $obj->{'get' . $column->getPhpName()}('Y-m-d');
             break;
         case PropelColumnTypes::TIMESTAMP:
             return $obj->{'get' . $column->getPhpName()}('Y-m-d H:i:s');
             break;
         case PropelColumnTypes::TIME:
             return $obj->{'get' . $column->getPhpName()}('H:i:s');
             break;
         default:
             return $obj->{'get' . $column->getPhpName()}();
     }
 }
 /**
  * Whether this column contains scalar values (to be used as indices).
  *
  * @param \ColumnMap $column
  *
  * @return Boolean
  */
 private function isScalar(\ColumnMap $column)
 {
     return in_array($column->getPdoType(), array(\PDO::PARAM_BOOL, \PDO::PARAM_INT, \PDO::PARAM_STR));
 }
 /**
  * Returns a PHP string representing options to pass to a validator for a given column.
  *
  * @param  ColumnMap $column  A ColumnMap object
  *
  * @return string    The options to pass to the validator as a PHP string
  */
 public function getValidatorOptionsForColumn(ColumnMap $column)
 {
     $options = array();
     if ($column->isForeignKey()) {
         $options[] = sprintf('\'model\' => \'%s\', \'column\' => \'%s\'', $this->getForeignTable($column)->getClassname(), $this->translateColumnName($column, true));
     } else {
         if ($column->isPrimaryKey()) {
             $options[] = sprintf('\'choices\' => array($this->getObject()->get%s()), \'empty_value\' => $this->getObject()->get%1$s()', $this->translateColumnName($column, false, BasePeer::TYPE_PHPNAME));
         } else {
             switch ($column->getType()) {
                 case PropelColumnTypes::CLOB:
                 case PropelColumnTypes::CHAR:
                 case PropelColumnTypes::VARCHAR:
                 case PropelColumnTypes::LONGVARCHAR:
                     if ($column->getSize()) {
                         $options[] = sprintf('\'max_length\' => %s', $column->getSize());
                     }
                     break;
                 case PropelColumnTypes::TINYINT:
                     $options[] = sprintf('\'min\' => %s, \'max\' => %s', -128, 127);
                     break;
                 case PropelColumnTypes::SMALLINT:
                     $options[] = sprintf('\'min\' => %s, \'max\' => %s', -32768, 32767);
                     break;
                 case PropelColumnTypes::INTEGER:
                     $options[] = sprintf('\'min\' => %s, \'max\' => %s', -2147483648, 2147483647);
                     break;
                 case PropelColumnTypes::BIGINT:
                     $options[] = sprintf('\'min\' => %s, \'max\' => %s', -9.223372036854776E+18, 9223372036854775807);
                     break;
                 case PropelColumnTypes::ENUM:
                     $valueSet = $column->getValueSet();
                     $options[] = sprintf("'choices' => %s", preg_replace('/[\\n\\r]+/', '', var_export($valueSet, true)));
                     break;
             }
         }
     }
     if (!$column->isNotNull() || $column->isPrimaryKey()) {
         $options[] = '\'required\' => false';
     }
     return count($options) ? sprintf('array(%s)', implode(', ', $options)) : '';
 }
Ejemplo n.º 24
0
 /**
  * Add a column to the table.
  *
  * @param      string name A String with the column name.
  * @param      string $type A string specifying the Propel type.
  * @param      boolean $isNotNull Whether column does not allow NULL values.
  * @param      int $size An int specifying the size.
  * @param      boolean $pk True if column is a primary key.
  * @param      string $fkTable A String with the foreign key table name.
  * @param      $fkColumn A String with the foreign key column name.
  * @param      string $defaultValue The default value for this column.
  * @return     ColumnMap The newly created column.
  */
 public function addColumn($name, $phpName, $type, $isNotNull = false, $size = null, $pk = null, $fkTable = null, $fkColumn = null)
 {
     $col = new ColumnMap($name, $this);
     if ($fkTable && $fkColumn) {
         if (strpos($fkColumn, '.') > 0 && strpos($fkColumn, $fkTable) !== false) {
             $fkColumn = substr($fkColumn, strlen($fkTable) + 1);
         }
         $col->setForeignKey($fkTable, $fkColumn);
     }
     $col->setType($type);
     $col->setPrimaryKey($pk);
     $col->setSize($size);
     $col->setPhpName($phpName);
     $col->setNotNull($isNotNull);
     $this->columns[$name] = $col;
     return $this->columns[$name];
 }
Ejemplo n.º 25
0
 /**
  * Whether this column in an integer
  *
  * @param \ColumnMap $column
  *
  * @return Boolean
  */
 private function isInteger(\ColumnMap $column)
 {
     return $column->getPdoType() === \PDO::PARAM_INT;
 }
Ejemplo n.º 26
0
 /**
  * Normalizes the column name, removing table prefix and uppercasing.
  * article.first_name becomes FIRST_NAME
  *
  * @deprecated Use ColumnMap::normalizeColumName() instead
  * @param      string $name
  * @return     string Normalized column name.
  */
 protected function normalizeColName($name)
 {
   return ColumnMap::normalizeName($name);
 }
Ejemplo n.º 27
0
 public function testNormalizeName()
 {
     $this->assertEquals('', ColumnMap::normalizeName(''), 'normalizeColumnName() returns an empty string when passed an empty string');
     $this->assertEquals('BAR', ColumnMap::normalizeName('bar'), 'normalizeColumnName() uppercases the input');
     $this->assertEquals('BAR_BAZ', ColumnMap::normalizeName('bar_baz'), 'normalizeColumnName() does not mind underscores');
     $this->assertEquals('BAR', ColumnMap::normalizeName('FOO.BAR'), 'normalizeColumnName() removes table prefix');
     $this->assertEquals('BAR', ColumnMap::normalizeName('BAR'), 'normalizeColumnName() leaves normalized column names unchanged');
     $this->assertEquals('BAR_BAZ', ColumnMap::normalizeName('foo.bar_baz'), 'normalizeColumnName() can do all the above at the same time');
 }
Ejemplo n.º 28
0
 /**
  * Binds a value to a positioned parameted in a statement,
  * given a ColumnMap object to infer the binding type.
  * Warning: duplicates logic from DefaultPlatform::getColumnBindingPHP().
  * Any code modification here must be ported there.
  *
  * @param     PDOStatement  $stmt  The statement to bind
  * @param     string        $parameter  Parameter identifier
  * @param     mixed         $value  The value to bind
  * @param     ColumnMap     $cMap  The ColumnMap of the column to bind
  * @param     null|integer  $position  The position of the parameter to bind
  *
  * @return    boolean
  */
 public function bindValue(PDOStatement $stmt, $parameter, $value, ColumnMap $cMap, $position = null)
 {
     if ($cMap->isTemporal()) {
         $value = $this->formatTemporalValue($value, $cMap);
     } elseif (is_resource($value) && $cMap->isLob()) {
         // we always need to make sure that the stream is rewound, otherwise nothing will
         // get written to database.
         rewind($value);
     }
     return $stmt->bindValue($parameter, $value, $cMap->getPdoType());
 }
Ejemplo n.º 29
0
 /**
  * Gets value for row table
  * 
  * Swaps foreign creator_node_id values for their unique FQDN value. Note that the other
  * part(s) to a primary or foreign key is set by the creator and is the same in all nodes,
  * so may be hashed without causing difference problems between nodes.
  * 
  * @todo Better node table detection required (should use known prefix)
  * @todo Fix column name hardwiring
  * 
  * @param MeshingBaseObject $object
  * @param ColumnMap $columnMap
  * @return mixed 
  */
 protected function getRowValue(MeshingBaseObject $object, ColumnMap $columnMap)
 {
     // Get value for this column
     $columnName = $columnMap->getName();
     $value = $object->getByName($columnName, BasePeer::TYPE_RAW_COLNAME);
     // If the related table name ends with '_known_node' then we assume this is a
     // FK to a creator node ID.
     if ($columnMap->isForeignKey()) {
         $match = '_known_node';
         $isNodeTable = $match == substr($columnMap->getRelatedTableName(), -strlen($match));
         if ($isNodeTable && $columnMap->getRelatedColumnName() == 'ID') {
             $nodePeerName = $columnMap->getRelation()->getForeignTable()->getPeerClassname();
             $node = call_user_func(array($nodePeerName, 'retrieveByPK'), $value, $this->con);
             // If there is no related node, we really do have problems!
             if (!$node) {
                 $primaryKey = $object->getPrimaryKey();
                 if (is_array($primaryKey)) {
                     $primaryKey = '{' . implode(',', $primaryKey) . '}';
                 }
                 $type = get_class($object);
                 throw new Exception("Row {$primaryKey} in table '{$type}' points to a non-existent node row");
             }
             $value = $node->getFqdn();
         }
     }
     return $value;
 }