/**
  * @param ObjectBuilder $builder
  * @param string        $script
  * @param Column        $column
  */
 protected function appendAddVersionMethod(ObjectBuilder $builder, &$script, $column)
 {
     $columnPhpName = $column->getPhpName();
     $methodName = "add{$columnPhpName}Version";
     $logTable = $this->getLogTable($column);
     $logTableName = $logTable->getName();
     $logARClassName = $builder->getClassNameFromBuilder($builder->getNewStubObjectBuilder($logTable));
     $logARQueryName = $builder->getNewStubQueryBuilder($logTable)->getFullyQualifiedClassName();
     $varName = lcfirst($column->getPhpName());
     $script .= "\n/**\n * @return {$logARClassName}|false model instance of saved log ({$logTableName}) or false if nothing was changed.\n */\npublic function {$methodName}()\n{\n    if (!isset(\$this->changeLoggerTracker['{$varName}'])) {\n        return false;\n    }\n\n    \$log = new {$logARClassName}();";
     foreach ($this->getTable()->getPrimaryKey() as $col) {
         $script .= "\n    \$log->set" . $col->getPhpName() . "(\$this->get" . $col->getPhpName() . "());";
     }
     $script .= "\n    \$log->set" . $column->getPhpName() . "(\$this->changeLoggerTracker['{$varName}']);";
     if ('true' === $this->getParameter('created_at')) {
         $createdAtColumn = $logTable->getColumn($this->getParameter('created_at_column'));
         $script .= "\n    \$log->set{$createdAtColumn->getPhpName()}(time());\n";
     }
     if ('true' === $this->getParameter('created_by')) {
         $createdByColumn = $logTable->getColumn($this->getParameter('created_by_column'));
         $methodGetName = 'get' . $column->getPhpName() . 'ChangeBy';
         $script .= "\n    \$log->set{$createdByColumn->getPhpName()}(\$this->{$methodGetName}());\n";
     }
     if ('true' === $this->getParameter('comment')) {
         $commentColumn = $logTable->getColumn($this->getParameter('comment_column'));
         $methodGetName = 'get' . $column->getPhpName() . 'ChangeComment';
         $script .= "\n    \$log->set{$commentColumn->getPhpName()}(\$this->{$methodGetName}());\n";
     }
     $script .= "\n    \$lastVersion = {$logARQueryName}::create()\n        ->filterByOrigin(\$this)\n        ->orderByVersion('desc')\n        ->findOne();\n\n    \$log->setVersion(\$lastVersion ? \$lastVersion->getVersion() + 1 : 1);\n    \$log->save();\n\n    \$this->changeLoggerTracker['{$varName}'] = \$this->get{$column->getPhpName()}();\n    return \$log;\n}\n";
 }
 /**
  * @param ObjectBuilder $builder
  *
  * @return string
  */
 public function objectMethods(ObjectBuilder $builder)
 {
     if ($this->behavior->hasSnapshotClass()) {
         $snapshotClass = $this->behavior->getParameter(SnapshottableBehavior::PARAMETER_SNAPSHOT_CLASS);
         $builder->declareClass($snapshotClass);
     } else {
         $snapshotTable = $this->behavior->getSnapshotTable();
         $stubObjectBuilder = $builder->getNewStubObjectBuilder($snapshotTable);
         $builder->declareClassFromBuilder($stubObjectBuilder);
     }
     $script = '';
     $script .= $this->addSnapshot($builder);
     return $script;
 }
