/**
  * Return the value editor for this value field
  *
  * @param string $name The field name to use in the editor
  * @return string The HTML for the editor
  */
 public function getValueEditor($name)
 {
     if ($this->column->isMulti()) {
         return $this->column->getType()->multiValueEditor($name, $this->rawvalue);
     } else {
         return $this->column->getType()->valueEditor($name, $this->rawvalue);
     }
 }
示例#2
0
 /**
  * @api
  * @since 1.0.0
  *
  * @param DataTable\Column $column
  * @param integer|string|\DateTime $value
  * @param string $label
  * @throws InvalidArgumentException if the supplied value is not of the supplied column's data type
  * @throws InvalidArgumentException if the supplied label is not a string
  */
 public function __construct(Column $column, $value, $label = '')
 {
     $this->column = $column;
     if (!$this->column->isValueValidType($value)) {
         throw new \InvalidArgumentException("'{$value}' is not of type '{$column->getType()}'!");
     }
     if (!is_string($label)) {
         throw new \InvalidArgumentException("The cell label must be a string!");
     }
     $this->value = $value;
     $this->label = $label;
 }
示例#3
0
 public static function compareColumns(Column $fromColumn, Column $toColumn)
 {
     $changedProperties = array();
     // compare column types
     $fromDomain = $fromColumn->getDomain();
     $toDomain = $toColumn->getDomain();
     if ($fromDomain->getType() != $toDomain->getType()) {
         if ($toColumn->getType() == PropelTypes::ENUM && $toColumn->getPhpType() == 'string') {
             // use MySQL native ENUM support
         } else {
             $changedProperties['type'] = array($fromDomain->getType(), $toDomain->getType());
         }
     }
     if ($fromDomain->getScale() != $toDomain->getScale()) {
         $changedProperties['scale'] = array($fromDomain->getScale(), $toDomain->getScale());
     }
     if ($fromDomain->getSize() != $toDomain->getSize()) {
         $changedProperties['size'] = array($fromDomain->getSize(), $toDomain->getSize());
     }
     if (strtoupper($fromDomain->getSqlType()) != strtoupper($toDomain->getSqlType())) {
         $changedProperties['sqlType'] = array($fromDomain->getSqlType(), $toDomain->getSqlType());
     }
     if ($fromColumn->isNotNull() != $toColumn->isNotNull()) {
         $changedProperties['notNull'] = array($fromColumn->isNotNull(), $toColumn->isNotNull());
     }
     // compare column default value
     $fromDefaultValue = $fromColumn->getDefaultValue();
     $toDefaultValue = $toColumn->getDefaultValue();
     if ($fromDefaultValue && !$toDefaultValue) {
         $changedProperties['defaultValueType'] = array($fromDefaultValue->getType(), null);
         $changedProperties['defaultValueValue'] = array($fromDefaultValue->getValue(), null);
     } elseif (!$fromDefaultValue && $toDefaultValue) {
         $changedProperties['defaultValueType'] = array(null, $toDefaultValue->getType());
         $changedProperties['defaultValueValue'] = array(null, $toDefaultValue->getValue());
     } elseif ($fromDefaultValue && $toDefaultValue) {
         if (!$fromDefaultValue->equals($toDefaultValue)) {
             if ($fromDefaultValue->getType() != $toDefaultValue->getType()) {
                 $changedProperties['defaultValueType'] = array($fromDefaultValue->getType(), $toDefaultValue->getType());
             }
             if ($fromDefaultValue->getValue() != $toDefaultValue->getValue()) {
                 $changedProperties['defaultValueValue'] = array($fromDefaultValue->getValue(), $toDefaultValue->getValue());
             }
         }
     }
     if ($fromColumn->isAutoIncrement() != $toColumn->isAutoIncrement()) {
         $changedProperties['autoIncrement'] = array($fromColumn->isAutoIncrement(), $toColumn->isAutoIncrement());
     }
     return $changedProperties;
 }
