Пример #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);
 }
Пример #2
0
 /**
  * @api
  *
  * @param int $idNode
  *
  * @return \Orm\Zed\Category\Persistence\SpyCategoryClosureTableQuery
  */
 public function queryClosureTableParentEntries($idNode)
 {
     $query = $this->getFactory()->createCategoryClosureTableQuery();
     $query->setModelAlias('node');
     $joinCategoryNodeDescendant = new Join('node.fk_category_node_descendant', 'descendants.fk_category_node_descendant', Criteria::JOIN);
     $joinCategoryNodeDescendant->setRightTableName('spy_category_closure_table')->setRightTableAlias('descendants')->setLeftTableName('spy_category_closure_table')->setLeftTableAlias('node');
     $joinCategoryNodeAscendant = new Join('descendants.fk_category_node', 'ascendants.fk_category_node', Criteria::LEFT_JOIN);
     $joinCategoryNodeAscendant->setRightTableName('spy_category_closure_table')->setRightTableAlias('ascendants')->setLeftTableName('spy_category_closure_table')->setLeftTableAlias('descendants');
     $query->addJoinObject($joinCategoryNodeDescendant);
     $query->addJoinObject($joinCategoryNodeAscendant, 'ascendantsJoin');
     $query->addJoinCondition('ascendantsJoin', 'ascendants.fk_category_node_descendant = node.fk_category_node');
     $query->where('descendants.fk_category_node = ' . $idNode)->where('ascendants.fk_category_node IS NULL');
     return $query;
 }