protected function applyQuerySort(QueryBuilder $queryBuilder, $alias = 'a')
    {
        $sort = $this->get('request')->get('sort');
        $order = $this->get('request')->get('order');

        if ($sort) {
            $repository = $this->get('orm.em')->getRepository($this->getEntityClass());
            // sort using the getQueryBuilderOrderedBy* magic method if defined
            $sortMethodName = 'getQueryBuilderOrderedBy'.ucfirst(strtolower($sort));
            if (method_exists($repository, $sortMethodName)) {
                $queryBuilder = call_user_method_array($sortMethodName, $repository, array($order, $queryBuilder));
            }
            // else sort by property name if exists
            elseif ($sort && property_exists($this->getEntityClass(), $sort)) {
                $queryBuilder->orderBy($alias.'.'.$sort, $order);
            }
        }
        // if empty sort use Gedmo Sortable annotation if enable
        elseif ($sort = $this->getSortableColumn()) {
            // pre order by group if defined
            if ($sortGroup = $this->getSortableGroup()) {
                $queryBuilder->orderBy($alias.'.'.$sortGroup);
            }
            $queryBuilder->addOrderBy($alias.'.'.$sort);
        }

        return $queryBuilder;
    }
protected function applyQuerySort(QueryBuilder $queryBuilder, $alias = 'a')
    {
        $sort = $this->get('request')->get('sort');
        $order = $this->get('request')->get('order');

        if ($sort) {
            $repository = $this->get('orm.em')->getRepository($this->getEntityClass());
            // sort using the getQueryBuilderOrderedBy* magic method if defined
            $sortMethodName = 'getQueryBuilderOrderedBy'.ucfirst(strtolower($sort));
            if (method_exists($repository, $sortMethodName)) {
                $queryBuilder = call_user_method_array($sortMethodName, $repository, array($order, $queryBuilder));
            }
            // else sort by property name if exists
            elseif ($sort && property_exists($this->getEntityClass(), $sort)) {
                $queryBuilder->orderBy($alias.'.'.$sort, $order);
            }
        }
        // if empty sort use Gedmo Sortable annotation if enable
        elseif ($sort = $this->getSortableColumn()) {
            // pre order by group if defined
            if ($sortGroup = $this->getSortableGroup()) {
                $queryBuilder->orderBy($alias.'.'.$sortGroup);
            }
            $queryBuilder->addOrderBy($alias.'.'.$sort);
        }

        return $queryBuilder;
    }
protected function applyQuerySort ( QueryBuilder $ queryBuilder , $ alias = 'a' ) { $ sort = $ this -> get ( 'request' ) -> get ( 'sort' ) ; $ order = $ this -> get ( 'request' ) -> get ( 'order' ) ; if ( $ sort ) { $ repository = $ this -> get ( 'orm.em' ) -> getRepository ( $ this -> getEntityClass ( ) ) ; // sort using the getQueryBuilderOrderedBy* magic method if defined $ sortMethodName = 'getQueryBuilderOrderedBy' . ucfirst ( strtolower ( $ sort ) ) ; if ( method_exists ( $ repository , $ sortMethodName ) ) { $ queryBuilder = call_user_method_array ( $ sortMethodName , $ repository , array ( $ order , $ queryBuilder ) ) ; } // else sort by property name if exists elseif ( $ sort && property_exists ( $ this -> getEntityClass ( ) , $ sort ) ) { $ queryBuilder -> orderBy ( $ alias . '.' . $ sort , $ order ) ; } } // if empty sort use Gedmo Sortable annotation if enable elseif ( $ sort = $ this -> getSortableColumn ( ) ) { // pre order by group if defined if ( $ sortGroup = $ this -> getSortableGroup ( ) ) { $ queryBuilder -> orderBy ( $ alias . '.' . $ sortGroup ) ; } $ queryBuilder -> addOrderBy ( $ alias . '.' . $ sort ) ; } return $ queryBuilder ; }
Gets by sort query builder

@param QueryBuilder $queryBuilder Query builder instance
@param string $alias Root query alias

@return Doctrine\ORM\QueryBuilder
Gets by sort query builder