vendor/propel/propel/src/Propel/Runtime/ActiveQuery/ModelJoin.php line 19

Open in your IDE?
  1. <?php
  2. /**
  3.  * MIT License. This file is part of the Propel package.
  4.  * For the full copyright and license information, please view the LICENSE
  5.  * file that was distributed with this source code.
  6.  */
  7. namespace Propel\Runtime\ActiveQuery;
  8. use Propel\Runtime\Map\RelationMap;
  9. use Propel\Runtime\Map\TableMap;
  10. /**
  11.  * A ModelJoin is a Join object tied to a RelationMap object
  12.  *
  13.  * @author Francois Zaninotto (Propel)
  14.  */
  15. class ModelJoin extends Join
  16. {
  17.     /**
  18.      * @var \Propel\Runtime\Map\RelationMap
  19.      */
  20.     protected $relationMap;
  21.     /**
  22.      * @var \Propel\Runtime\Map\TableMap|null
  23.      */
  24.     protected $tableMap;
  25.     /**
  26.      * @var \Propel\Runtime\ActiveQuery\ModelJoin|null
  27.      */
  28.     protected $previousJoin;
  29.     /**
  30.      * @param \Propel\Runtime\Map\RelationMap $relationMap
  31.      * @param string|null $leftTableAlias
  32.      * @param string|null $relationAlias
  33.      *
  34.      * @return $this
  35.      */
  36.     public function setRelationMap(RelationMap $relationMap$leftTableAlias null$relationAlias null)
  37.     {
  38.         $leftCols $relationMap->getLeftColumns();
  39.         $rightCols $relationMap->getRightColumns();
  40.         $leftValues $relationMap->getLocalValues();
  41.         $nbColumns $relationMap->countColumnMappings();
  42.         for ($i 0$i $nbColumns$i++) {
  43.             if ($leftValues[$i] !== null) {
  44.                 if ($relationMap->getType() === RelationMap::ONE_TO_MANY) {
  45.                     //one-to-many
  46.                     $this->addForeignValueCondition(
  47.                         $rightCols[$i]->getTableName(),
  48.                         $rightCols[$i]->getName(),
  49.                         $relationAlias,
  50.                         $leftValues[$i],
  51.                         Criteria::EQUAL,
  52.                     );
  53.                 } else {
  54.                     //many-to-one
  55.                     $this->addLocalValueCondition(
  56.                         $leftCols[$i]->getTableName(),
  57.                         $leftCols[$i]->getName(),
  58.                         $leftTableAlias,
  59.                         $leftValues[$i],
  60.                         Criteria::EQUAL,
  61.                     );
  62.                 }
  63.             } else {
  64.                 $this->addExplicitCondition(
  65.                     $leftCols[$i]->getTableName(),
  66.                     $leftCols[$i]->getName(),
  67.                     $leftTableAlias,
  68.                     $rightCols[$i]->getTableName(),
  69.                     $rightCols[$i]->getName(),
  70.                     $relationAlias,
  71.                     Criteria::EQUAL,
  72.                 );
  73.             }
  74.         }
  75.         $this->relationMap $relationMap;
  76.         return $this;
  77.     }
  78.     /**
  79.      * @return \Propel\Runtime\Map\RelationMap
  80.      */
  81.     public function getRelationMap()
  82.     {
  83.         return $this->relationMap;
  84.     }
  85.     /**
  86.      * Sets the right tableMap for this join
  87.      *
  88.      * @param \Propel\Runtime\Map\TableMap $tableMap The table map to use
  89.      *
  90.      * @return $this The current join object, for fluid interface
  91.      */
  92.     public function setTableMap(TableMap $tableMap)
  93.     {
  94.         $this->tableMap $tableMap;
  95.         return $this;
  96.     }
  97.     /**
  98.      * Gets the right tableMap for this join
  99.      *
  100.      * @return \Propel\Runtime\Map\TableMap The table map
  101.      */
  102.     public function getTableMap()
  103.     {
  104.         if ($this->tableMap === null && $this->relationMap !== null) {
  105.             $this->tableMap $this->relationMap->getRightTable();
  106.         }
  107.         return $this->tableMap;
  108.     }
  109.     /**
  110.      * @param \Propel\Runtime\ActiveQuery\ModelJoin $join
  111.      *
  112.      * @return $this
  113.      */
  114.     public function setPreviousJoin(ModelJoin $join)
  115.     {
  116.         $this->previousJoin $join;
  117.         return $this;
  118.     }
  119.     /**
  120.      * @return self
  121.      */
  122.     public function getPreviousJoin()
  123.     {
  124.         return $this->previousJoin;
  125.     }
  126.     /**
  127.      * @return bool
  128.      */
  129.     public function isPrimary()
  130.     {
  131.         return $this->previousJoin === null;
  132.     }
  133.     /**
  134.      * @param string $relationAlias
  135.      *
  136.      * @return $this
  137.      */
  138.     public function setRelationAlias($relationAlias)
  139.     {
  140.         $this->setRightTableAlias($relationAlias);
  141.         return $this;
  142.     }
  143.     /**
  144.      * @return string|null
  145.      */
  146.     public function getRelationAlias()
  147.     {
  148.         return $this->getRightTableAlias();
  149.     }
  150.     /**
  151.      * @return bool
  152.      */
  153.     public function hasRelationAlias()
  154.     {
  155.         return $this->hasRightTableAlias();
  156.     }
  157.     /**
  158.      * @return bool
  159.      */
  160.     public function isIdentifierQuotingEnabled()
  161.     {
  162.         return $this->getTableMap()->isIdentifierQuotingEnabled();
  163.     }
  164.     /**
  165.      * This method returns the last related, but already hydrated object up until this join
  166.      * Starting from $startObject and continuously calling the getters to get
  167.      * to the base object for the current join.
  168.      *
  169.      * This method only works if PreviousJoin has been defined,
  170.      * which only happens when you provide dotted relations when calling join
  171.      *
  172.      * @param object $startObject the start object all joins originate from and which has already hydrated
  173.      *
  174.      * @return object The base Object of this join
  175.      */
  176.     public function getObjectToRelate($startObject)
  177.     {
  178.         if ($this->isPrimary()) {
  179.             return $startObject;
  180.         }
  181.         $previousJoin $this->getPreviousJoin();
  182.         $previousObject $previousJoin->getObjectToRelate($startObject);
  183.         $method 'get' $previousJoin->getRelationMap()->getName();
  184.         return $previousObject->$method();
  185.     }
  186.     /**
  187.      * @param \Propel\Runtime\ActiveQuery\Join|null $join
  188.      *
  189.      * @return bool
  190.      */
  191.     public function equals($join)
  192.     {
  193.         /** @phpstan-var \Propel\Runtime\ActiveQuery\ModelJoin $join */
  194.         return parent::equals($join)
  195.             && $this->relationMap == $join->getRelationMap()
  196.             && $this->previousJoin == $join->getPreviousJoin()
  197.             && $this->rightTableAlias == $join->getRightTableAlias();
  198.     }
  199.     /**
  200.      * @return string
  201.      */
  202.     public function __toString()
  203.     {
  204.         return parent::toString()
  205.             . ' tableMap: ' . ($this->tableMap get_class($this->tableMap) : 'null')
  206.             . ' relationMap: ' $this->relationMap->getName()
  207.             . ' previousJoin: ' . ($this->previousJoin '(' $this->previousJoin ')' 'null')
  208.             . ' relationAlias: ' $this->rightTableAlias;
  209.     }
  210. }