/** * Transforms orderings into SQL. * * @param array $orderings An array of orderings (Qom\Ordering) * @param Qom\SourceInterface $source The source * @throws UnsupportedOrderException * @return void */ protected function parseOrderings(array $orderings, Qom\SourceInterface $source) { foreach ($orderings as $propertyName => $order) { if ($order !== QueryInterface::ORDER_ASCENDING && $order !== QueryInterface::ORDER_DESCENDING) { throw new UnsupportedOrderException('Unsupported order encountered.', 1242816074); } $className = null; $tableName = ''; if ($source instanceof Qom\SelectorInterface) { $className = $source->getNodeTypeName(); $tableName = $this->dataMapper->convertClassNameToTableName($className); $fullPropertyPath = ''; while (strpos($propertyName, '.') !== false) { $this->addUnionStatement($className, $tableName, $propertyName, $fullPropertyPath); } } elseif ($source instanceof Qom\JoinInterface) { $tableName = $source->getLeft()->getSelectorName(); } $columnName = $this->dataMapper->convertPropertyNameToColumnName($propertyName, $className); if ($tableName !== '') { $this->queryBuilder->addOrderBy($tableName . '.' . $columnName, $order); } else { $this->queryBuilder->addOrderBy($columnName, $order); } } }
/** * Prepares the clause by which the result elements are sorted. See description of ORDER BY in * SQL standard for reference. * * @return void */ protected function prepareOrderByStatement() { if (empty($this->config['orderBy'])) { $this->queryBuilder->addOrderBy($GLOBALS['TCA'][$this->table]['ctrl']['label']); } else { foreach (QueryHelper::parseOrderBy($this->config['orderBy']) as $orderPair) { list($fieldName, $order) = $orderPair; $this->queryBuilder->addOrderBy($fieldName, $order); } } }
/** * @test */ public function addOrderByQuotesIdentifierAndDelegatesToConcreteQueryBuilder() { $this->connection->quoteIdentifier('aField')->shouldBeCalled()->willReturnArgument(0); $this->concreteQueryBuilder->addOrderBy('aField', 'DESC')->shouldBeCalled()->willReturn($this->subject); $this->subject->addOrderBy('aField', 'DESC'); }