Ejemplo n.º 1
0
 /**
  * Строит JOIN часть запроса (SELECT FROM JOIN...)
  * @internal
  * @param ISelectBuilder $query
  * @return string
  */
 private function buildSelectJoinPart(ISelectBuilder $query)
 {
     $joins = $query->getJoins();
     if (!count($joins)) {
         return '';
     }
     $result = '';
     foreach ($joins as $join) {
         list($name, $alias) = $join->getTable();
         $result .= "\n\t" . $join->getType() . ' JOIN ';
         $result .= $this->quoteIdentifier($name) . ($alias ? ' AS ' . $this->quoteIdentifier($alias) : '');
         $joinConditions = [];
         foreach ($join->getConditions() as $condition) {
             list($leftColumn, $operator, $rightColumn) = $condition;
             $joinConditions[] = $this->quoteIdentifier($leftColumn) . ' ' . $operator . ' ' . $this->quoteIdentifier($rightColumn);
         }
         if (count($joinConditions) === 1) {
             $result .= ' ON ' . $joinConditions[0];
         } elseif (count($joinConditions) > 1) {
             $result .= ' ON (' . implode(' AND ', $joinConditions) . ')';
         }
     }
     return $result;
 }