Add the order to query builder according to the configuration.

@param ORMFilterEvent $event
7956
public function addOrder(ORMFilterEvent $event)
    {
        $queryBuilder = $event->getQueryBuilder();
        $admin = $event->getAdmin();
        $actionConfiguration = $admin->getAction()->getConfiguration();

        $request = $this->requestStack->getMasterRequest();
        $sort = $request->get('sort');
        $alias = $queryBuilder->getRootAliases()[0];

        // The sort from the request override the configured one
        if ($sort) {
            $order = $request->get('order', 'asc');

            $queryBuilder->addOrderBy($alias.'.'.$sort, $order);
        } else {
            foreach ($actionConfiguration->getParameter('order') as $field => $order) {
                $queryBuilder->addOrderBy($alias.'.'.$field, $order);
            }
        }
    }
1085221
public function beforeFind(Event $event)
    {
        //Inject default query handlers
        $queryParameters = Hash::merge($this->getConfig('queryParameters'), [
            'sort' => [
                'callable' => [$this, '_sortParameter'],
            ],
            'include' => [
                'callable' => [$this, '_includeParameter']
            ],
            'fields' => [
                'callable' => [$this, '_fieldSetsParameter']
            ]
        ]);

        foreach ($queryParameters as $parameter => $options) {
            if (is_callable($options)) {
                $options = [
                    'callable' => $options
                ];
            }

            if (!is_callable($options['callable'])) {
                throw new \InvalidArgumentException('Invalid callable supplied for query parameter ' . $parameter);
            }

            $options['callable']($this->_request()->getQuery($parameter), $event->getSubject(), $options);
        }
    }
421594
public function onKernelController(FilterControllerEvent $event)
    {
        $request = $event->getRequest();
        $route = $this->routes->get($request->attributes->get('_route'));
        if ($route && $converters = $route->getOption('_converters')) {
            foreach ($converters as $name => $callback) {
                $callback = $this->callbackResolver->resolveCallback($callback);

                $request->attributes->set($name, call_user_func($callback, $request->attributes->get($name), $request));
            }
        }
    }
1124896
public function addOrderBy(QueryBuilder $queryBuilder, Request $request, TableModel $table)
    {
        $sorting = $table->getSorting();
        $rootAlias = $this->getRootAlias($queryBuilder);

        $orderByField = $request->query->get('order_by', null);
        $orderDirection = $request->query->get('order_dir', null);

        if (null !== $orderByField && true === in_array($orderByField, $sorting->getSortableFields())) {
            $sorting->setIndex($orderByField);
        }

        if (null !== $orderDirection && true === in_array(strtolower($orderDirection), $this->getOrderDirections())) {
            $sorting->setDirection($orderDirection);
        }

        $queryBuilder
            ->orderBy(sprintf("%s.%s", $rootAlias, $sorting->getIndex()), $sorting->getDirection());

        return $queryBuilder;
    }
719279
public function onKernelController(FilterControllerEvent $event)
    {
        $request = $this->request = $event->getRequest();
        if (false === $this->isEnabled()) {
            return;
        }

        $controller = $event->getController();

        $metadata = $this->getControllerActionMetadata($controller);
        if (null === $metadata || 0 === count($metadata->param_converter_bag)) {
            // no annotations defined for this controller
            return;
        }

        foreach ($metadata->param_converter_bag as $param_converter) {
            $class = $param_converter->class;
            $bag = $param_converter->id_source;
            $unique_identifier = $request->$bag->get($param_converter->id_name, null);
            $entity = null;
            try {
                if (null === $unique_identifier) {
                    throw new \InvalidArgumentException(
                        'Unable to find identifier with provided attribute: '.$param_converter->id_name
                    );
                }
            } catch (\InvalidArgumentException $e) {
                if (true === $param_converter->required) {
                    throw $e;
                }
            }

            if (null !== $unique_identifier) {
                $entity = $event->getKernel()->getApplication()->getEntityManager()->find($class, $unique_identifier);
                if (null === $entity) {
                    throw new NotFoundHttpException("No `$class` exists with uid `$unique_identifier`.");
                }
            }

            $request->attributes->set($param_converter->name, $entity);
        }
    }
801149
public function dispatchOrderLineOnCreatedEvent(
        OrderInterface $order,
        CartLineInterface $cartLine,
        OrderLineInterface $orderLine
    ) {
        $orderLineOnCreatedEvent = new OrderLineOnCreatedEvent(
            $order,
            $cartLine,
            $orderLine
        );

        $this->eventDispatcher->dispatch(
            ElcodiCartEvents::ORDERLINE_ONCREATED,
            $orderLineOnCreatedEvent
        );

        return $this;
    }
747532
private function orderQueryBuilderBy(QueryBuilder $queryBuilder, TableInterface $table, $sort)
    {
        if (!is_array($sort)) {
            $sort = array($sort => $table->getOption('order', 'DESC'));
        }

        foreach ($sort as $fieldName => $order) {
            // Check field is sortable
            $field = $table->getField($fieldName);
            if (!$field->getOption('sortable')) {
                throw new InvalidArgumentException("Field $fieldName is not sortable in table " . $table->getName());
            }

            foreach ((array)$field->getOption('order_path') as $orderBy) {
                $queryBuilder->addOrderBy($this->fixQueryPath($orderBy, $field), $order);
            }
        }
    }
