Ejemplo n.º 1
0
 /**
  * Transforms orderings into SQL.
  *
  * @param array $orderings An array of orderings (Qom\Ordering)
  * @param Qom\SourceInterface $source The source
  * @param array &$sql The query parts
  * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedOrderException
  * @return void
  */
 protected function parseOrderings(array $orderings, Qom\SourceInterface $source, array &$sql)
 {
     foreach ($orderings as $propertyName => $order) {
         switch ($order) {
             case Qom\QueryObjectModelConstantsInterface::JCR_ORDER_ASCENDING:
             case QueryInterface::ORDER_ASCENDING:
                 $order = 'ASC';
                 break;
             case Qom\QueryObjectModelConstantsInterface::JCR_ORDER_DESCENDING:
             case QueryInterface::ORDER_DESCENDING:
                 $order = 'DESC';
                 break;
             default:
                 throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedOrderException('Unsupported order encountered.', 1242816074);
         }
         $className = '';
         $tableName = '';
         if ($source instanceof Qom\SelectorInterface) {
             $className = $source->getNodeTypeName();
             $tableName = $this->dataMapper->convertClassNameToTableName($className);
             while (strpos($propertyName, '.') !== FALSE) {
                 $this->addUnionStatement($className, $tableName, $propertyName, $sql);
             }
         } elseif ($source instanceof Qom\JoinInterface) {
             $tableName = $source->getLeft()->getSelectorName();
         }
         $columnName = $this->dataMapper->convertPropertyNameToColumnName($propertyName, $className);
         if ($tableName !== '') {
             $sql['orderings'][] = $tableName . '.' . $columnName . ' ' . $order;
         } else {
             $sql['orderings'][] = $columnName . ' ' . $order;
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * 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);
         }
     }
 }