Ejemplo n.º 1
0
 /**
  * Add a join with multiple conditions
  * @deprecated use Join::setJoinCondition($criterion) instead
  *
  * @see http://propel.phpdb.org/trac/ticket/167, http://propel.phpdb.org/trac/ticket/606
  *
  * Example usage:
  * $c->addMultipleJoin(array(
  *     array(LeftTableMap::LEFT_COLUMN, RightTableMap::RIGHT_COLUMN),  // if no third argument, defaults to Criteria::EQUAL
  *     array(FoldersTableMap::alias( 'fo', FoldersTableMap::LFT ), FoldersTableMap::alias( 'parent', FoldersTableMap::RGT ), Criteria::LESS_EQUAL )
  *   ),
  *   Criteria::LEFT_JOIN
  * );
  *
  * @see addJoin()
  * @param array  $conditions An array of conditions, each condition being an array (left, right, operator)
  * @param string $joinType   A String with the join operator. Defaults to an implicit join.
  *
  * @return $this|Criteria A modified Criteria object.
  */
 public function addMultipleJoin($conditions, $joinType = null)
 {
     $join = new Join();
     $join->setIdentifierQuoting($this->isIdentifierQuotingEnabled());
     $joinCondition = null;
     foreach ($conditions as $condition) {
         $left = $condition[0];
         $right = $condition[1];
         $pos = strrpos($left, '.');
         if ($pos) {
             $leftTableAlias = substr($left, 0, $pos);
             $leftColumnName = substr($left, $pos + 1);
             list($leftTableName, $leftTableAlias) = $this->getTableNameAndAlias($leftTableAlias);
         } else {
             list($leftTableName, $leftTableAlias) = [null, null];
             $leftColumnName = $left;
         }
         $pos = strrpos($right, '.');
         if ($pos) {
             $rightTableAlias = substr($right, 0, $pos);
             $rightColumnName = substr($right, $pos + 1);
             list($rightTableName, $rightTableAlias) = $this->getTableNameAndAlias($rightTableAlias);
         } else {
             list($rightTableName, $rightTableAlias) = [null, null];
             $rightColumnName = $right;
         }
         if (!$join->getRightTableName()) {
             $join->setRightTableName($rightTableName);
         }
         if (!$join->getRightTableAlias()) {
             $join->setRightTableAlias($rightTableAlias);
         }
         $conditionClause = $leftTableAlias ? $leftTableAlias . '.' : ($leftTableName ? $leftTableName . '.' : '');
         $conditionClause .= $leftColumnName;
         $conditionClause .= isset($condition[2]) ? $condition[2] : Join::EQUAL;
         $conditionClause .= $rightTableAlias ? $rightTableAlias . '.' : ($rightTableName ? $rightTableName . '.' : '');
         $conditionClause .= $rightColumnName;
         $criterion = $this->getNewCriterion($leftTableName . '.' . $leftColumnName, $conditionClause, Criteria::CUSTOM);
         if (null === $joinCondition) {
             $joinCondition = $criterion;
         } else {
             $joinCondition = $joinCondition->addAnd($criterion);
         }
     }
     $join->setJoinType($joinType);
     $join->setJoinCondition($joinCondition);
     return $this->addJoinObject($join);
 }