示例#1
0
 public function removeSubColumn(Column $column)
 {
     $this->subColumns = array_values(array_filter($this->subColumns, function ($elm) use($column) {
         return $elm->getName() !== $column->getName();
     }));
     return $this;
 }
 /**
  * Adds the close of mutator (setter) method for a column.
  * This method overrides the method from PHP5BasicObjectBuilder in order to
  * account for updating related objects.
  * @param      string &$script The script will be modified in this method.
  * @param      Column $col The current column.
  * @see        PHP5BasicObjectBuilder::addMutatorClose()
  */
 protected function addMutatorClose(&$script, Column $col)
 {
     $table = $this->getTable();
     $cfc = $col->getPhpName();
     $clo = strtolower($col->getName());
     if ($col->isForeignKey()) {
         $tblFK = $table->getDatabase()->getTable($col->getRelatedTableName());
         $colFK = $tblFK->getColumn($col->getRelatedColumnName());
         $varName = $this->getFKVarName($col->getForeignKey());
         $script .= "\n\t\tif (\$this->{$varName} !== null && \$this->" . $varName . "->get" . $colFK->getPhpName() . "() !== \$v) {\n\t\t\t\$this->{$varName} = null;\n\t\t}\n";
     }
     /* if col is foreign key */
     foreach ($col->getReferrers() as $fk) {
         $tblFK = $this->getDatabase()->getTable($fk->getForeignTableName());
         if ($tblFK->getName() != $table->getName()) {
             $collName = $this->getRefFKCollVarName($fk);
             $tblFK = $table->getDatabase()->getTable($col->getRelatedTableName());
             $colFK = $tblFK->getColumn($col->getRelatedColumnName());
             $script .= "\n\n\t\t// update associated " . $tblFK->getPhpName() . "\n\t\tif (\$this->{$collName} !== null) {\n\t\t\tforeach(\$this->{$collName} as \$referrerObject) {\n\t\t\t\t  \$referrerObject->set" . $colFK->getPhpName() . "(\$v);\n\t\t\t  }\n\t\t  }\n";
         }
         // if
     }
     // foreach
     $script .= "\n\t} // set{$cfc}()\n";
 }
