/** * Transforms a Join into SQL and parameter arrays * * @param JoinInterface $join The join * @param array &$sql The query parts * @return void */ protected function parseJoin(JoinInterface $join, array &$sql) { $leftSource = $join->getLeft(); $leftTableName = $leftSource->getSelectorName(); // $sql['fields'][$leftTableName] = $leftTableName . '.*'; $rightSource = $join->getRight(); if ($rightSource instanceof JoinInterface) { $rightTableName = $rightSource->getLeft()->getSelectorName(); } else { $rightTableName = $rightSource->getSelectorName(); $sql['fields'][$leftTableName] = $rightTableName . '.*'; } $sql['tables'][$leftTableName] = $leftTableName; $sql['unions'][$rightTableName] = 'LEFT JOIN ' . $rightTableName; $joinCondition = $join->getJoinCondition(); if ($joinCondition instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\EquiJoinCondition) { $column1Name = $joinCondition->getProperty1Name(); $column2Name = $joinCondition->getProperty2Name(); $sql['unions'][$rightTableName] .= ' ON ' . $joinCondition->getSelector1Name() . '.' . $column1Name . ' = ' . $joinCondition->getSelector2Name() . '.' . $column2Name; } if ($rightSource instanceof JoinInterface) { $this->parseJoin($rightSource, $sql); } }
/** * Transforms a Join into SQL and parameter arrays * * @param Qom\JoinInterface $join The join * @param array &$sql The query parts * @return void */ protected function parseJoin(Qom\JoinInterface $join, array &$sql) { $leftSource = $join->getLeft(); $leftClassName = $leftSource->getNodeTypeName(); $leftTableName = $leftSource->getSelectorName(); $this->addRecordTypeConstraint($leftClassName, $sql); $rightSource = $join->getRight(); if ($rightSource instanceof Qom\JoinInterface) { $left = $rightSource->getLeft(); $rightClassName = $left->getNodeTypeName(); $rightTableName = $left->getSelectorName(); } else { $rightClassName = $rightSource->getNodeTypeName(); $rightTableName = $rightSource->getSelectorName(); $sql['fields'][$leftTableName] = $rightTableName . '.*'; } $this->addRecordTypeConstraint($rightClassName, $sql); $sql['tables'][$leftTableName] = $leftTableName; $sql['unions'][$rightTableName] = 'LEFT JOIN ' . $rightTableName; $joinCondition = $join->getJoinCondition(); if ($joinCondition instanceof Qom\EquiJoinCondition) { $column1Name = $this->dataMapper->convertPropertyNameToColumnName($joinCondition->getProperty1Name(), $leftClassName); $column2Name = $this->dataMapper->convertPropertyNameToColumnName($joinCondition->getProperty2Name(), $rightClassName); $sql['unions'][$rightTableName] .= ' ON ' . $joinCondition->getSelector1Name() . '.' . $column1Name . ' = ' . $joinCondition->getSelector2Name() . '.' . $column2Name; } if ($rightSource instanceof Qom\JoinInterface) { $this->parseJoin($rightSource, $sql); } }
/** * Transforms a Join into SQL and parameter arrays * * @param Qom\JoinInterface $join The join * @param string $leftTableAlias The alias from the table to main * @return void */ protected function parseJoin(Qom\JoinInterface $join, $leftTableAlias) { $leftSource = $join->getLeft(); $leftClassName = $leftSource->getNodeTypeName(); $this->addRecordTypeConstraint($leftClassName); $rightSource = $join->getRight(); if ($rightSource instanceof Qom\JoinInterface) { $left = $rightSource->getLeft(); $rightClassName = $left->getNodeTypeName(); $rightTableName = $left->getSelectorName(); } else { $rightClassName = $rightSource->getNodeTypeName(); $rightTableName = $rightSource->getSelectorName(); $this->queryBuilder->addSelect($rightTableName . '.*'); } $this->addRecordTypeConstraint($rightClassName); $rightTableAlias = $this->getUniqueAlias($rightTableName); $joinCondition = $join->getJoinCondition(); $joinConditionExpression = null; $this->unionTableAliasCache[] = $rightTableAlias; if ($joinCondition instanceof Qom\EquiJoinCondition) { $column1Name = $this->dataMapper->convertPropertyNameToColumnName($joinCondition->getProperty1Name(), $leftClassName); $column2Name = $this->dataMapper->convertPropertyNameToColumnName($joinCondition->getProperty2Name(), $rightClassName); $joinConditionExpression = $this->queryBuilder->expr()->eq($leftTableAlias . '.' . $column1Name, $rightTableAlias . '.' . $column2Name); } $this->queryBuilder->leftJoin($leftTableAlias, $rightTableName, $rightTableAlias, $joinConditionExpression); if ($rightSource instanceof Qom\JoinInterface) { $this->parseJoin($rightSource, $rightTableAlias); } }