示例#4
0
 /**
  * Returns the difference between the fields $field1 and $field2.
  *
  * If there are differences this method returns $field2, otherwise the
  * boolean false.
  *
  * @param Column $column1
  * @param Column $column2
  *
  * @return array
  */
 public function diffColumn(Column $column1, Column $column2)
 {
     $changedProperties = array();
     if ($column1->getType() != $column2->getType()) {
         $changedProperties[] = 'type';
     }
     if ($column1->getNotnull() != $column2->getNotnull()) {
         $changedProperties[] = 'notnull';
     }
     if ($column1->getDefault() != $column2->getDefault()) {
         $changedProperties[] = 'default';
     }
     if ($column1->getUnsigned() != $column2->getUnsigned()) {
         $changedProperties[] = 'unsigned';
     }
     if ($column1->getType() instanceof \Doctrine\DBAL\Types\StringType) {
         if ($column1->getLength() != $column2->getLength()) {
             $changedProperties[] = 'length';
         }
         if ($column1->getFixed() != $column2->getFixed()) {
             $changedProperties[] = 'fixed';
         }
     }
     if ($column1->getType() instanceof \Doctrine\DBAL\Types\DecimalType) {
         if ($column1->getPrecision() != $column2->getPrecision()) {
             $changedProperties[] = 'precision';
         }
         if ($column1->getScale() != $column2->getScale()) {
             $changedProperties[] = 'scale';
         }
     }
     if ($column1->getAutoincrement() != $column2->getAutoincrement()) {
         $changedProperties[] = 'autoincrement';
     }
     return $changedProperties;
 }
示例#5
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');
 }
示例#6
0
 /**
  * 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());
     // pdo_sqlsrv driver requires the use of PDOStatement::bindColumn() or a hex string will be returned
     if ($col->getType() === PropelTypes::BLOB && $platform instanceof SqlsrvPlatform) {
         $script .= "\n\t\t\$c = \$this->buildPkeyCriteria();\n\t\t\$c->addSelectColumn(" . $this->getColumnConstant($col) . ");\n\t\ttry {\n\t\t\t\$row = array(0 => null);\n\t\t\t\$stmt = " . $this->getPeerClassname() . "::doSelectStmt(\$c, \$con);\n\t\t\t\$stmt->bindColumn(1, \$row[0], PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);\n\t\t\t\$stmt->fetch(PDO::FETCH_BOUND);\n\t\t\t\$stmt->closeCursor();";
     } else {
         $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 && $platform 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}";
 }
示例#7
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()));
 }
 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
 /**
  * Returns the difference between the fields $field1 and $field2.
  *
  * If there are differences this method returns $field2, otherwise the
  * boolean false.
  *
  * @param Column $column1
  * @param Column $column2
  *
  * @return array
  */
 public function diffColumn(Column $column1, Column $column2)
 {
     $changedProperties = array();
     if ($column1->getType() != $column2->getType()) {
         $changedProperties[] = 'type';
     }
     if ($column1->getNotnull() != $column2->getNotnull()) {
         $changedProperties[] = 'notnull';
     }
     if ($column1->getDefault() != $column2->getDefault()) {
         $changedProperties[] = 'default';
     }
     if ($column1->getUnsigned() != $column2->getUnsigned()) {
         $changedProperties[] = 'unsigned';
     }
     if ($column1->getType() instanceof \Doctrine\DBAL\Types\StringType) {
         // check if value of length is set at all, default value assumed otherwise.
         $length1 = $column1->getLength() ?: 255;
         $length2 = $column2->getLength() ?: 255;
         if ($length1 != $length2) {
             $changedProperties[] = 'length';
         }
         if ($column1->getFixed() != $column2->getFixed()) {
             $changedProperties[] = 'fixed';
         }
     }
     if ($column1->getType() instanceof \Doctrine\DBAL\Types\DecimalType) {
         if (($column1->getPrecision() ?: 10) != ($column2->getPrecision() ?: 10)) {
             $changedProperties[] = 'precision';
         }
         if ($column1->getScale() != $column2->getScale()) {
             $changedProperties[] = 'scale';
         }
     }
     if ($column1->getAutoincrement() != $column2->getAutoincrement()) {
         $changedProperties[] = 'autoincrement';
     }
     // only allow to delete comment if its set to '' not to null.
     if ($column1->getComment() !== null && $column1->getComment() != $column2->getComment()) {
         $changedProperties[] = 'comment';
     }
     $options1 = $column1->getCustomSchemaOptions();
     $options2 = $column2->getCustomSchemaOptions();
     $commonKeys = array_keys(array_intersect_key($options1, $options2));
     foreach ($commonKeys as $key) {
         if ($options1[$key] !== $options2[$key]) {
             $changedProperties[] = $key;
         }
     }
     $diffKeys = array_keys(array_diff_key($options1, $options2) + array_diff_key($options2, $options1));
     $changedProperties = array_merge($changedProperties, $diffKeys);
     return $changedProperties;
 }