示例#3
0
 /**
  * Builds the DDL SQL for a Column object.
  * @return string
  */
 public function getColumnDDL(Column $col)
 {
     $platform = $this->getPlatform();
     $domain = $col->getDomain();
     $sb = "";
     $sb .= $this->quoteIdentifier($col->getName()) . " ";
     $sb .= $domain->getSqlType();
     if ($platform->hasSize($domain->getSqlType())) {
         $sb .= $domain->printSize();
     }
     $sb .= " ";
     $sb .= $col->getDefaultSetting() . " ";
     $sb .= $col->getNotNullString() . " ";
     $sb .= $col->getAutoIncrementString();
     return trim($sb);
 }
 /**
  * Adds the function body for the lazy loader method
  * @param      string &$script The script will be modified in this method.
  * @param      Column $col The current column.
  * @see        addLazyLoader()
  **/
 protected function addLazyLoaderBody(&$script, Column $col)
 {
     $platform = $this->getPlatform();
     $clo = strtolower($col->getName());
     $script .= "\n\t\t\$c = \$this->buildPkeyCriteria();\n\t\t\$c->addSelectColumn(" . $this->getColumnConstant($col) . ");\n\t\ttry {\n\t\t\t\$stmt = " . $this->getPeerClassname() . "::doSelectStmt(\$c, \$con);\n\t\t\t\$row = \$stmt->fetch(PDO::FETCH_NUM);\n\t\t\t\$stmt->closeCursor();";
     if ($col->getType() === PropelTypes::CLOB && $this->getPlatform() instanceof OraclePlatform) {
         // PDO_OCI returns a stream for CLOB objects, while other PDO adapters return a string...
         $script .= "\n\t\t\t\$this->{$clo} = stream_get_contents(\$row[0]);";
     } elseif ($col->isLobType() && !$platform->hasStreamBlobImpl()) {
         $script .= "\n\t\t\tif (\$row[0] !== null) {\n\t\t\t\t\$this->{$clo} = fopen('php://memory', 'r+');\n\t\t\t\tfwrite(\$this->{$clo}, \$row[0]);\n\t\t\t\trewind(\$this->{$clo});\n\t\t\t} else {\n\t\t\t\t\$this->{$clo} = null;\n\t\t\t}";
     } elseif ($col->isPhpPrimitiveType()) {
         $script .= "\n\t\t\t\$this->{$clo} = (\$row[0] !== null) ? (" . $col->getPhpType() . ") \$row[0] : null;";
     } elseif ($col->isPhpObjectType()) {
         $script .= "\n\t\t\t\$this->{$clo} = (\$row[0] !== null) ? new " . $col->getPhpType() . "(\$row[0]) : null;";
     } else {
         $script .= "\n\t\t\t\$this->{$clo} = \$row[0];";
     }
     $script .= "\n\t\t\t\$this->" . $clo . "_isLoaded = true;\n\t\t} catch (Exception \$e) {\n\t\t\tthrow new PropelException(\"Error loading value for [{$clo}] column on demand.\", \$e);\n\t\t}";
 }
 /**
  * Constructs an instance from a list of column headers as returned by the
  * Google Analytics API.
  *
  * @param array $headers
  * @param Google\Analytics\API $api
  */
 public function __construct(array $headers, API $api)
 {
     $headerCount = count($headers);
     for ($i = 0; $i < $headerCount; $i++) {
         self::_validateHeader($headers[$i]);
         try {
             $column = $api->getColumn($headers[$i]['name']);
         } catch (InvalidArgumentException $e) {
             /* I don't expect this to happen but in case it does, we can
             			create a representation of the column by building it on the
             			fly, though it will be missing most of the available
             			properties. */
             $column = new Column();
             $column->setID(API::addPrefix($headers[$i]['name']));
             $column->setType($headers[$i]['columnType']);
             $column->setDataType($headers[$i]['dataType']);
         }
         $this->_columns[] = $column;
         $this->_columnIndicesByName[$column->getName()] = $i;
     }
 }
示例#6
0
 /**
  * Get the quoted identifier for the column name
  * @param Column $column
  * @return string
  */
 public function getColumnBaseIdentifier(Column $column)
 {
     return $this->quoteObjectIdentifier($column->getName());
 }
 public function addColumn(Column $col)
 {
     $this->columns[$col->getName()] = $col;
     return $this;
 }
 public function getColumnDDL(Column $col)
 {
     $domain = $col->getDomain();
     $ddl = array($this->quoteIdentifier($col->getName()));
     $sqlType = $domain->getSqlType();
     $table = $col->getTable();
     if ($col->isAutoIncrement() && $table && $table->getIdMethodParameters() == null) {
         $sqlType = $col->getType() === PropelTypes::BIGINT ? 'bigserial' : 'serial';
     }
     if ($this->hasSize($sqlType) && $col->isDefaultSqlType($this)) {
         $ddl[] = $sqlType . $domain->printSize();
     } else {
         $ddl[] = $sqlType;
     }
     if ($default = $this->getColumnDefaultValueDDL($col)) {
         $ddl[] = $default;
     }
     if ($notNull = $this->getNullString($col->isNotNull())) {
         $ddl[] = $notNull;
     }
     if ($autoIncrement = $col->getAutoIncrementString()) {
         $ddl[] = $autoIncrement;
     }
     return implode(' ', $ddl);
 }
示例#9
0
 /**
  * Gets the name of the column that this Validator applies to.
  * @return     string
  */
 public function getColumnName()
 {
     return $this->column->getName();
 }
 /**
  * Metodo que verifica se a coluna eh foreign key, caso for - retorna os dados da chave estrangeira
  *
  * @param Column $objColumn
  * @return array
  */
 private function isForeignKey($objColumn)
 {
     $arrForeignKey = [];
     if (array_key_exists($objColumn->getName(), $this->arrForeignKeys)) {
         $arrForeignKey = $this->arrForeignKeys[$objColumn->getName()];
     }
     return $arrForeignKey;
 }