Ejemplo n.º 3
0
 /**
  * Validates the current table to make sure that it won't
  * result in generated code that will not parse.
  *
  * This method may emit warnings for code which may cause problems
  * and will throw exceptions for errors that will definitely cause
  * problems.
  */
 protected function validateModel()
 {
     parent::validateModel();
     $table = $this->getTable();
     // Check to see whether any generated foreign key names
     // will conflict with column names.
     $colPhpNames = array();
     $fkPhpNames = array();
     foreach ($table->getColumns() as $col) {
         $colPhpNames[] = $col->getPhpName();
     }
     foreach ($table->getForeignKeys() as $fk) {
         $fkPhpNames[] = $this->getFKPhpNameAffix($fk, $plural = false);
     }
     $intersect = array_intersect($colPhpNames, $fkPhpNames);
     if (!empty($intersect)) {
         throw new EngineException("One or more of your column names for [" . $table->getName() . "] table conflict with foreign key names (" . implode(", ", $intersect) . ")");
     }
     // Check foreign keys to see if there are any foreign keys that
     // are also matched with an inversed referencing foreign key
     // (this is currently unsupported behavior)
     // see: http://propel.phpdb.org/trac/ticket/549
     foreach ($table->getForeignKeys() as $fk) {
         if ($fk->isMatchedByInverseFK()) {
             throw new EngineException("The 1:1 relationship expressed by foreign key " . $fk->getName() . " is defined in both directions; Propel does not currently support this (if you must have both foreign key constraints, consider adding this constraint with a custom SQL file.)");
         }
     }
 }
 /**
  * @param ObjectBuilder $builder
  * @return string
  */
 protected function addObjectCompute(ObjectBuilder $builder)
 {
     $conditions = array();
     if ($this->getParameter('condition')) {
         $conditions[] = $this->getParameter('condition');
     }
     $bindings = array();
     $database = $this->getTable()->getDatabase();
     foreach ($this->getForeignKey()->getColumnObjectsMapping() as $index => $columnReference) {
         $conditions[] = $columnReference['local']->getFullyQualifiedName() . ' = :p' . ($index + 1);
         $bindings[$index + 1] = $columnReference['foreign']->getPhpName();
     }
     $tableName = $database->getTablePrefix() . $this->getParameter('foreign_table');
     if ($database->getPlatform()->supportsSchemas() && $this->getParameter('foreign_schema')) {
         $tableName = $this->getParameter('foreign_schema') . $database->getPlatform()->getSchemaDelimiter() . $tableName;
     }
     $sql = sprintf('SELECT %s FROM %s WHERE %s', $this->getParameter('expression'), $builder->getTable()->quoteIdentifier($tableName), implode(' AND ', $conditions));
     return $this->renderTemplate('objectCompute', array('column' => $this->getColumn(), 'sql' => $sql, 'bindings' => $bindings));
 }
 /**
  * @param ObjectBuilder $builder
  * @return string
  */
 protected function addObjectCompute(ObjectBuilder $builder)
 {
     $conditions = array();
     if ($this->getParameter('condition')) {
         $conditions[] = $this->getParameter('condition');
     }
     $bindings = array();
     $database = $this->getTable()->getDatabase();
     if ($this->getForeignKey()->isPolymorphic()) {
         throw new \InvalidArgumentException('AggregateColumnBehavior does not work with polymorphic relations.');
     }
     foreach ($this->getForeignKey()->getMapping() as $index => $mapping) {
         list($localColumn, $foreignColumn) = $mapping;
         $conditions[] = $localColumn->getFullyQualifiedName() . ' = :p' . ($index + 1);
         $bindings[$index + 1] = $foreignColumn->getPhpName();
     }
     $tableName = $database->getTablePrefix() . $this->getParameter('foreign_table');
     if ($database->getPlatform()->supportsSchemas() && $this->getParameter('foreign_schema')) {
         $tableName = $this->getParameter('foreign_schema') . $database->getPlatform()->getSchemaDelimiter() . $tableName;
     }
     $sql = sprintf('SELECT %s FROM %s WHERE %s', $this->getParameter('expression'), $builder->getTable()->quoteIdentifier($tableName), implode(' AND ', $conditions));
     return $this->renderTemplate('objectCompute', array('column' => $this->getColumn(), 'sql' => $sql, 'bindings' => $bindings));
 }
Ejemplo n.º 6
0
 protected function addFindOneBySlug(&$script)
 {
     $script .= "\n/**\n * Find one object based on its slug\n *\n * @param     string \$slug The value to use as filter.\n * @param     ConnectionInterface \$con The optional connection object\n *\n * @return    " . $this->builder->getObjectClassName() . " the result, formatted by the current formatter\n */\npublic function findOneBySlug(\$slug, \$con = null)\n{\n    return \$this->filterBySlug(\$slug)->findOne(\$con);\n}\n";
 }
Ejemplo n.º 7
0
 public function getDefaultValueString(Column $col)
 {
     return parent::getDefaultValueString($col);
 }
 /**
  * @param ObjectBuilder $builder
  *
  * @return array
  */
 public function getSnapshotTablePhpName(ObjectBuilder $builder)
 {
     if ($this->hasSnapshotClass()) {
         return $this->getParameter(self::PARAMETER_SNAPSHOT_CLASS);
     }
     return $builder->getNewStubObjectBuilder($this->snapshotTable)->getClassname();
 }
Ejemplo n.º 9
0
 /**
  * @param \Propel\Generator\Model\Table $table
  */
 public function __construct(Table $table)
 {
     parent::__construct($table);
     Environment::initialize();
 }
 public function objectAttributes(ObjectBuilder $builder)
 {
     $tableName = $this->table->getName();
     $objectClassName = $builder->getObjectClassName();
     $script = "\n/**\n * Queries to be executed in the save transaction\n * @var        array\n */\nprotected \$nestedSetQueries = array();\n\n/**\n * Internal cache for children nodes\n * @var        null|ObjectCollection\n */\nprotected \$collNestedSetChildren = null;\n\n/**\n * Internal cache for parent node\n * @var        null|{$objectClassName}\n */\nprotected \$aNestedSetParent = null;\n\n/**\n * Left column for the set\n */\nconst LEFT_COL = '" . $tableName . '.' . $this->behavior->getColumnConstant('left_column') . "';\n\n/**\n * Right column for the set\n */\nconst RIGHT_COL = '" . $tableName . '.' . $this->behavior->getColumnConstant('right_column') . "';\n\n/**\n * Level column for the set\n */\nconst LEVEL_COL = '" . $tableName . '.' . $this->behavior->getColumnConstant('level_column') . "';\n";
     if ($this->behavior->useScope()) {
         $script .= "\n/**\n * Scope column for the set\n */\nconst SCOPE_COL = '" . $tableName . '.' . $this->behavior->getColumnConstant('scope_column') . "';\n";
     }
     return $script;
 }
 /**
  * Override method to return child package, if specified.
  * @return     string
  */
 public function getPackage()
 {
     return $this->child->getPackage() ? $this->child->getPackage() : parent::getPackage();
 }