/** * Returns the expression for a specific sort order. * * @param QueryBuilder $queryBuilder * @param $sorter * * @throws \Exception * * @return \Doctrine\ORM\Query\Expr\Comparison|\Doctrine\ORM\Query\Expr\Func */ private function applyOrderByExpression(QueryBuilder $queryBuilder, Sorter $sorter) { if ($sorter->getAssociation() !== null) { $alias = $this->getAlias('o.' . $sorter->getAssociation()) . '.' . $sorter->getProperty(); } else { $alias = 'o.' . $sorter->getProperty(); } return $queryBuilder->addOrderBy($alias, $sorter->getDirection()); }