/** * Собираем данные для сабформы поиска */ private function initGlobalSearchSubform() { $search = array(); /** * Инициализация левой части с параметрами поиска */ if (CRequest::getGlobalFilterClass() != "") { $modelMeta = CCoreObjectsManager::getCoreModel(CRequest::getGlobalFilterClass()); if (!is_null($modelMeta)) { $globalSearch = CRequest::getGlobalFilter(); if ($globalSearch["field"] !== false) { /** * Получаем название поля, по которому в данный * момент выполняется поиск */ $translations = $modelMeta->getTranslationDefault(); $filterValue = $globalSearch["value"]; if (CRequest::getString("filterLabel") != "") { $filterValue = CRequest::getString("filterLabel"); } $search[$globalSearch["field"]] = $filterValue; if (array_key_exists($globalSearch["field"], $translations)) { unset($search[$globalSearch["field"]]); $search[$translations[$globalSearch["field"]]] = $filterValue; } } } } $this->setData("__search", $search); /** * Поиск только в рамках текущей задачи */ $this->setData("__current_task", ""); if (!is_null(CSession::getCurrentTask())) { $this->setData("__current_task", CSession::getCurrentTask()->getId()); } CSession::setCurrentController($this); $this->setData("__controller", $this); }
/** * Разбитый на страницы набор данных * * @return CArrayList */ public function getPaginated() { /** * Разбивка на страницы на случай, если записи добавлялись вручную * и на случай, если рекордсет получен из таблицы */ if ($this->_manualAdded) { $res = new CArrayList(); $i = 0; $start = ($this->getCurrentPage() - 1) * $this->getPageSize(); $end = $this->getCurrentPage() * $this->getPageSize(); foreach ($this->getItems() as $key => $value) { if ($i >= $start && $i < $end) { $res->add($key, $value); } $i++; } return $res; } else { $res = new CArrayList(); $query = $this->getQuery(); /** * Использование глобального поиск и глобальных сортировок */ if ($this->_useGlobalSearch) { // глобальный поиск $globalFilter = CRequest::getGlobalFilter(); if ($globalFilter["field"] !== false) { $condition = $query->getCondition(); if (is_numeric($globalFilter["value"])) { if ($condition != "") { $condition .= " AND " . $globalFilter["field"] . '=' . $globalFilter["value"]; } else { $condition = $globalFilter["field"] . '=' . $globalFilter["value"]; } } else { if ($condition != "") { $condition .= " AND " . $globalFilter["field"] . " like '%" . $globalFilter["value"] . "%'"; } else { $condition = $globalFilter["field"] . " like '%" . $globalFilter["value"] . "%'"; } } $query->condition($condition); } // глобальные сортировки $globalOrder = CRequest::getGlobalOrder(); if ($globalOrder["field"] !== false) { $query->order($globalOrder["field"] . " " . $globalOrder["direction"]); } } /** * Использование глобального ограничения доступа */ if ($this->_isAclControlledSet) { $this->updateQueryForACLLimitations(); } if ($this->getPageSize() != PAGINATION_ALL) { $start = ($this->getCurrentPage() - 1) * $this->getPageSize(); $query->limit($start, $this->getPageSize()); } $items = $query->execute(); foreach ($items->getItems() as $item) { $ar = new CActiveRecord($item); $ar->setTable($query->getTable()); $res->add($ar->getId(), $ar); } return $res; } }