Skip to content

Instantly share code, notes, and snippets.

@wazum
Created January 30, 2020 06:43
Show Gist options
  • Save wazum/5b21cfa2f3da04189b52ea86a1da85c0 to your computer and use it in GitHub Desktop.
Save wazum/5b21cfa2f3da04189b52ea86a1da85c0 to your computer and use it in GitHub Desktop.
<?php
// $pageIdList is an array of integers (make sure it is!)
/** @var QueryBuilder $queryBuilder */
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('pages');
$queryBuilder->select(uid)
->orderBy('FIELD(uid,' . implode(',', $pageIdList) . ')', null, false)
<?php
defined('TYPO3_MODE') or die ('Access denied.');
(static function () {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][\TYPO3\CMS\Core\Database\Query\QueryBuilder::class] = [
'className' => \Vendor\Extension\Database\Query\QueryBuilder::class
];
})();
<?php
declare(strict_types=1);
namespace Vendor\Extension\Database\Query;
class QueryBuilder extends \TYPO3\CMS\Core\Database\Query\QueryBuilder
{
/**
* Specifies an ordering for the query results.
* Replaces any previously specified orderings, if any.
*
* @param string $fieldName The fieldName to order by.
* @param string $order The ordering direction. No automatic quoting/escaping.
* @param bool $quote Flag if to quote the given field name.
* @return QueryBuilder This QueryBuilder instance.
*/
public function orderBy(string $fieldName, string $order = null, bool $quote = true): \TYPO3\CMS\Core\Database\Query\QueryBuilder
{
$this->concreteQueryBuilder->orderBy($quote ? $this->connection->quoteIdentifier($fieldName) : $fieldName, $order);
return $this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment