Override the default query builder to utilize correct sorting

@param string $context
@return ProxyQueryInterface
427617
public function createQuery($context = 'list')
    {
        if ($context === 'list') {
            /** @var $em \Doctrine\ORM\EntityManager */
            $em = $this->getModelManager()->getEntityManager($this->getClass());

            /** @var $cmd \Doctrine\Common\Persistence\Mapping\ClassMetadata */
            $cmd = $em->getMetadataFactory()->getMetadataFor($this->getClass());

            $queryBuilder = $em->createQueryBuilder();
            $queryBuilder
                ->select('n')
                ->from($this->getClass(), 'n');

            if ($cmd->hasField('root')) {
                $queryBuilder->orderBy('n.root, n.lft');
            } else {
                $queryBuilder->orderBy('n.lft');
            }

            return new ProxyQuery($queryBuilder);
        }
        return parent::createQuery($context);
    }
162738
protected function _beforeRepositoryFetch(AnCommandContext $context)
    {
        $query = $context->query;

        if ($query->keyword) {
            $keywords = $query->keyword;

            if ($keywords) {
                if (strpos($keywords, ' OR ')) {
                    $keywords = explode(' OR ', $keywords);
                    $operation = 'OR';
                } else {
                    $keywords = explode(' ', $keywords);
                    $operation = 'AND';
                }

                if (!empty($operation)) {
                    $clause = $query->clause();
                    $search_column = array();

                    foreach ($this->_searchable_properties as $property) {
                        $search_column[] = "IF(@col($property) IS NULL,\"\",@col($property))";
                    }

                    $search_column = implode($search_column, ',');

                    foreach ($keywords as $keyword) {
                        $clause->where('CONCAT('.$search_column.') LIKE @quote(%'.$keyword.'%)', $operation);
                    }
                }
            }
        }
    }
493079
protected function get_text_filters($context) {
        if (!isset($this->textfilters[$context->id])) {
            $this->load_filters($context);
        }
        return $this->textfilters[$context->id];
    }
111964
public function createQuery($context = 'list')
    {
        $query = parent::createQuery($context);
        $query->leftJoin($query->getRootAlias().'.template', 'template')->addSelect('template')
              ->leftJoin('template.areas', 'area')->addSelect('area')
              ->leftJoin($query->getRootAlias().'.metas', 'articleMeta')->addSelect('articleMeta')
              ->leftJoin('articleMeta.meta', 'meta')->addSelect('meta');

        return $query;
    }
280728
protected function proxy() {
        if (!$this->context) {
            $this->context = new DefaultsContext($this->version, $this->solution['assistantSid']);
        }

        return $this->context;
    }
887907
protected function proxy() {
        if (!$this->context) {
            $this->context = new QueryContext(
                $this->version,
                $this->solution['assistantSid'],
                $this->solution['sid']
            );
        }

        return $this->context;
    }
1197232
protected function getDefaultParametersFromContext($context = null)
    {
        if (count($this->defaultParameters['contexts'])) {
            //If context is not given, just take the default one
            if ($context === null) {
                $context = $this->defaultParameters['default']['context'];
            }

            //If context is in declared contexts, we use it
            if (array_key_exists($context, $this->defaultParameters['contexts'])) {
                return $this->defaultParameters['contexts'][$context];
            }
        }

        //else we return the default configuration
        return $this->defaultParameters['default'];
    }
490927
protected function processOrder($order, $context)
    {
        if ($order instanceof Order || $order instanceof OrderByIsNull) {
            $column = $this->processColumnOrSubQuery($order->column, $context);

            if ($column === $order->column) {
                return $order;
            } elseif ($order instanceof Order) {
                return new Order($column, $order->isDescending);
            } else {
                return new OrderByIsNull($column, $order->areNullFirst);
            }
        }

        if ($order instanceof ExplicitOrder) {
            $column = $this->processColumnOrSubQuery($order->column, $context);

            $values = [];
            foreach ($order->order as $index => $value) {
                $values[$index] = $this->processValueOrSubQuery($value, $context);
            }

            if ($column === $order->column && $values === $order->order) {
                return $order;
            } else {
                return new ExplicitOrder($column, $values, $order->areOtherFirst);
            }
        }

        return $order;
    }
253306
final public function filterByContext(array $context)
    {
        if ($context !== $this->withContext) {
            $this->withContext = $context;
            $this->consumer = null;
        }
        
        return $this;
    }
2673
protected function proxy() {
        if (!$this->context) {
            $this->context = new CompositionContext($this->version, $this->solution['sid']);
        }

        return $this->context;
    }
168253
protected function proxy() {
        if (!$this->context) {
            $this->context = new SyncMapContext(
                $this->version,
                $this->solution['serviceSid'],
                $this->solution['sid']
            );
        }

        return $this->context;
    }
844255
protected function getParser($context = null)
    {
        $parser = $this->getComponent('parser');

        $parser->registeredVars['context'] = $context;

        return $parser;
    }
601531
protected function _beforeQuerySelect(AnCommandContext $context)
    {
        $query = $context->query;

        if ($query->aggregate_keys) {
            $this->_buildAggregateQuery($query, $query->aggregate_keys);
        }
    }
341722
protected function initializeSorting(ContextInterface $context)
    {
        if (null !== $activeSort = $context->getActiveSort()) {
            $columnName = $activeSort->getColumnName();
            if ($this->table->hasColumn($columnName)) {
                $this->table->getColumn($columnName)->applySort($this, $activeSort);
            }
        }
    }
67345
protected function getHandlersForContext($context = null)
    {
        $handlers = $this->config()->get('token_handlers');
        if (empty($handlers)) {
            throw new Exception('No token handlers were registered');
        }

        // If we've been given a context, limit to that context + global handlers.
        // Otherwise only allow global handlers (i.e. exclude named ones)
        $allowedContexts = ['*'];
        if ($context) {
            $allowedContexts[] = $context;
        }

        // Filter handlers by context
        $handlers = array_filter($handlers, function ($handler) use ($allowedContexts) {
            return in_array($handler['context'], $allowedContexts);
        });

        // Sort handlers by priority
        uasort($handlers, function ($a, $b) {
            if (!array_key_exists('priority', $a) || !array_key_exists('priority', $b)) {
                return 0;
            }

            return ($a['priority'] < $b['priority']) ? -1 : 1;
        });

        return $handlers;
    }
703725
public function unserialize(string $context): GraphQLContext
    {
        [
            'request' => $rawRequest,
            'user' => $rawUser
        ] = unserialize($context);

        $request = new Request(
            $rawRequest['query'],
            $rawRequest['request'],
            $rawRequest['attributes'],
            $rawRequest['cookies'],
            $rawRequest['files'],
            $rawRequest['server'],
            $rawRequest['content']
        );

        $request->setUserResolver(
            function () use ($rawUser) {
                return unserialize($rawUser);
            }
        );

        return $this->createsContext->generate($request);
    }
10595
protected function getWhere(ProxyQuery $proxy)
    {
        $queryBuilder = $proxy->getQueryBuilder();
        if (self::CONDITION_OR == $this->getCondition()) {
            return $queryBuilder->orWhere();
        }

        return $queryBuilder->andWhere();
    }