示例#10
0
 /**
  * Returns the SQL for the default value of a Column object
  * @return     string
  */
 public function getColumnDefaultValueDDL(Column $col)
 {
     $default = '';
     $defaultValue = $col->getDefaultValue();
     if ($defaultValue !== null) {
         $default .= 'DEFAULT ';
         if ($defaultValue->isExpression()) {
             $default .= $defaultValue->getValue();
         } else {
             if ($col->isTextType()) {
                 $default .= $this->quote($defaultValue->getValue());
             } elseif ($col->getType() == PropelTypes::BOOLEAN || $col->getType() == PropelTypes::BOOLEAN_EMU) {
                 $default .= $this->getBooleanString($defaultValue->getValue());
             } elseif ($col->getType() == PropelTypes::ENUM) {
                 $default .= array_search($defaultValue->getValue(), $col->getValueSet());
             } else {
                 $default .= $defaultValue->getValue();
             }
         }
     }
     return $default;
 }
示例#11
0
 /**
  * Adds the body of the temporal accessor
  * @param      string &$script The script will be modified in this method.
  * @param      Column $col The current column.
  * @see        addTemporalAccessor
  **/
 protected function addTemporalAccessorBody(&$script, Column $col)
 {
     $cfc = $col->getPhpName();
     $clo = strtolower($col->getName());
     $useDateTime = $this->getBuildProperty('useDateTimeClass');
     $dateTimeClass = $this->getBuildProperty('dateTimeClass');
     if (!$dateTimeClass) {
         $dateTimeClass = 'DateTime';
     }
     $defaultfmt = null;
     // Default date/time formatter strings are specified in build.properties
     if ($col->getType() === PropelTypes::DATE) {
         $defaultfmt = $this->getBuildProperty('defaultDateFormat');
     } elseif ($col->getType() === PropelTypes::TIME) {
         $defaultfmt = $this->getBuildProperty('defaultTimeFormat');
     } elseif ($col->getType() === PropelTypes::TIMESTAMP) {
         $defaultfmt = $this->getBuildProperty('defaultTimeStampFormat');
     }
     if (empty($defaultfmt)) {
         $defaultfmt = null;
     }
     $handleMysqlDate = false;
     if ($this->getPlatform() instanceof MysqlPlatform) {
         if ($col->getType() === PropelTypes::TIMESTAMP) {
             $handleMysqlDate = true;
             $mysqlInvalidDateString = '0000-00-00 00:00:00';
         } elseif ($col->getType() === PropelTypes::DATE) {
             $handleMysqlDate = true;
             $mysqlInvalidDateString = '0000-00-00';
         }
         // 00:00:00 is a valid time, so no need to check for that.
     }
     if ($col->isLazyLoad()) {
         $script .= "\r\n\t\tif (!\$this->" . $clo . "_isLoaded && \$this->{$clo} === null && !\$this->isNew()) {\r\n\t\t\t\$this->load{$cfc}(\$con);\r\n\t\t}\r\n";
     }
     $script .= "\r\n\t\tif (\$this->{$clo} === null) {\r\n\t\t\treturn null;\r\n\t\t}\r\n\r\n";
     if ($handleMysqlDate) {
         $script .= "\r\n\t\tif (\$this->{$clo} === '{$mysqlInvalidDateString}') {\r\n\t\t\t// while technically this is not a default value of NULL,\r\n\t\t\t// this seems to be closest in meaning.\r\n\t\t\treturn null;\r\n\t\t} else {\r\n\t\t\ttry {\r\n\t\t\t\t\$dt = new {$dateTimeClass}(\$this->{$clo});\r\n\t\t\t} catch (Exception \$x) {\r\n\t\t\t\tthrow new PropelException(\"Internally stored date/time/timestamp value could not be converted to {$dateTimeClass}: \" . var_export(\$this->{$clo}, true), \$x);\r\n\t\t\t}\r\n\t\t}\r\n";
     } else {
         $script .= "\r\n\r\n\t\ttry {\r\n\t\t\t\$dt = new {$dateTimeClass}(\$this->{$clo});\r\n\t\t} catch (Exception \$x) {\r\n\t\t\tthrow new PropelException(\"Internally stored date/time/timestamp value could not be converted to {$dateTimeClass}: \" . var_export(\$this->{$clo}, true), \$x);\r\n\t\t}\r\n";
     }
     // if handleMyqlDate
     $script .= "\r\n\t\tif (\$format === null) {";
     if ($useDateTime) {
         $script .= "\r\n\t\t\t// Because propel.useDateTimeClass is TRUE, we return a {$dateTimeClass} object.\r\n\t\t\treturn \$dt;";
     } else {
         $script .= "\r\n\t\t\t// We cast here to maintain BC in API; obviously we will lose data if we're dealing with pre-/post-epoch dates.\r\n\t\t\treturn (int) \$dt->format('U');";
     }
     $script .= "\r\n\t\t} elseif (strpos(\$format, '%') !== false) {\r\n\t\t\treturn strftime(\$format, \$dt->format('U'));\r\n\t\t} else {\r\n\t\t\treturn \$dt->format(\$format);\r\n\t\t}";
 }
