/** * Process order * * @param Criteria $criteria * @param RequestInterface $request */ protected function processOrder(Criteria $criteria, RequestInterface $request) { $criteria->orderBy($request->getOrder()); }
/** * {@inheritdoc} */ public function getOrder() { if ($this->order === null) { $this->order = []; foreach ($this->request->getOrder() as $name => $direction) { $orderBy = $this->schema->getField($name)->getOrderBy(); if (empty($orderBy)) { $this->order[$name] = $direction; } $this->order = array_replace($this->order, array_fill_keys($orderBy, $direction)); } } return $this->order; }
/** * Validate order * * @param RequestInterface $request * @param array $errors */ protected function validateOrder(RequestInterface $request, array &$errors) { foreach ($request->getOrder() as $field => $value) { if (!$this->schema->hasField($field)) { $errors[] = sprintf('Order cannot be applied to non-existent field "%s"', $field); continue; } if (!$this->schema->getField($field)->isOrderable()) { $errors[] = sprintf('Field "%s" is not orderable', $field); } if ($value !== RequestInterface::ORDER_ASC && $value !== RequestInterface::ORDER_DESC) { $errors[] = sprintf('Invalid order direction "%s" specified for the field "%s"', $value, $field); } } }