示例#11
0
 /**
  * Populates the properties that store cached dimensions and metrics,
  * either from the database or from the API directly, depending on when
  * the data that we have was last fetched.
  */
 private function _refreshColumnMetadata()
 {
     /* If we're not using a database, the best we can do is to cache the
        column metadata for the duration of this process' existence. */
     if (self::$_dbConn) {
         try {
             $lastFetchData = self::_getLastFetchData('google_analytics_api_columns');
             if ($lastFetchData) {
                 $fetchDate = (int) $lastFetchData['fetch_date'];
                 $etag = $lastFetchData['etag'];
             } else {
                 $fetchDate = null;
                 $etag = null;
             }
             $columns = null;
             $newETag = null;
             if ($this->_bypassColumnCache || !$fetchDate || $fetchDate <= time() - GOOGLE_ANALYTICS_API_METADATA_CACHE_DURATION) {
                 $this->_bypassColumnCache = false;
                 $request = new APIRequest('metadata/ga/columns');
                 if ($etag) {
                     $request->setHeader('If-None-Match: ' . $etag);
                 }
                 $columns = $this->_makeRequest($request);
                 if ($columns) {
                     $stmt = self::$_DB_STATEMENTS['google_analytics_api_columns']['insert'];
                     foreach ($columns as $column) {
                         $stmt->bindValue(':name', $column->getName(), \PDO::PARAM_STR);
                         $stmt->bindValue(':type', $column->getType(), \PDO::PARAM_STR);
                         $stmt->bindValue(':data_type', $column->getDataType(), \PDO::PARAM_STR);
                         $stmt->bindValue(':replaced_by', $column->getReplacementColumn(), \PDO::PARAM_STR);
                         $stmt->bindValue(':group', $column->getGroup(), \PDO::PARAM_STR);
                         $stmt->bindValue(':ui_name', $column->getUIName(), \PDO::PARAM_STR);
                         $stmt->bindValue(':description', $column->getDescription(), \PDO::PARAM_STR);
                         $stmt->bindValue(':calculation', $column->getCalculation(), \PDO::PARAM_STR);
                         $stmt->bindValue(':min_template_index', $column->getMinTemplateIndex(), \PDO::PARAM_INT);
                         $stmt->bindValue(':max_template_index', $column->getMaxTemplateIndex(), \PDO::PARAM_INT);
                         $stmt->bindValue(':min_template_index_premium', $column->getPremiumMinTemplateIndex(), \PDO::PARAM_INT);
                         $stmt->bindValue(':max_template_index_premium', $column->getPremiumMaxTemplateIndex(), \PDO::PARAM_INT);
                         $stmt->bindValue(':allowed_in_segments', $column->isAllowedInSegments(), \PDO::PARAM_INT);
                         $stmt->bindValue(':deprecated', $column->isDeprecated(), \PDO::PARAM_INT);
                         $stmt->execute();
                     }
                     $stmt = null;
                 }
                 if (array_key_exists('etag', $this->_responseParsed) && $this->_responseParsed['etag']) {
                     $newETag = $this->_responseParsed['etag'];
                 } else {
                     $responseHeader = $this->getResponseHeaderAsAssociativeArray();
                     if (array_key_exists('ETag', $responseHeader) && $responseHeader['ETag']) {
                         $newETag = $responseHeader['ETag'];
                     }
                 }
                 if ($newETag) {
                     self::_storeFetchData('google_analytics_api_columns', count($columns), $newETag);
                 }
             }
             if (!$columns) {
                 $columns = array();
                 $stmt = self::$_dbConn->query('SELECT * FROM google_analytics_api_columns');
                 $stmt->bindColumn('name', $name, \PDO::PARAM_STR);
                 $stmt->bindColumn('type', $type, \PDO::PARAM_STR);
                 $stmt->bindColumn('data_type', $dataType, \PDO::PARAM_STR);
                 $stmt->bindColumn('replaced_by', $replacement, \PDO::PARAM_STR);
                 $stmt->bindColumn('group', $group, \PDO::PARAM_STR);
                 $stmt->bindColumn('ui_name', $uiName, \PDO::PARAM_STR);
                 $stmt->bindColumn('description', $description, \PDO::PARAM_STR);
                 $stmt->bindColumn('calculation', $calculation, \PDO::PARAM_STR);
                 /* Null values get cast to zeros if I bind them as
                    integers, so we'll rely on the object's setter to take care
                    of the type casting. */
                 $stmt->bindColumn('min_template_index', $minTemplateIndex, \PDO::PARAM_STR);
                 $stmt->bindColumn('max_template_index', $maxTemplateIndex, \PDO::PARAM_STR);
                 $stmt->bindColumn('min_template_index_premium', $minTemplateIndexPremium, \PDO::PARAM_STR);
                 $stmt->bindColumn('max_template_index_premium', $maxTemplateIndexPremium, \PDO::PARAM_STR);
                 $stmt->bindColumn('allowed_in_segments', $allowedInSegments, \PDO::PARAM_BOOL);
                 $stmt->bindColumn('deprecated', $deprecated, \PDO::PARAM_BOOL);
                 while ($stmt->fetch(\PDO::FETCH_BOUND)) {
                     $column = new Column();
                     $column->setID('ga:' . $name);
                     $column->setReplacementColumn($replacement);
                     $column->setType($type);
                     $column->setDataType($dataType);
                     $column->setGroup($group);
                     $column->setUIName($uiName);
                     $column->setDescription($description);
                     $column->setCalculation($calculation);
                     if ($minTemplateIndex !== null) {
                         $column->setMinTemplateIndex($minTemplateIndex);
                     }
                     if ($maxTemplateIndex !== null) {
                         $column->setMaxTemplateIndex($maxTemplateIndex);
                     }
                     if ($minTemplateIndexPremium !== null) {
                         $column->setPremiumMinTemplateIndex($minTemplateIndexPremium);
                     }
                     if ($maxTemplateIndexPremium !== null) {
                         $column->setPremiumMaxTemplateIndex($maxTemplateIndexPremium);
                     }
                     $column->isAllowedInSegments($allowedInSegments);
                     $column->isDeprecated($deprecated);
                     $columns[] = $column;
                 }
             }
         } catch (\PDOException $e) {
             throw new RuntimeException('Caught database error while refreshing column metadata.', null, $e);
         }
     } else {
         $columns = $this->_makeRequest(new APIRequest('metadata/ga/columns'));
     }
     foreach ($columns as $column) {
         if ($column->getType() == 'DIMENSION') {
             $table =& self::$_dimensions;
             $list =& self::$_dimensionNames;
         } else {
             $table =& self::$_metrics;
             $list =& self::$_metricNames;
         }
         $name = $column->getName();
         $table[$name] = $column;
         if (!$column->isDeprecated()) {
             $list[] = $name;
         }
     }
     usort(self::$_dimensionNames, 'strcasecmp');
     usort(self::$_metricNames, 'strcasecmp');
 }