示例#12
0
 /**
  * Adds a date/time/timestamp getter method.
  * @param      string &$script The script will be modified in this method.
  * @param      Column $col The current column.
  * @see        parent::addColumnAccessors()
  */
 protected function addTemporalAccessor(&$script, $col)
 {
     $cfc = $col->getPhpName();
     $clo = strtolower($col->getName());
     // these default values are based on the Creole defaults
     // the date and time default formats are locale-sensitive
     if ($col->getType() === PropelTypes::DATE) {
         $defaultfmt = $this->getBuildProperty('defaultDateFormat');
     } elseif ($col->getType() === PropelTypes::TIME) {
         $defaultfmt = $this->getBuildProperty('defaultTimeFormat');
     } elseif ($col->getType() === PropelTypes::TIMESTAMP) {
         $defaultfmt = $this->getBuildProperty('defaultTimeStampFormat');
     }
     // if the default format property was an empty string, then we'll set it
     // to NULL, which will return the "native" integer timestamp
     if (empty($defaultfmt)) {
         $defaultfmt = null;
     }
     $script .= "\n\t/**\n\t * Get the [optionally formatted] [{$clo}] column value.\n\t * " . $col->getDescription() . "\n\t * @param      string \$format The date/time format string (either date()-style or strftime()-style).\n\t *\t\t\t\t\t\t\tIf format is NULL, then the integer unix timestamp will be returned.\n\t * @return     mixed Formatted date/time value as string or integer unix timestamp (if format is NULL).\n\t * @throws     PropelException - if unable to convert the date/time to timestamp.\n\t */\n\tpublic function get{$cfc}(\$format = " . var_export($defaultfmt, true) . "";
     if ($col->isLazyLoad()) {
         $script .= ", \$con = null";
     }
     $script .= ")\n\t{\n";
     if ($col->isLazyLoad()) {
         $script .= "\n\t\tif (!\$this->" . $clo . "_isLoaded && \$this->{$clo} === null && !\$this->isNew()) {\n\t\t\t\$this->load{$cfc}(\$con);\n\t\t}\n";
     }
     $script .= "\n\t\tif (\$this->{$clo} === null || \$this->{$clo} === '') {\n\t\t\treturn null;\n\t\t} elseif (!is_int(\$this->{$clo})) {\n\t\t\t// a non-timestamp value was set externally, so we convert it\n\t\t\t\$ts = strtotime(\$this->{$clo});\n\t\t\tif (\$ts === -1 || \$ts === false) { // in PHP 5.1 return value changes to FALSE\n\t\t\t\tthrow new PropelException(\"Unable to parse value of [{$clo}] as date/time value: \" . var_export(\$this->{$clo}, true));\n\t\t\t}\n\t\t} else {\n\t\t\t\$ts = \$this->{$clo};\n\t\t}\n\t\tif (\$format === null) {\n\t\t\treturn \$ts;\n\t\t} elseif (strpos(\$format, '%') !== false) {\n\t\t\treturn strftime(\$format, \$ts);\n\t\t} else {\n\t\t\treturn date(\$format, \$ts);\n\t\t}\n\t}\n";
 }
 protected function addTranslatedColumnSetter(Column $column)
 {
     $i18nTablePhpName = $this->builder->getNewStubObjectBuilder($this->behavior->getI18nTable())->getClassname();
     $tablePhpName = $this->builder->getStubObjectBuilder()->getClassname();
     $objectBuilder = $this->builder->getNewObjectBuilder($this->behavior->getI18nTable());
     $comment = '';
     $functionStatement = '';
     if ($column->getType() === PropelTypes::DATE || $column->getType() === PropelTypes::TIME || $column->getType() === PropelTypes::TIMESTAMP) {
         $objectBuilder->addTemporalMutatorComment($comment, $column);
         $objectBuilder->addMutatorOpenOpen($functionStatement, $column);
     } else {
         $objectBuilder->addMutatorComment($comment, $column);
         $objectBuilder->addMutatorOpenOpen($functionStatement, $column);
     }
     $comment = preg_replace('/^\\t/m', '', $comment);
     $comment = str_replace('@return     ' . $i18nTablePhpName, '@return     ' . $tablePhpName, $comment);
     $functionStatement = preg_replace('/^\\t/m', '', $functionStatement);
     preg_match_all('/\\$[a-z]+/i', $functionStatement, $params);
     return $this->behavior->renderTemplate('objectTranslatedColumnSetter', array('comment' => $comment, 'functionStatement' => $functionStatement, 'columnPhpName' => $column->getPhpName(), 'params' => implode(', ', $params[0])));
 }
