/** * Processes the pending join conditions, used for dynamically add conditions * to root component/joined components without interfering in the main dql * handling. * * @param string $alias Component Alias * @return Processed pending conditions */ protected function _processPendingJoinConditions($alias) { $parts = array(); if ($alias !== null && isset($this->_pendingJoinConditions[$alias])) { $parser = new Doctrine_Query_JoinCondition($this, $this->_tokenizer); foreach ($this->_pendingJoinConditions[$alias] as $joinCondition) { $parts[] = $parser->parse($joinCondition); } // FIX #1860 and #1876: Cannot unset them, otherwise query cannot be reused later //unset($this->_pendingJoinConditions[$alias]); } return count($parts) > 0 ? '(' . implode(') AND (', $parts) . ')' : ''; }
/** * _buildSqlFromPart * builds the from part of the query and returns it * * @return string the query sql from part */ protected function _buildSqlFromPart() { $q = ''; foreach ($this->_sqlParts['from'] as $k => $part) { if ($k === 0) { $q .= $part; continue; } // preserve LEFT JOINs only if needed // Check if it's JOIN, if not add a comma separator instead of space if (!preg_match('/\\bJOIN\\b/i', $part) && !isset($this->_pendingJoinConditions[$k])) { $q .= ', ' . $part; } else { $e = explode(' ', $part); if (substr($part, 0, 9) === 'LEFT JOIN') { $aliases = array_merge($this->_subqueryAliases, array_keys($this->_neededTables)); if (!in_array($e[3], $aliases) && !in_array($e[2], $aliases) && !empty($this->_pendingFields)) { continue; } } if (isset($this->_pendingJoinConditions[$k])) { $parser = new Doctrine_Query_JoinCondition($this, $this->_tokenizer); if (strpos($part, ' ON ') !== false) { $part .= ' AND '; } else { $part .= ' ON '; } $part .= $parser->parse($this->_pendingJoinConditions[$k]); unset($this->_pendingJoinConditions[$k]); } $componentAlias = $this->getComponentAlias($e[3]); $string = $this->getInheritanceCondition($componentAlias); if ($string) { $q .= ' ' . $part . ' AND ' . $string; } else { $q .= ' ' . $part; } } $this->_sqlParts['from'][$k] = $part; } return $q; }
/** * Processes the pending join conditions, used for dynamically add conditions * to root component/joined components without interferring in the main dql * processment. * * @param string $alias Component Alias * @return Processed pending conditions */ protected function _processPendingJoinConditions($alias) { $part = ''; if ($alias !== null && isset($this->_pendingJoinConditions[$alias])) { $parser = new Doctrine_Query_JoinCondition($this, $this->_tokenizer); $part = $parser->parse($this->_pendingJoinConditions[$alias]); unset($this->_pendingJoinConditions[$alias]); } return $part; }
/** * Processes the pending join conditions, used for dynamically add conditions * to root component/joined components without interferring in the main dql * processment. * * @param string $alias Component Alias * @return Processed pending conditions */ protected function _processPendingJoinConditions($alias) { $part = ''; if ($alias !== null && isset($this->_pendingJoinConditions[$alias])) { $parser = new Doctrine_Query_JoinCondition($this, $this->_tokenizer); $part = $parser->parse($this->_pendingJoinConditions[$alias]); // FIX #1860 and #1876: Cannot unset them, otherwise query cannot be reused later //unset($this->_pendingJoinConditions[$alias]); } return $part; }
/** * buildFromPart * builds the from part of the query and returns it * * @return string the query sql from part */ public function buildFromPart() { $q = ''; foreach ($this->parts['from'] as $k => $part) { if ($k === 0) { $q .= $part; continue; } // preserve LEFT JOINs only if needed if (substr($part, 0, 9) === 'LEFT JOIN') { $e = explode(' ', $part); $aliases = array_merge($this->subqueryAliases, array_keys($this->neededTables)); if (!in_array($e[3], $aliases) && !in_array($e[2], $aliases) && !empty($this->pendingFields)) { continue; } } if (isset($this->_pendingJoinConditions[$k])) { $parser = new Doctrine_Query_JoinCondition($this); $part .= ' AND ' . $parser->parse($this->_pendingJoinConditions[$k]); unset($this->_pendingJoinConditions[$k]); } $q .= ' ' . $part; $this->parts['from'][$k] = $part; } return $q; }