示例#12
0
 /**
  * Builds the DDL SQL to remove a column
  *
  * @return     string
  */
 public function getRemoveColumnDDL(Column $column)
 {
     $pattern = "\nALTER TABLE %s DROP %s;\n";
     return sprintf($pattern, $this->quoteIdentifier($column->getTable()->getName()), $this->quoteIdentifier($column->getName()));
 }
示例#13
0
 /**
  * Adds a setter method for date/time/timestamp columns.
  * @param      string &$script The script will be modified in this method.
  * @param      Column $col The current column.
  * @see        parent::addColumnMutators()
  */
 protected function addTemporalMutator(&$script, Column $col)
 {
     $cfc = $col->getPhpName();
     $clo = strtolower($col->getName());
     $visibility = $col->getMutatorVisibility();
     $dateTimeClass = $this->getBuildProperty('dateTimeClass');
     if (!$dateTimeClass) {
         $dateTimeClass = 'DateTime';
     }
     $script .= "\n\t/**\n\t * Sets the value of [{$clo}] column to a normalized version of the date/time value specified.\n\t * " . $col->getDescription() . "\n\t * @param      mixed \$v string, integer (timestamp), or DateTime value.  Empty string will\n\t *\t\t\t\t\t\tbe treated as NULL for temporal objects.\n\t * @return     " . $this->getObjectClassname() . " The current object (for fluent API support)\n\t */\n\t" . $visibility . " function set{$cfc}(\$v)\n\t{";
     $this->addMutatorOpenBody($script, $col);
     $fmt = var_export($this->getTemporalFormatter($col), true);
     $script .= "\n\t\t// we treat '' as NULL for temporal objects because DateTime('') == DateTime('now')\n\t\t// -- which is unexpected, to say the least.\n\t\tif (\$v === null || \$v === '') {\n\t\t\t\$dt = null;\n\t\t} elseif (\$v instanceof DateTime) {\n\t\t\t\$dt = \$v;\n\t\t} else {\n\t\t\t// some string/numeric value passed; we normalize that so that we can\n\t\t\t// validate it.\n\t\t\ttry {\n\t\t\t\tif (is_numeric(\$v)) { // if it's a unix timestamp\n\t\t\t\t\t\$dt = new {$dateTimeClass}('@'.\$v, new DateTimeZone('UTC'));\n\t\t\t\t\t// We have to explicitly specify and then change the time zone because of a\n\t\t\t\t\t// DateTime bug: http://bugs.php.net/bug.php?id=43003\n\t\t\t\t\t\$dt->setTimeZone(new DateTimeZone(date_default_timezone_get()));\n\t\t\t\t} else {\n\t\t\t\t\t\$dt = new {$dateTimeClass}(\$v);\n\t\t\t\t}\n\t\t\t} catch (Exception \$x) {\n\t\t\t\tthrow new PropelException('Error parsing date/time value: ' . var_export(\$v, true), \$x);\n\t\t\t}\n\t\t}\n\n\t\tif ( \$this->{$clo} !== null || \$dt !== null ) {\n\t\t\t// (nested ifs are a little easier to read in this case)\n\n\t\t\t\$currNorm = (\$this->{$clo} !== null && \$tmpDt = new {$dateTimeClass}(\$this->{$clo})) ? \$tmpDt->format({$fmt}) : null;\n\t\t\t\$newNorm = (\$dt !== null) ? \$dt->format({$fmt}) : null;\n\n\t\t\tif ( (\$currNorm !== \$newNorm) // normalized values don't match ";
     if (($def = $col->getDefaultValue()) !== null && !$def->isExpression()) {
         $defaultValue = $this->getDefaultValueString($col);
         $script .= "\n\t\t\t\t\t|| (\$dt->format({$fmt}) === {$defaultValue}) // or the entered value matches the default";
     }
     $script .= "\n\t\t\t\t\t)\n\t\t\t{\n\t\t\t\t\$this->{$clo} = (\$dt ? \$dt->format({$fmt}) : null);\n\t\t\t\t\$this->modifiedColumns[] = " . $this->getColumnConstant($col) . ";\n\t\t\t}\n\t\t} // if either are not null\n";
     $this->addMutatorClose($script, $col);
 }
