/** * Add code in ObjectBuilder::preSave * * @return string The code to put at the hook */ public function preSave(PHP5ObjectBuilder $builder) { $const = $builder->getColumnConstant($this->getColumnForParameter('slug_column')); $pattern = $this->getParameter('slug_pattern'); $script = "\nif (\$this->isColumnModified({$const}) && \$this->{$this->getColumnGetter()}()) {\n \$this->{$this->getColumnSetter()}(\$this->makeSlugUnique(\$this->{$this->getColumnGetter()}()));"; if ($pattern && false === $this->booleanValue($this->getParameter('permanent'))) { $script .= "\n} elseif ("; $count = preg_match_all('/{([a-zA-Z]+)}/', $pattern, $matches, PREG_PATTERN_ORDER); foreach ($matches[1] as $key => $match) { $columnName = $this->underscore(ucfirst($match)); $column = $this->getTable()->getColumn($columnName); if (null == $column && $this->getTable()->hasBehavior('symfony_i18n')) { $i18n = $this->getTable()->getBehavior('symfony_i18n'); $column = $i18n->getI18nTable()->getColumn($columnName); } if (null == $column) { throw new \InvalidArgumentException(sprintf('The pattern %s is invalid the column %s is not found', $pattern, $match)); } $columnConst = $builder->getColumnConstant($column); $script .= "\$this->isColumnModified({$columnConst})" . ($key < $count - 1 ? " || " : ""); } $script .= ") {\n \$this->{$this->getColumnSetter()}(\$this->createSlug());"; } if (null == $pattern && false === $this->booleanValue($this->getParameter('permanent'))) { $script .= "\n} else {\n \$this->{$this->getColumnSetter()}(\$this->createSlug());\n}"; } else { $script .= "\n} elseif (!\$this->{$this->getColumnGetter()}()) {\n \$this->{$this->getColumnSetter()}(\$this->createSlug());\n}"; } return $script; }
protected function addGetAllVersions(&$script) { $versionTable = $this->behavior->getVersionTable(); $versionARClassname = $this->builder->getNewStubObjectBuilder($versionTable)->getClassname(); $versionForeignColumn = $versionTable->getColumn($this->behavior->getParameter('version_column')); $fks = $versionTable->getForeignKeysReferencingTable($this->table->getName()); $relCol = $this->builder->getRefFKPhpNameAffix($fks[0], $plural = true); $script .= "\n/**\n * Gets all the versions of this object, in incremental order\n *\n * @param PropelPDO \$con the connection to use\n *\n * @return PropelObjectCollection A list of {$versionARClassname} objects\n */\npublic function getAllVersions(\$con = null)\n{\n \$criteria = new Criteria();\n \$criteria->addAscendingOrderByColumn({$this->builder->getColumnConstant($versionForeignColumn)});\n\n return \$this->get{$relCol}(\$criteria, \$con);\n}\n"; }