Created
January 30, 2020 06:43
-
-
Save wazum/5b21cfa2f3da04189b52ea86a1da85c0 to your computer and use it in GitHub Desktop.
This file contains 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 | |
// $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) | |
… |
This file contains 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 | |
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 | |
]; | |
})(); |
This file contains 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 | |
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