示例#14
0
 public function getObject(Column $column)
 {
     switch ($column->getType()) {
         case self::DBFFIELD_TYPE_CHAR:
             return $this->getString($column->getName());
         case self::DBFFIELD_TYPE_DOUBLE:
             return $this->getDouble($column->getName());
         case self::DBFFIELD_TYPE_DATE:
             return $this->getDate($column->getName());
         case self::DBFFIELD_TYPE_DATETIME:
             return $this->getDateTime($column->getName());
         case self::DBFFIELD_TYPE_FLOATING:
             return $this->getFloat($column->getName());
         case self::DBFFIELD_TYPE_LOGICAL:
             return $this->getBoolean($column->getName());
         case self::DBFFIELD_TYPE_MEMO:
             return $this->getMemo($column->getName());
         case self::DBFFIELD_TYPE_NUMERIC:
             return $this->getNum($column->getName());
         case self::DBFFIELD_TYPE_INDEX:
             return $this->getIndex($column->getName(), $column->getLength());
         case self::DBFFIELD_IGNORE_0:
             return false;
     }
     throw new Exception\InvalidColumnException(sprintf('Cannot handle datatype %s', $column->getType()));
 }
示例#15
0
 /**
  * Adds a column to the definition of the Model.
  *
  * @param Column $column the column to add.
  */
 function addColumn(Column $column)
 {
     $this->columns[$column->getName()] = $column;
 }