596928
public function onKernelController(FilterControllerEvent $event)
    {
        $request = $event->getRequest();
        $template = $request->attributes->get('_template');

        if (!$template instanceof Template) {
            return;
        }

        $controller = $event->getController();
        if (!\is_array($controller) && method_exists($controller, '__invoke')) {
            $controller = [$controller, '__invoke'];
        }
        $template->setOwner($controller);

        // when no template has been given, try to resolve it based on the controller
        if (null === $template->getTemplate()) {
            $template->setTemplate($this->templateGuesser->guessTemplateName($controller, $request));
        }
    }
495364
public function addEventFilter(FilterCollectionEvent $event): void
    {
        $now = new \DateTime();
        $qb = $event->getQueryBuilder();
        $query = $qb->query()->bool()
            ->addMust($qb->query()->term(['_index' => 'event']))
            ->addMust($qb->query()->term(['active' => true]))
            ->addMust($qb->query()->terms('groups.id', $event->getGroupIds()))
            ->addMustNot($qb->query()->exists('schedule'))
        ;
        $event->addFilter($query);
    }
809999
public function onPreCreate(OrderEvent $event)
    {
        if ($this->isOrderLocked($event)) {
            return;
        }

        $order = $event->getOrder();

        // Only for orders and quotes
        if (!in_array($order->getType(), [OrderTypes::TYPE_ORDER, OrderTypes::TYPE_QUOTE])) {
            return;
        }

        // Generate number and key
        $this->generateNumberAndKey($order);

        // Handle identity
        $this->handleIdentity($order);

        // Handle addresses
        $this->handleAddresses($order);
    }
922591
public function beforeFilter(Event $event)
    {
        $slug = lcfirst($this->request->params['type']);

        $this->type = $this->PostTypes->getOption($slug);

        if (!$this->type) {
            throw new Exception("The PostType is not registered");
        }

        $this->Model = TableRegistry::get($this->type['model']);

        // making the current item active
        $this->Menu->active($this->type['alias']);

        parent::beforeFilter($event);
    }
1163142
public function onCreatePaginator(CreatePaginatorEvent $event)
    {
        $params = $event->getPaginatorParams();
        $paginatorName = $event->getPaginatorName();
        $paginators = $event->getPaginators();
        $serviceName = 'Solr/' . $paginatorName;
        if (is_object($paginators) && $paginators->has($serviceName)) {
            /* @var \Zend\Paginator\Paginator $paginator */
            // yes, we have that solr paginator to replace $paginatorName
            $paginator = $paginators->get($serviceName, $params);
            $event->setPaginator($paginator);
        }
    }
1118595
public function beforeFilter(\Cake\Event\Event $event)
    {
        parent::beforeFilter($event);

        $this->Auth->allow([]);
    }
471448
public function saveOrder(OrderOnCreatedEvent $event)
    {
        $order = $event->getOrder();

        $this->orderObjectManager->persist($order);
        $this->orderObjectManager->flush($order);
    }
255612
public function onKernelController(FilterControllerEvent $event)
    {
        $request = $event->getRequest();

        // Check if the event has a nodeTranslation, if not this method can be skipped
        if (!$request->attributes->has('_nodeTranslation')) {
            return;
        }

        $nodeTranslation = $request->attributes->get('_nodeTranslation');
        if (!($nodeTranslation instanceof NodeTranslation)) {
            throw new \Exception('Invalid _nodeTranslation value found in request attributes');
        }
        $entity = $nodeTranslation->getRef($this->em);

        // If the entity is an instance of the SlugActionInterface, change the controller
        if ($entity instanceof SlugActionInterface) {
            $request->attributes->set('_entity', $entity);

            // Do security check by firing an event that gets handled by the SlugSecurityListener
            $securityEvent = new SlugSecurityEvent();
            $securityEvent
                ->setNode($nodeTranslation->getNode())
                ->setEntity($entity)
                ->setRequest($request)
                ->setNodeTranslation($nodeTranslation);

            $this->eventDispatcher->dispatch(Events::SLUG_SECURITY, $securityEvent);

            // Set the right controller
            $request->attributes->set('_controller', $entity->getControllerAction());
            $event->setController($this->resolver->getController($request));
        }
    }
1273941
public function beforeFilter($event)
    {
        $this->Controller->authUser = $this->Controller->Auth->user();

        // beforeFilter-event
        $_event = new Event('Component.Manager.beforeFilter', $this, [
        ]);
        $this->Controller->eventManager()->dispatch($_event);

        // beforeFilter-event for prefixes
        if ($this->isPrefix()) {
            $this->_runCallback("beforeFilter", $event);

            // beforeFilter-event with Prefix
            $this->_runEvent("beforeFilter");
        }

        $this->__loadHelpers();
    }
1181004
public function createOrderCouponsByCartCoupons(OrderOnCreatedEvent $event)
    {
        $this
            ->cartCouponToOrderTransformer
            ->createOrderCouponsByCartCoupons(
                $event->getCart(),
                $event->getOrder()
            );
    }