Entity/EntityRepository.php
protected function addSorting(QueryBuilder $queryBuilder, array $sorting = [])
    {
        foreach ($sorting as $field => $sortOrder) {
            if (!$this->isFieldSortable($field)) {
                // Skip: invalid field
                continue;
            }
            if (!$this->isSortOrderValid($sortOrder)) {
                // Skip: invalid sort order
                continue;
            }

            $methodName = sprintf('add%sSorting', ucfirst($field));
            if (method_exists($this, $methodName)) {
                $this->$methodName($queryBuilder, $sortOrder);
                continue;
            }

            $queryBuilder->addOrderBy($this->addEntityAlias($field), strtolower($sortOrder));
        }

        return $queryBuilder;
    }
protected function addSorting(QueryBuilder $queryBuilder, array $sorting = [])
    {
        foreach ($sorting as $field => $sortOrder) {
            if (!$this->isFieldSortable($field)) {
                // Skip: invalid field
                continue;
            }
            if (!$this->isSortOrderValid($sortOrder)) {
                // Skip: invalid sort order
                continue;
            }

            $methodName = sprintf('add%sSorting', ucfirst($field));
            if (method_exists($this, $methodName)) {
                $this->$methodName($queryBuilder, $sortOrder);
                continue;
            }

            $queryBuilder->addOrderBy($this->addEntityAlias($field), strtolower($sortOrder));
        }

        return $queryBuilder;
    }
protected function addSorting ( QueryBuilder $ queryBuilder , array $ sorting = [ ] ) { foreach ( $ sorting as $ field => $ sortOrder ) { if ( ! $ this -> isFieldSortable ( $ field ) ) { // Skip: invalid field continue ; } if ( ! $ this -> isSortOrderValid ( $ sortOrder ) ) { // Skip: invalid sort order continue ; } $ methodName = sprintf ( 'add%sSorting' , ucfirst ( $ field ) ) ; if ( method_exists ( $ this , $ methodName ) ) { $ this -> $ methodName ( $ queryBuilder , $ sortOrder ) ; continue ; } $ queryBuilder -> addOrderBy ( $ this -> addEntityAlias ( $ field ) , strtolower ( $ sortOrder ) ) ; } return $ queryBuilder ; }
Adds sorting to the specified query builder.

@param \Doctrine\ORM\QueryBuilder $queryBuilder
@param array $sorting
@return \Doctrine\ORM\QueryBuilder
Adds sorting to the specified query builder .