示例#16
0
 public function getAddColumnDDLBits(Column $column)
 {
     $pattern = "ADD %s %s";
     $tableColumns = $column->getTable()->getColumns();
     //default to add to top if the before-column cannot be found
     $insertPositionDDL = "FIRST";
     foreach ($tableColumns as $i => $tableColumn) {
         //we found the column, use the column before it, if its not the first
         if ($tableColumn->getName() == $column->getName()) {
             //we have a column that is not the first column
             if ($i > 0) {
                 $insertPositionDDL = "AFTER " . $this->quoteIdentifier($tableColumns[$i - 1]->getName());
             }
             break;
         }
     }
     return sprintf($pattern, $this->getColumnDDL($column), $insertPositionDDL);
 }
 /**
  * @param \DatabaseExporterImporter\Entity\Column $column
  * @return $this
  */
 public function addColumn(Column $column)
 {
     $column->setTable($this);
     $this->columns[$column->getName()] = $column;
     return $this;
 }
示例#18
0
 /**
  * COMPATIBILITY: Get the column constant name (e.g. PeerName::COLUMN_NAME).
  *
  * This method exists simply because it belonged to the 'PeerBuilder' that this
  * class is replacing (because of name conflict more than actual functionality overlap).
  * When the new builder model is finished this method will be removed.
  *
  * @param      Column $col The column we need a name for.
  * @param      string $phpName The PHP Name of the peer class. The 'Peer' is appended automatically.
  *
  * @return     string If $phpName is provided, then will return {$phpName}Peer::COLUMN_NAME; if not, just COLUMN_NAME.
  * @deprecated
  */
 public static function getColumnName(Column $col, $phpName = null)
 {
     // was it overridden in schema.xml ?
     if ($col->getPeerName()) {
         $const = strtoupper($col->getPeerName());
     } else {
         $const = strtoupper($col->getName());
     }
     if ($phpName !== null) {
         return $phpName . 'Peer::' . $const;
     } else {
         return $const;
     }
 }
 public function getColumnConstant(Column $column)
 {
     return "{$this->getPeerClassName()}::" . strtoupper($column->getName());
 }
示例#20
0
 /**
  * setColumn
  *
  * @param Column $column
  *
  * @return  static
  */
 public function setColumn(Column $column)
 {
     $this->columns[$column->getName()] = $column;
     return $this;
 }
示例#21
0
 /**
  * Get the column constant name (e.g. PeerName::COLUMN_NAME).
  *
  * @param      Column $col The column we need a name for.
  * @param      string $classname The Peer classname to use.
  *
  * @return     string If $classname is provided, then will return $classname::COLUMN_NAME; if not, then the peername is looked up for current table to yield $currTablePeer::COLUMN_NAME.
  */
 public function getColumnConstant($col, $classname = null)
 {
     if ($col === null) {
         $e = new Exception("No col specified.");
         print $e;
         throw $e;
     }
     if ($classname === null) {
         return $this->getBuildProperty('classPrefix') . $col->getConstantName();
     }
     // was it overridden in schema.xml ?
     if ($col->getPeerName()) {
         $const = strtoupper($col->getPeerName());
     } else {
         $const = strtoupper($col->getName());
     }
     return $classname . '::' . $const;
 }
示例#22
0
 /**
  * Gets a single validator for specified column name.
  * @param      Column $column
  * @return     Validator
  */
 public function getValidator(Column $column)
 {
     $key = $column->getName();
     if (!isset($this->validators[$key])) {
         $this->validators[$key] = new Validator();
         $this->validators[$key]->setColumn($column);
     }
     return $this->validators[$key];
 }
