Created
December 18, 2018 14:17
-
-
Save dmitryd/ab4a53bb11b81993e3897f9644604a45 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Vendor\Extension\Storage; | |
use TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface; | |
use TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbQueryParser; | |
/** | |
* This class allows ordering by 'FIELD' SQL statement. | |
* | |
* @author Dmitry Dulepov <[email protected]> | |
* @see https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_field | |
*/ | |
class Typo3DbQueryParseWithOrderByField extends Typo3DbQueryParser | |
{ | |
/** | |
* Adds FIELD sorting support to the query. | |
* | |
* @param array $orderings | |
* @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source | |
* @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedOrderException | |
*/ | |
protected function parseOrderings(array $orderings, SourceInterface $source) | |
{ | |
foreach ($orderings as $propertyName => $order) { | |
if (preg_match('/^\s*field\s*\(/i', $propertyName)) { | |
$this->queryBuilder->getConcreteQueryBuilder()->addOrderBy($propertyName, $order); | |
} else { | |
parent::parseOrderings([$propertyName => $order], $source); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment