protected function applyOrder($params = null) { $query = $this->getQuery(); if (is_null($params)) { return $query; } $orders = $params->getOrder(); foreach ($orders as $order) { if (!is_array($order)) { ModelException::throwException("Wrong 'order' parameter"); } $orderField = array_keys($order); if (!is_array($orderField) || !isset($orderField[0])) { ModelException::throwException("Wrong 'order' parameter"); } $orderField = $orderField[0]; $fields = $this->getFieldsValidators(); if ($orderField === 'random' && $order[$orderField]) { $randStr = substr(preg_replace("/[^a-zA-Z0-9]/", "", $order[$orderField]), 0, 16); $query->addSortField("{$orderField}_{$randStr}", \SolrQuery::ORDER_DESC); } if (!isset($fields[$orderField])) { continue; } if (strtolower($order[$orderField]) == 'asc') { $query->addSortField($orderField, \SolrQuery::ORDER_ASC); } if (strtolower($order[$orderField]) == 'desc') { $query->addSortField($orderField, \SolrQuery::ORDER_DESC); } } return $query; }
public function edit($id, $data) { $item = $this->getById($id); if (!$item) { ModelException::throwException("Entity with id = {$id} doesn't exist!"); } $data['id'] = $id; return $this->setValues($data, true)->validateValues()->save(); }