示例#23
0
 /**
  * Add a foreign column for the relation
  *
  * @param Column $column
  *
  * @return $this
  * @throws Exception\Manager
  */
 public function addForeignForeignColumn(Column $column)
 {
     $alias = $this->normalizeName($column->getName());
     if ($this->foreignForeignColumns->offsetExists($alias) === true) {
         throw Exception\Relation::foreignForeignColumnAlreadyExists($alias, $this->getName());
     }
     $this->foreignForeignColumns->offsetSet($alias, $column);
     return $this;
 }
 /**
  * Adds setter method for "normal" columns.
  *
  * @param string &$script The script will be modified in this method.
  * @param Column $col     The current column.
  *
  * @see        parent::addColumnMutators()
  */
 protected function addDefaultMutator(&$script, Column $col)
 {
     $clo = strtolower($col->getName());
     $this->addMutatorOpen($script, $col);
     // Perform type-casting to ensure that we can use type-sensitive
     // checking in mutators.
     if ($col->isPhpPrimitiveType()) {
         $script .= "\n        if (\$v !== null && is_numeric(\$v)) {\n            \$v = (" . $col->getPhpType() . ") \$v;\n        }\n";
     }
     $script .= "\n        if (\$this->{$clo} !== \$v) {\n            \$this->{$clo} = \$v;\n            \$this->modifiedColumns[] = " . $this->getColumnConstant($col) . ";\n        }\n";
     $this->addMutatorClose($script, $col);
 }
示例#25
0
 /** 
  * Get the column constant name (e.g. PeerName::COLUMN_NAME).
  * 
  * @param Column $col The column we need a name for.
  * @param string $phpName The PHP Name of the peer class. The 'Peer' is appended automatically.
  * 
  * @return string If $phpName is provided, then will return {$phpName}Peer::COLUMN_NAME; if not, then uses current table COLUMN_NAME.
  */
 public function getColumnConstant($col, $phpName = null)
 {
     if ($col === null) {
         $e = new Exception("No col specified.");
         print $e;
         throw $e;
     }
     $classname = $this->getPeerClassname($phpName);
     // was it overridden in schema.xml ?
     if ($col->getPeerName()) {
         $const = strtoupper($col->getPeerName());
     } else {
         $const = strtoupper($col->getName());
     }
     return $classname . '::' . $const;
 }
示例#26
0
 /**
  * Adds setter method for "normal" columns.
  * @param      string &$script The script will be modified in this method.
  * @param      Column $col The current column.
  * @see        parent::addColumnMutators()
  */
 protected function addDefaultMutator(&$script, Column $col)
 {
     $clo = strtolower($col->getName());
     // FIXME: refactor this
     $defaultValue = null;
     if (($val = $col->getPhpDefaultValue()) !== null) {
         settype($val, $col->getPhpNative());
         $defaultValue = var_export($val, true);
     }
     $this->addMutatorOpen($script, $col);
     // Perform some smart checking here to handle possible type discrepancies
     // between the passed-in value and the value from the DB
     if ($col->getPhpNative() === "int") {
         $script .= "\n\t\t// Since the native PHP type for this column is integer,\n\t\t// we will cast the input value to an int (if it is not).\n\t\tif (\$v !== null && !is_int(\$v) && is_numeric(\$v)) {\n\t\t\t\$v = (int) \$v;\n\t\t}\n";
     } elseif ($col->getPhpNative() === "string") {
         $script .= "\n\t\t// Since the native PHP type for this column is string,\n\t\t// we will cast the input to a string (if it is not).\n\t\tif (\$v !== null && !is_string(\$v)) {\n\t\t\t\$v = (string) \$v;\n\t\t}\n";
     }
     $script .= "\n\t\tif (\$this->{$clo} !== \$v";
     if ($defaultValue !== null) {
         $script .= " || \$v === {$defaultValue}";
     }
     $script .= ") {\n\t\t\t\$this->{$clo} = \$v;\n\t\t\t\$this->modifiedColumns[] = " . $this->getColumnConstant($col) . ";\n\t\t}\n";
     $this->addMutatorClose($script, $col);
 }
