You can call orderBy multiple times. Each call will add a
column to order by.
Example:
$q->select( '*' )->from( 'table' )
->orderBy( 'id' );
public orderBy ( string $column, string $type = self::ASC ) : eZ\Publish\Core\Persistence\Database\SelectQuery | ||
$column | string | a column name in the result set |
$type | string | if the column should be sorted ascending or descending. you can specify this using \eZ\Publish\Core\Persistence\Database\SelectQuerySelect::ASC or \eZ\Publish\Core\Persistence\Database\SelectQuerySelect::DESC |
리턴 | eZ\Publish\Core\Persistence\Database\SelectQuery | a pointer to $this |
/** * Helper for {@see listVersions()} and {@see listVersionsForUser()} that filters duplicates * that are the result of the cartesian product performed by createVersionInfoFindQuery(). * * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query * * @return string[][] */ private function listVersionsHelper(SelectQuery $query) { $query->orderBy($this->dbHandler->quoteColumn('id', 'ezcontentobject_version')); $statement = $query->prepare(); $statement->execute(); $results = array(); $previousId = null; foreach ($statement->fetchAll(\PDO::FETCH_ASSOC) as $row) { if ($row['ezcontentobject_version_id'] == $previousId) { continue; } $previousId = $row['ezcontentobject_version_id']; $results[] = $row; } return $results; }
/** * Apply order by parts of sort clauses to query * * @param \eZ\Publish\Core\Persistence\Database\SelectQuery $query */ public function applyOrderBy(SelectQuery $query) { foreach ($this->sortColumns as $column => $direction) { $query->orderBy($column, $direction === Query::SORT_ASC ? SelectQuery::ASC : SelectQuery::DESC); } // @todo Review needed // The following line was added because without it, loading sub user groups through the Public API // fails with the database error "Unknown column sort_column_0". The change does not break any // integration tests or legacy persistence tests, but it can break something else, so review is needed // Discussion: https://github.com/ezsystems/ezpublish-kernel/commit/8749d0977307858c3e2a7d82f3be90fa21973357#L1R102 $this->sortColumns = array(); }