Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removed PeerBuilder

  • Loading branch information...
commit a07adf4d2f5b44d8b9aa467ba2eba27a23dff1fc 1 parent 0e9aa89
@willdurand willdurand authored
View
11 src/EqualNestParentBehavior.php
@@ -19,8 +19,6 @@ class EqualNestParentBehavior extends Behavior
protected $queryBuilderModifier;
- protected $peerBuilderModifier;
-
protected $parameters = array(
'middle_table' => null,
);
@@ -47,13 +45,4 @@ public function getQueryBuilderModifier()
return $this->queryBuilderModifier;
}
-
- public function getPeerBuilderModifier()
- {
- if (null === $this->peerBuilderModifier) {
- $this->peerBuilderModifier = new EqualNestParentBehaviorPeerBuilderModifier($this, $this->getMiddleTable());
- }
-
- return $this->peerBuilderModifier;
- }
}
View
55 src/EqualNestParentBehaviorObjectBuilderModifier.php
@@ -106,48 +106,23 @@ public function addClearListRelatedPKs($builder)
), '/templates/parent/');
}
- public function addInitListRelatedPKs($builder)
- {
- $ucMiddleTableName = strtoupper($this->middleTable->getPhpName());
- $pluralRefTableName = $builder->getPluralizer()->getPluralForm($this->middleTable->getPhpName());
- $peerClassname = $builder->getStubPeerBuilder()->getClassname();
- $objectClassname = $builder->getStubObjectBuilder()->getClassname();
-
- $pk = $this->table->getPrimaryKey(); /** @var Column */ $pk = $pk[0];
-
- $varListRelatedPKs = "listEqualNest{$builder->getPluralizer()->getPluralForm($this->middleTable->getPhpName())}PKs";
- $varRelatedObjectsColl = "collEqualNest{$builder->getPluralizer()->getPluralForm($this->middleTable->getPhpName())}";
-
- return "
-/**
- * Initializes the list of Equal Nest $pluralRefTableName PKs.
- *
- * This will query the database for Equal Nest $pluralRefTableName relations to this {$objectClassname} object.
- * It will set the list to an empty array if the object is newly created.
- *
- * @param PropelPDO \$con
- * @return void
- */
-protected function initList{$pluralRefTableName}PKs(PropelPDO \$con = null)
-{
- if (\$con === null) {
- \$con = Propel::getConnection({$peerClassname}::DATABASE_NAME, Propel::CONNECTION_READ);
- }
-
- if (null === \$this->$varListRelatedPKs) {
- if (\$this->isNew()) {
- \$this->$varListRelatedPKs = array();
- } else {
- \$stmt = \$con->prepare($peerClassname::LIST_EQUAL_NEST_{$ucMiddleTableName}_PKs_QUERY);
- \$stmt->bindValue(':{$pk->getStudlyPhpName()}', \$this->getPrimaryKey(), PDO::PARAM_INT);
- \$stmt->execute();
+ public function addInitListRelatedPKs($builder)
+ {
+ $pk = current($this->table->getPrimaryKey());
- \$this->$varListRelatedPKs = \$stmt->fetchAll(PDO::FETCH_COLUMN);
+ return $this->behavior->renderTemplate('addInitListRelatedPKs', array(
+ 'pluralRefTableName' => $builder->getPluralizer()->getPluralForm($this->middleTable->getPhpName()),
+ 'objectClassname' => $builder->getStubObjectBuilder()->getClassname(),
+ 'peerClassname' => $builder->getStubPeerBuilder()->getClassname(),
+ 'varListRelatedPKs' => $this->getEqualNestListPksName($builder),
+ 'pkName' => $pk->getStudlyPhpName(),
+ 'tablePk' => $pk->getFullyQualifiedName(),
+ 'tableName' => $this->table->getName(),
+ 'middleTableName' => $this->middleTable->getName(),
+ 'refColumn1' => $this->middleBehavior->getReferenceColumn1()->getFullyQualifiedName(),
+ 'refColumn2' => $this->middleBehavior->getReferenceColumn2()->getFullyQualifiedName(),
+ ), '/templates/parent/');
}
- }
-}
-";
- }
public function addClearRelatedCollection($builder)
{
View
104 src/EqualNestParentBehaviorPeerBuilderModifier.php
@@ -1,104 +0,0 @@
-<?php
-
-/**
- * This file is part of the Equal Nest Behavior package.
- * For the full copyright and license information, please view the README.md
- * file that was distributed with this source code.
- *
- * @license MIT License
- */
-
-/**
- * @author Ivan Plamenov Tanev aka Crafty_Shadow @ WEBWORLD.BG <vankata.t@gmail.com>
- * @package propel.generator.behavior.equal_nest
- */
-class EqualNestParentBehaviorPeerBuilderModifier
-{
- protected $behavior, $builder, $objectClassname, $peerClassname;
-
- /** @var Table */
- protected $table;
-
- /** @var Table */
- protected $middle_table;
-
- /** @var EqualNestBehavior */
- protected $middle_behavior;
-
- public function __construct($behavior, $middle_table)
- {
- $this->behavior = $behavior;
- $this->table = $behavior->getTable();
- $this->middle_table = $middle_table;
- $this->middle_behavior = $this->middle_table->getBehavior('equal_nest');
- }
-
- protected function getParameter($key)
- {
- return $this->behavior->getParameter($key);
- }
-
- protected function getColumn($name)
- {
- return $this->behavior->getColumnForParameter($name);
- }
-
- protected function getColumnAttribute($name)
- {
- return strtolower($this->getColumn($name)->getName());
- }
-
- protected function getColumnConstant($name)
- {
- return strtoupper($this->getColumn($name)->getName());
- }
-
- protected function getColumnPhpName($name)
- {
- return $this->getColumn($name)->getPhpName();
- }
-
- protected function setBuilder($builder)
- {
- $this->builder = $builder;
- $this->objectClassname = $builder->getStubObjectBuilder()->getClassname();
- $this->peerClassname = $builder->getStubPeerBuilder()->getClassname();
- }
-
- public function staticAttributes($builder)
- {
- $this->builder = $builder;
- $tableName = $this->table->getName();
- $pks = $this->table->getPrimaryKey();
- $tablePk = $pks[0]->getFullyQualifiedName();
-
- $middleTableName = $this->middle_table->getName();
- $ucMiddleTableName = strtoupper($this->middle_table->getPhpName());
- $ref_column_1 = $this->middle_behavior->getReferenceColumn1();
- $ref_column_2 = $this->middle_behavior->getReferenceColumn2();
-
- $script = "
-/**
- * Select query to get the IDs that will be used for IN clauses to retrieve the {$this->builder->getPluralizer()->getPluralForm($this->middle_table->getPhpName())}
- */
-const LIST_EQUAL_NEST_{$ucMiddleTableName}_PKs_QUERY = '
- SELECT DISTINCT $tablePk FROM $tableName
- INNER JOIN $middleTableName ON
- $tablePk = {$ref_column_1->getFullyQualifiedName()}
- OR
- $tablePk = {$ref_column_2->getFullyQualifiedName()}
- WHERE
- $tablePk IN (
- SELECT {$ref_column_1->getFullyQualifiedName()} FROM $middleTableName WHERE {$ref_column_2->getFullyQualifiedName()} = :{$pks[0]->getStudlyPhpName()}
- )
- OR
- $tablePk IN (
- SELECT {$ref_column_2->getFullyQualifiedName()} FROM $middleTableName WHERE {$ref_column_1->getFullyQualifiedName()} = :{$pks[0]->getStudlyPhpName()}
- )
-';
-
-";
-
- return $script;
- }
-}
View
47 src/templates/parent/addInitListRelatedPKs.php
@@ -0,0 +1,47 @@
+
+/**
+ * Initializes the list of Equal Nest <?php echo $pluralRefTableName ?> PKs.
+ *
+ * This will query the database for Equal Nest <?php echo $pluralRefTableName ?> relations to this <?php echo $objectClassname ?> object.
+ * It will set the list to an empty array if the object is newly created.
+ *
+ * @param PropelPDO $con
+ */
+protected function initList<?php echo $pluralRefTableName ?>PKs(PropelPDO $con = null)
+{
+ if ($con === null) {
+ $con = Propel::getConnection(<?php echo $peerClassname ?>::DATABASE_NAME, Propel::CONNECTION_READ);
+ }
+
+ if (null === $this-><?php echo $varListRelatedPKs ?>) {
+ if ($this->isNew()) {
+ $this-><?php echo $varListRelatedPKs ?> = array();
+ } else {
+ $sql = "
+SELECT DISTINCT <?php echo $tablePk . "\n" ?>
+FROM <?php echo $tableName . "\n" ?>
+INNER JOIN <?php echo $middleTableName ?> ON
+<?php echo $tablePk ?> = <?php echo $refColumn1 . "\n" ?>
+OR
+<?php echo $tablePk ?> = <?php echo $refColumn2 . "\n" ?>
+WHERE
+<?php echo $tablePk ?> IN (
+ SELECT <?php echo $refColumn1 . "\n" ?>
+ FROM <?php echo $middleTableName . "\n" ?>
+ WHERE <?php echo $refColumn2 ?> = :<?php echo $pkName . "\n" ?>
+)
+OR
+<?php echo $tablePk ?> IN (
+ SELECT <?php echo $refColumn2 . "\n" ?>
+ FROM <?php echo $middleTableName . "\n" ?>
+ WHERE <?php echo $refColumn1 ?> = :<?php echo $pkName . "\n" ?>
+)";
+
+ $stmt = $con->prepare($sql);
+ $stmt->bindValue(':<?php echo $pkName ?>', $this->getPrimaryKey(), PDO::PARAM_INT);
+ $stmt->execute();
+
+ $this-><?php echo $varListRelatedPKs ?> = $stmt->fetchAll(PDO::FETCH_COLUMN);
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.