示例#27
0
 /**
  * Adds setter method for "normal" columns.
  * @param      string &$script The script will be modified in this method.
  * @param      Column $col The current column.
  * @see        parent::addColumnMutators()
  */
 protected function addDefaultMutator(&$script, Column $col)
 {
     $clo = strtolower($col->getName());
     $this->addMutatorOpen($script, $col);
     // Perform type-casting to ensure that we can use type-sensitive
     // checking in mutators.
     if ($col->isPhpPrimitiveType()) {
         $script .= "\n\t\tif (\$v !== null) {\n\t\t\t\$v = (" . $col->getPhpType() . ") \$v;\n\t\t}\n";
     }
     $script .= "\n\t\tif (\$this->{$clo} !== \$v";
     if (($def = $col->getDefaultValue()) !== null && !$def->isExpression()) {
         $script .= " || \$this->isNew()";
     }
     $script .= ") {\n\t\t\t\$this->{$clo} = \$v;\n\t\t\t\$this->modifiedColumns[] = " . $this->getColumnConstant($col) . ";\n\t\t}\n";
     $this->addMutatorClose($script, $col);
 }
示例#28
0
 /**
  * Adds the comment for a mutator
  * @param string &$script The script will be modified in this method.
  * @param Column $col The current column.
  * @see        addMutatorOpen()
  **/
 public function addMutatorComment(&$script, Column $col)
 {
     $clo = strtolower($col->getName());
     $script .= "\n    /**\n     * Set the value of [{$clo}] column.\n     * " . $col->getDescription() . "\n     * @param " . $col->getPhpType() . "|null \$v new value\n     * @return " . $this->getObjectClassname() . " The current object (for fluent API support)\n     */";
 }
示例#29
0
 /**
  * Builds the DDL SQL for a Column object.
  * @return     string
  */
 public function getColumnDDL(Column $col)
 {
     $platform = $this->getPlatform();
     $domain = $col->getDomain();
     $sqlType = $domain->getSqlType();
     $notNullString = $col->getNotNullString();
     $defaultSetting = $col->getDefaultSetting();
     // Special handling of TIMESTAMP/DATETIME types ...
     // See: http://propel.phpdb.org/trac/ticket/538
     if ($sqlType == 'DATETIME') {
         $def = $domain->getDefaultValue();
         if ($def && $def->isExpression()) {
             // DATETIME values can only have constant expressions
             $sqlType = 'TIMESTAMP';
         }
     } elseif ($sqlType == 'DATE') {
         $def = $domain->getDefaultValue();
         if ($def && $def->isExpression()) {
             // DATE values don't support expressions in MySQL
             throw new EngineException("DATE columns cannot have default *expressions* in MySQL.");
         }
     }
     $sb = "";
     $sb .= $this->quoteIdentifier($col->getName()) . " ";
     $sb .= $sqlType;
     if ($platform->hasSize($sqlType)) {
         $sb .= $domain->printSize();
     }
     $sb .= " ";
     if ($sqlType == 'TIMESTAMP') {
         $notNullString = $col->getNotNullString();
         $defaultSetting = $col->getDefaultSetting();
         if ($notNullString == '') {
             $notNullString = 'NULL';
         }
         if ($defaultSetting == '' && $notNullString == 'NOT NULL') {
             $defaultSetting = 'DEFAULT CURRENT_TIMESTAMP';
         }
         $sb .= $notNullString . " " . $defaultSetting . " ";
     } else {
         $sb .= $defaultSetting . " ";
         $sb .= $notNullString . " ";
     }
     $sb .= $col->getAutoIncrementString();
     return trim($sb);
 }
示例#30
0
 /**
  * @param Column|array $column
  */
 public function addColumn($column)
 {
     if ($column instanceof Column) {
         $column->setRow($this);
         $this->columns[$column->getName()] = $column;
         return $column;
     } else {
         if (is_array($column)) {
             $c = new Column($column);
             $c->setRow($this);
             $this->columns[$c->getName()] = $c;
             return $c;
         } else {
             throw new \Exception('column must be instance of ZendX\\DataGrid\\Column or an array');
         }
     }
 }