accounts/common/db/mysql/QueryBuilder.php
ErickSkrauch 45101d6453 Completely restored authorization_code grant for user side.
Reworked oauth_sessions table.
Added extension to use MariaDB's JSON columns.
Rewritten tests for authorization_code grant for client side.
Deprecate some old shit.
[skip ci]
2019-09-18 02:15:12 +03:00

41 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace common\db\mysql;
use SamIT\Yii2\MariaDb\QueryBuilder as MysqlQueryBuilder;
use yii\db\ExpressionInterface;
class QueryBuilder extends MysqlQueryBuilder {
public function buildOrderBy($columns) {
if (empty($columns)) {
return '';
}
$orders = [];
foreach ($columns as $name => $direction) {
if ($direction instanceof ExpressionInterface) {
$orders[] = $direction->expression;
} elseif (is_array($direction)) {
// This condition branch is our custom solution
if (empty($direction)) {
continue;
}
$fieldValues = [];
foreach ($direction as $fieldValue) {
$fieldValues[] = $this->db->quoteValue($fieldValue);
}
$orders[] = 'FIELD(' . $this->db->quoteColumnName($name) . ',' . implode(',', $fieldValues) . ')';
} else {
$orders[] = $this->db->quoteColumnName($name) . ($direction === SORT_DESC ? ' DESC' : '');
}
}
return 'ORDER BY ' . implode(', ', $orders);
}
}