示例#14
0
 /**
  * Returns the difference between the fields $field1 and $field2.
  *
  * If there are differences this method returns $field2, otherwise the
  * boolean false.
  *
  * @param Column $column1
  * @param Column $column2
  *
  * @return array
  */
 public function diffColumn(Column $column1, Column $column2)
 {
     $changedProperties = array();
     if ($column1->getType() != $column2->getType()) {
         $changedProperties[] = 'type';
     }
     if ($column1->getNotnull() != $column2->getNotnull()) {
         $changedProperties[] = 'notnull';
     }
     if ($column1->getDefault() != $column2->getDefault()) {
         $changedProperties[] = 'default';
     }
     if ($column1->getUnsigned() != $column2->getUnsigned()) {
         $changedProperties[] = 'unsigned';
     }
     if ($column1->getType() instanceof \Doctrine\DBAL\Types\StringType) {
         if ($column1->getLength() != $column2->getLength()) {
             $changedProperties[] = 'length';
         }
         if ($column1->getFixed() != $column2->getFixed()) {
             $changedProperties[] = 'fixed';
         }
     }
     if ($column1->getType() instanceof \Doctrine\DBAL\Types\DecimalType) {
         if ($column1->getPrecision() != $column2->getPrecision()) {
             $changedProperties[] = 'precision';
         }
         if ($column1->getScale() != $column2->getScale()) {
             $changedProperties[] = 'scale';
         }
     }
     foreach ($this->_checkColumnPlatformOptions as $optionName) {
         if ($column1->hasPlatformOption($optionName) && $column2->hasPlatformOption($optionName)) {
             if ($column1->getPlatformOption($optionName) != $column2->getPlatformOption($optionName)) {
                 $changedProperties[] = $optionName;
             }
         } else {
             if ($column1->hasPlatformOption($optionName) != $column2->hasPlatformOption($optionName)) {
                 $changedProperties[] = $optionName;
             }
         }
     }
     return $changedProperties;
 }
 public static function isQuotedType(Column $column)
 {
     return in_array($column->getType(), self::getQuotedTypes());
 }