adding zend project folders into old campcaster.
This commit is contained in:
parent
56abfaf28e
commit
7ef0c18b26
4045 changed files with 1054952 additions and 0 deletions
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Propel package.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @license MIT License
|
||||
*/
|
||||
|
||||
require_once 'AggregateColumnRelationBehavior.php';
|
||||
|
||||
/**
|
||||
* Keeps an aggregate column updated with related table
|
||||
*
|
||||
* @author François Zaninotto
|
||||
* @version $Revision: 1785 $
|
||||
* @package propel.generator.behavior.aggregate_column
|
||||
*/
|
||||
class AggregateColumnBehavior extends Behavior
|
||||
{
|
||||
|
||||
// default parameters value
|
||||
protected $parameters = array(
|
||||
'name' => null,
|
||||
'expression' => null,
|
||||
'foreign_table' => null,
|
||||
);
|
||||
|
||||
/**
|
||||
* Add the aggregate key to the current table
|
||||
*/
|
||||
public function modifyTable()
|
||||
{
|
||||
$table = $this->getTable();
|
||||
if (!$columnName = $this->getParameter('name')) {
|
||||
throw new InvalidArgumentException(sprintf('You must define a \'name\' parameter for the \'aggregate_column\' behavior in the \'%s\' table', $table->getName()));
|
||||
}
|
||||
|
||||
// add the aggregate column if not present
|
||||
if(!$this->getTable()->containsColumn($columnName)) {
|
||||
$column = $this->getTable()->addColumn(array(
|
||||
'name' => $columnName,
|
||||
'type' => 'INTEGER',
|
||||
));
|
||||
}
|
||||
|
||||
// add a behavior in the foreign table to autoupdate the aggregate column
|
||||
$foreignTable = $this->getForeignTable();
|
||||
if (!$foreignTable->hasBehavior('concrete_inheritance_parent')) {
|
||||
$relationBehavior = new AggregateColumnRelationBehavior();
|
||||
$relationBehavior->setName('aggregate_column_relation');
|
||||
$foreignKey = $this->getForeignKey();
|
||||
$relationBehavior->addParameter(array('name' => 'foreign_table', 'value' => $table->getName()));
|
||||
$relationBehavior->addParameter(array('name' => 'update_method', 'value' => 'update' . $this->getColumn()->getPhpName()));
|
||||
$foreignTable->addBehavior($relationBehavior);
|
||||
}
|
||||
}
|
||||
|
||||
public function objectMethods($builder)
|
||||
{
|
||||
if (!$foreignTableName = $this->getParameter('foreign_table')) {
|
||||
throw new InvalidArgumentException(sprintf('You must define a \'foreign_table\' parameter for the \'aggregate_column\' behavior in the \'%s\' table', $this->getTable()->getName()));
|
||||
}
|
||||
$script = '';
|
||||
$script .= $this->addObjectCompute();
|
||||
$script .= $this->addObjectUpdate();
|
||||
|
||||
return $script;
|
||||
}
|
||||
|
||||
protected function addObjectCompute()
|
||||
{
|
||||
$conditions = array();
|
||||
$bindings = array();
|
||||
foreach ($this->getForeignKey()->getColumnObjectsMapping() as $index => $columnReference) {
|
||||
$conditions[] = $columnReference['local']->getFullyQualifiedName() . ' = :p' . ($index + 1);
|
||||
$bindings[$index + 1] = $columnReference['foreign']->getPhpName();
|
||||
}
|
||||
$sql = sprintf('SELECT %s FROM %s WHERE %s',
|
||||
$this->getParameter('expression'),
|
||||
$this->getTable()->getDatabase()->getPlatform()->quoteIdentifier($this->getParameter('foreign_table')),
|
||||
implode(' AND ', $conditions)
|
||||
);
|
||||
|
||||
return $this->renderTemplate('objectCompute', array(
|
||||
'column' => $this->getColumn(),
|
||||
'sql' => $sql,
|
||||
'bindings' => $bindings,
|
||||
));
|
||||
}
|
||||
|
||||
protected function addObjectUpdate()
|
||||
{
|
||||
return $this->renderTemplate('objectUpdate', array(
|
||||
'column' => $this->getColumn(),
|
||||
));
|
||||
}
|
||||
|
||||
protected function getForeignTable()
|
||||
{
|
||||
return $this->getTable()->getDatabase()->getTable($this->getParameter('foreign_table'));
|
||||
}
|
||||
|
||||
protected function getForeignKey()
|
||||
{
|
||||
$foreignTable = $this->getForeignTable();
|
||||
// let's infer the relation from the foreign table
|
||||
$fks = $foreignTable->getForeignKeysReferencingTable($this->getTable()->getName());
|
||||
if (!$fks) {
|
||||
throw new InvalidArgumentException(sprintf('You must define a foreign key to the \'%s\' table in the \'%s\' table to enable the \'aggregate_column\' behavior', $this->getTable()->getName(), $foreignTable->getName()));
|
||||
}
|
||||
// FIXME doesn't work when more than one fk to the same table
|
||||
return array_shift($fks);
|
||||
}
|
||||
|
||||
protected function getColumn()
|
||||
{
|
||||
return $this->getTable()->getColumn($this->getParameter('name'));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,164 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Propel package.
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @license MIT License
|
||||
*/
|
||||
|
||||
require_once 'AggregateColumnRelationBehavior.php';
|
||||
|
||||
/**
|
||||
* Keeps an aggregate column updated with related table
|
||||
*
|
||||
* @author François Zaninotto
|
||||
* @version $Revision: 1785 $
|
||||
* @package propel.generator.behavior.aggregate_column
|
||||
*/
|
||||
class AggregateColumnRelationBehavior extends Behavior
|
||||
{
|
||||
|
||||
// default parameters value
|
||||
protected $parameters = array(
|
||||
'foreign_table' => '',
|
||||
'update_method' => '',
|
||||
);
|
||||
|
||||
public function postSave($builder)
|
||||
{
|
||||
$relationName = $this->getRelationName($builder);
|
||||
return "\$this->updateRelated{$relationName}(\$con);";
|
||||
}
|
||||
|
||||
// no need for a postDelete() hook, since delete() uses Query::delete(),
|
||||
// which already has a hook
|
||||
|
||||
public function objectAttributes($builder)
|
||||
{
|
||||
$relationName = $this->getRelationName($builder);
|
||||
return "protected \$old{$relationName};
|
||||
";
|
||||
}
|
||||
|
||||
public function objectMethods($builder)
|
||||
{
|
||||
return $this->addObjectUpdateRelated($builder);
|
||||
}
|
||||
|
||||
protected function addObjectUpdateRelated($builder)
|
||||
{
|
||||
$relationName = $this->getRelationName($builder);
|
||||
$updateMethodName = $this->getParameter('update_method');
|
||||
return $this->renderTemplate('objectUpdateRelated', array(
|
||||
'relationName' => $relationName,
|
||||
'variableName' => self::lcfirst($relationName),
|
||||
'updateMethodName' => $this->getParameter('update_method'),
|
||||
));
|
||||
}
|
||||
|
||||
public function objectFilter(&$script, $builder)
|
||||
{
|
||||
$relationName = $this->getRelationName($builder);
|
||||
$relatedClass = $this->getForeignTable()->getPhpName();
|
||||
$search = " public function set{$relationName}({$relatedClass} \$v = null)
|
||||
{";
|
||||
$replace = $search . "
|
||||
// aggregate_column_relation behavior
|
||||
if (null !== \$this->a{$relationName} && \$v !== \$this->a{$relationName}) {
|
||||
\$this->old{$relationName} = \$this->a{$relationName};
|
||||
}";
|
||||
$script = str_replace($search, $replace, $script);
|
||||
}
|
||||
|
||||
public function preUpdateQuery($builder)
|
||||
{
|
||||
return $this->getFindRelated($builder);
|
||||
}
|
||||
|
||||
public function preDeleteQuery($builder)
|
||||
{
|
||||
return $this->getFindRelated($builder);
|
||||
}
|
||||
|
||||
protected function getFindRelated($builder)
|
||||
{
|
||||
$relationName = $this->getRelationName($builder);
|
||||
return "\$this->findRelated{$relationName}s(\$con);";
|
||||
}
|
||||
|
||||
public function postUpdateQuery($builder)
|
||||
{
|
||||
return $this->getUpdateRelated($builder);
|
||||
}
|
||||
|
||||
public function postDeleteQuery($builder)
|
||||
{
|
||||
return $this->getUpdateRelated($builder);
|
||||
}
|
||||
|
||||
protected function getUpdateRelated($builder)
|
||||
{
|
||||
$relationName = $this->getRelationName($builder);
|
||||
return "\$this->updateRelated{$relationName}s(\$con);";
|
||||
}
|
||||
|
||||
public function queryMethods($builder)
|
||||
{
|
||||
$script = '';
|
||||
$script .= $this->addQueryFindRelated($builder);
|
||||
$script .= $this->addQueryUpdateRelated($builder);
|
||||
|
||||
return $script;
|
||||
}
|
||||
|
||||
protected function addQueryFindRelated($builder)
|
||||
{
|
||||
$foreignKey = $this->getForeignKey();
|
||||
$relationName = $this->getRelationName($builder);
|
||||
return $this->renderTemplate('queryFindRelated', array(
|
||||
'foreignTable' => $this->getForeignTable(),
|
||||
'relationName' => $relationName,
|
||||
'variableName' => self::lcfirst($relationName),
|
||||
'foreignQueryName' => $foreignKey->getForeignTable()->getPhpName() . 'Query',
|
||||
'refRelationName' => $builder->getRefFKPhpNameAffix($foreignKey),
|
||||
));
|
||||
}
|
||||
|
||||
protected function addQueryUpdateRelated($builder)
|
||||
{
|
||||
$relationName = $this->getRelationName($builder);
|
||||
return $this->renderTemplate('queryUpdateRelated', array(
|
||||
'relationName' => $relationName,
|
||||
'variableName' => self::lcfirst($relationName),
|
||||
'updateMethodName' => $this->getParameter('update_method'),
|
||||
));
|
||||
}
|
||||
|
||||
protected function getForeignTable()
|
||||
{
|
||||
return $this->getTable()->getDatabase()->getTable($this->getParameter('foreign_table'));
|
||||
}
|
||||
|
||||
protected function getForeignKey()
|
||||
{
|
||||
$foreignTable = $this->getForeignTable();
|
||||
// let's infer the relation from the foreign table
|
||||
$fks = $this->getTable()->getForeignKeysReferencingTable($foreignTable->getName());
|
||||
// FIXME doesn't work when more than one fk to the same table
|
||||
return array_shift($fks);
|
||||
}
|
||||
|
||||
protected function getRelationName($builder)
|
||||
{
|
||||
return $builder->getFKPhpNameAffix($this->getForeignKey());
|
||||
}
|
||||
|
||||
protected static function lcfirst($input)
|
||||
{
|
||||
// no lcfirst in php<5.3...
|
||||
$input[0] = strtolower($input[0]);
|
||||
return $input;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
|
||||
/**
|
||||
* Computes the value of the aggregate column <?php echo $column->getName() ?>
|
||||
*
|
||||
* @param PropelPDO $con A connection object
|
||||
*
|
||||
* @return mixed The scalar result from the aggregate query
|
||||
*/
|
||||
public function compute<?php echo $column->getPhpName() ?>(PropelPDO $con)
|
||||
{
|
||||
$stmt = $con->prepare('<?php echo $sql ?>');
|
||||
<?php foreach ($bindings as $key => $binding): ?>
|
||||
$stmt->bindValue(':p<?php echo $key ?>', $this->get<?php echo $binding ?>());
|
||||
<?php endforeach; ?>
|
||||
$stmt->execute();
|
||||
return $stmt->fetchColumn();
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
/**
|
||||
* Updates the aggregate column <?php echo $column->getName() ?>
|
||||
*
|
||||
* @param PropelPDO $con A connection object
|
||||
*/
|
||||
public function update<?php echo $column->getPhpName() ?>(PropelPDO $con)
|
||||
{
|
||||
$this->set<?php echo $column->getPhpName() ?>($this->compute<?php echo $column->getPhpName() ?>($con));
|
||||
$this->save($con);
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
/**
|
||||
* Update the aggregate column in the related <?php echo $relationName ?> object
|
||||
*
|
||||
* @param PropelPDO $con A connection object
|
||||
*/
|
||||
protected function updateRelated<?php echo $relationName ?>(PropelPDO $con)
|
||||
{
|
||||
if ($<?php echo $variableName ?> = $this->get<?php echo $relationName ?>()) {
|
||||
$<?php echo $variableName ?>-><?php echo $updateMethodName ?>($con);
|
||||
}
|
||||
if ($this->old<?php echo $relationName ?>) {
|
||||
$this->old<?php echo $relationName ?>-><?php echo $updateMethodName ?>($con);
|
||||
$this->old<?php echo $relationName ?> = null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
|
||||
/**
|
||||
* Finds the related <?php echo $foreignTable->getPhpName() ?> objects and keep them for later
|
||||
*
|
||||
* @param PropelPDO $con A connection object
|
||||
*/
|
||||
protected function findRelated<?php echo $relationName ?>s($con)
|
||||
{
|
||||
$criteria = clone $this;
|
||||
if ($this->useAliasInSQL) {
|
||||
$alias = $this->getModelAlias();
|
||||
$criteria->removeAlias($alias);
|
||||
} else {
|
||||
$alias = '';
|
||||
}
|
||||
$this-><?php echo $variableName ?>s = <?php echo $foreignQueryName ?>::create()
|
||||
->join<?php echo $refRelationName ?>($alias)
|
||||
->mergeWith($criteria)
|
||||
->find($con);
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
protected function updateRelated<?php echo $relationName ?>s($con)
|
||||
{
|
||||
foreach ($this-><?php echo $variableName ?>s as $<?php echo $variableName ?>) {
|
||||
$<?php echo $variableName ?>-><?php echo $updateMethodName ?>($con);
|
||||
}
|
||||
$this-><?php echo $variableName ?>s = array();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue