SetVisibleHeaderColumn(); } public function SetVisibleHeaderColumn() { $gridOptions = new Bitrix\Main\Grid\Options($this->table_id); $gridColumns = $gridOptions->GetVisibleColumns(); if ($gridColumns) { $this->arVisibleColumns = array(); $this->aVisibleHeaders = array(); foreach ($gridColumns as $columnId) { if (isset($this->aHeaders[$columnId]) && !isset($this->aVisibleHeaders[$columnId])) { $this->arVisibleColumns[] = $columnId; $this->aVisibleHeaders[$columnId] = $this->aHeaders[$columnId]; } } } } /** * @param $navigationId * * @return PageNavigation */ public function getPageNavigation($navigationId) { $pageNum = 1; if (!Context::isInternalRequest() && !(isset($_REQUEST["clear_nav"]) && $_REQUEST["clear_nav"] === "Y") && isset(\Bitrix\Main\Application::getInstance()->getSession()["ADMIN_PAGINATION_DATA"]) && isset(\Bitrix\Main\Application::getInstance()->getSession()["ADMIN_PAGINATION_DATA"][$this->table_id]) ) { $paginationData = \Bitrix\Main\Application::getInstance()->getSession()["ADMIN_PAGINATION_DATA"][$this->table_id]; if (isset($paginationData["PAGE_NUM"])) { $pageNum = (int)$paginationData["PAGE_NUM"]; } } $nav = new PageNavigation($navigationId); $nav->setPageSize($this->getNavSize()); $nav->setCurrentPage($pageNum); $nav->initFromUri(); if (Context::isInternalRequest()) { if (!isset(\Bitrix\Main\Application::getInstance()->getSession()["ADMIN_PAGINATION_DATA"])) { \Bitrix\Main\Application::getInstance()->getSession()["ADMIN_PAGINATION_DATA"] = array(); } \Bitrix\Main\Application::getInstance()->getSession()["ADMIN_PAGINATION_DATA"][$this->table_id] = array("PAGE_NUM" => $nav->getCurrentPage()); } return $nav; } public function isTotalCountRequest() { $request = Bitrix\Main\Context::getCurrent()->getRequest(); if ($request->isAjaxRequest() && $request->get("action") == "getTotalCount") { return true; } return false; } public function sendTotalCountResponse($totalCount) { global $adminAjaxHelper; if (!is_object($adminAjaxHelper)) { require_once($_SERVER["DOCUMENT_ROOT"].BX_ROOT."/modules/main/interface/admin_lib.php"); $adminAjaxHelper = new CAdminAjaxHelper(); } $adminAjaxHelper->sendJsonResponse(["totalCountHtml" => GetMessage("admin_lib_list_all_title").": ".(int) $totalCount]); } public function SetNavigationParams(\CAdminUiResult $queryObject, $params = array()) { if ($this->isPublicMode) { unset($params["BASE_LINK"]); } $queryObject->setNavigationParams($params); $this->NavText($queryObject->GetNavPrint("")); $this->totalRowCount = $queryObject->NavRecordCount; $this->enableNextPage = $queryObject->PAGEN < $queryObject->NavPageCount; } public function setNavigation(\Bitrix\Main\UI\PageNavigation $nav, $title, $showAllways = true, $post = false) { global $APPLICATION; $this->totalRowCount = $nav->getRecordCount(); $this->enableNextPage = $nav->getCurrentPage() < $nav->getPageCount(); ob_start(); $APPLICATION->IncludeComponent( "bitrix:main.pagenavigation", "grid", array( "NAV_OBJECT" => $nav, "TITLE" => $title, "SHOW_ALWAYS" => $showAllways, "POST" => $post, "TABLE_ID" => $this->table_id, ), false, array( "HIDE_ICONS" => "Y", ) ); $this->NavText(ob_get_clean()); } public function getCurPageParam($strParam="", $arParamKill=array(), $get_index_page=null) { global $APPLICATION; if (Context::isInternalRequest()) { $arParamKill = array_merge($arParamKill, array("internal", "grid_id", "grid_action", "bxajaxid", "sessid")); } return $APPLICATION->GetCurPageParam($strParam, $arParamKill, $get_index_page); } public function getNavSize() { $gridOptions = new Bitrix\Main\Grid\Options($this->table_id); $navParams = $gridOptions->getNavParams(); return $navParams["nPageSize"]; } public function EditAction() { if( $_SERVER["REQUEST_METHOD"] == "POST" && !empty($_REQUEST["action_button_".$this->table_id]) && is_array($_POST["FIELDS"]) && check_bitrix_sessid() ) { $arrays = array(&$_POST, &$_REQUEST, &$GLOBALS); foreach ($arrays as $i => &$array) { $customFields = []; foreach ($array["FIELDS"] as $id => &$fields) { if (is_array($fields)) { CUtil::decodeURIComponent($fields); $keys = array_keys($fields); foreach ($keys as $key) { if (preg_match("/_custom/i", $key, $match)) { if (!is_array($arrays[$i]["FIELDS"][$id][$key])) { continue; } foreach ($arrays[$i]["FIELDS"][$id][$key] as $index => $value) { if (!isset($value["name"]) || !isset($value["value"])) { continue; } if (preg_match_all("/(.*?)\[(.*?)\]/", $value["name"], $listMatchKeys)) { $listPreparedKeys = []; foreach ($listMatchKeys as $matchKeys) { foreach ($matchKeys as $matchKey) { if (!is_string($matchKey) || trim($matchKey) == '') { continue; } if (mb_strpos($matchKey, "[") === false && mb_strpos($matchKey, "]") === false) { $listPreparedKeys[] = $matchKey; } } } $listPreparedKeys[] = $value["value"]; $customFields = array_replace_recursive($customFields, $this->prepareCustomKey( array_shift($listPreparedKeys), $listPreparedKeys)); } } unset($arrays[$i]["FIELDS"][$id][$key]); } if(($c = mb_substr($key, 0, 1)) == '~' || $c == '=') { unset($arrays[$i]["FIELDS"][$id][$key]); } } } } if ($customFields) { $arrays[$i] = array_replace_recursive($arrays[$i], $customFields); } } return true; } return false; } private function prepareCustomKey($key, array $keys) { return (count($keys) == 1 ? [$key => array_shift($keys)] : [$key => $this->prepareCustomKey(array_shift($keys), $keys)]); } /** * @return array|false */ public function GroupAction() { $this->PrepareAction(); if ($this->GetAction() === null) { return false; } if (!check_bitrix_sessid()) { return false; } if (!empty($_REQUEST["bxajaxid"])) { global $adminSidePanelHelper; $adminSidePanelHelper->setSkipResponse(true); } if (!$this->IsGroupActionToAll()) { $arID = $this->GetGroupIds(); if ($arID === null) { $arID = false; } } else { $arID = array(""); } return $arID; } /** * Returns true if the user has set the flag "To all" in the list. * * @return bool */ public function IsGroupActionToAll() { return ( isset($_REQUEST["action_all_rows_".$this->table_id]) && $_REQUEST["action_all_rows_".$this->table_id] === 'Y' ); } /** * @return void */ protected function PrepareAction() { if (isset($_REQUEST["action"]) && is_array($_REQUEST["action"])) { foreach ($_REQUEST["action"] as $actionKey => $actionValue) $_REQUEST[$actionKey] = $actionValue; } if (!empty($_REQUEST["action_button_".$this->table_id])) { $_REQUEST["action"] = $_REQUEST["action_button_".$this->table_id]; $_REQUEST["action_button"] = $_REQUEST["action_button_".$this->table_id]; } } public function ActionDoGroup($id, $action_id, $add_params = "") { $listParams = explode("&", $add_params); $addParams = array(); if ($listParams) { foreach($listParams as $param) { $explode = explode("=", $param); if ($explode[0] && $explode[1]) { $addParams[$explode[0]] = $explode[1]; } } } $postParams = array_merge(array( "action_button_".$this->table_id => $action_id, "ID" => $id ), $addParams); return $this->ActionAjaxPostGrid($postParams); } public function ActionAjaxPostGrid($postParams) { return "BX.Main.gridManager.getById('".$this->table_id."').instance.reloadTable('POST', ". CUtil::PhpToJsObject($postParams).");"; } public function AddFilter(array $filterFields, array &$arFilter) { $filterOption = new Bitrix\Main\UI\Filter\Options($this->table_id); $filterData = $filterOption->getFilter($filterFields); $filterable = array(); $quickSearchKey = ""; foreach ($filterFields as $filterField) { if (isset($filterField["quickSearch"])) { $quickSearchKey = $filterField["quickSearch"].$filterField["id"]; } $filterable[$filterField["id"]] = $filterField["filterable"]; } foreach ($filterData as $fieldId => $fieldValue) { if ((is_array($fieldValue) && empty($fieldValue)) || (is_string($fieldValue) && $fieldValue == '')) { continue; } if (mb_substr($fieldId, -5) == "_from") { $realFieldId = mb_substr($fieldId, 0, mb_strlen($fieldId) - 5); if (!array_key_exists($realFieldId, $filterable)) { continue; } if (mb_substr($realFieldId, -2) == "_1") { $arFilter[$realFieldId] = $fieldValue; } else { if (!empty($filterData[$realFieldId."_numsel"]) && $filterData[$realFieldId."_numsel"] == "more") $filterPrefix = ">"; else $filterPrefix = ">="; $arFilter[$filterPrefix.$realFieldId] = trim($fieldValue); } } elseif (mb_substr($fieldId, -3) == "_to") { $realFieldId = mb_substr($fieldId, 0, mb_strlen($fieldId) - 3); if (!array_key_exists($realFieldId, $filterable)) { continue; } if (mb_substr($realFieldId, -2) == "_1") { $realFieldId = mb_substr($realFieldId, 0, mb_strlen($realFieldId) - 2); $arFilter[$realFieldId."_2"] = $fieldValue; } else { if (!empty($filterData[$realFieldId."_numsel"]) && $filterData[$realFieldId."_numsel"] == "less") $filterPrefix = "<"; else $filterPrefix = "<="; $arFilter[$filterPrefix.$realFieldId] = trim($fieldValue); } } else { if (array_key_exists($fieldId, $filterable)) { $filterPrefix = $filterable[$fieldId]; $arFilter[$filterPrefix.$fieldId] = $fieldValue; } if ($fieldId == "FIND" && trim($fieldValue) && $quickSearchKey) { $arFilter[$quickSearchKey] = $fieldValue; } } } } public function hasGroupErrors() { return (bool)(count($this->arGroupErrors)); } public function getGroupErrors() { $error = ""; foreach ($this->arGroupErrors as $groupError) { $error .= " ".$groupError[0]; } return trim($error); } public function setContextSettings(array $settings) { $this->contextSettings = $settings; } protected function GetSystemContextMenu(array $config = []): array { $result = []; /** @global CMain $APPLICATION */ global $APPLICATION; if (isset($config['excel'])) { if ($this->contextSettings["pagePath"]) { $pageParam = (!empty($_GET) ? http_build_query($_GET, "", "&") : ""); $pagePath = $this->contextSettings["pagePath"]."?".$pageParam; $pageParams = ["mode" => "excel"]; if ($this->isPublicMode) $pageParams["public"] = "y"; $link = CHTTP::urlAddParams($pagePath, $pageParams); } else { $link = CHTTP::urlAddParams($APPLICATION->GetCurPageParam(), ["mode" => "excel"]); } $link = CHTTP::urlDeleteParams($link, ["apply_filter"]); $result[] = [ "TEXT" => "Excel", "TITLE" => GetMessage("admin_lib_excel"), "LINK" => $link, "GLOBAL_ICON"=>"adm-menu-excel", ]; } return $result; } protected function InitContextMenu(array $menu = [], array $additional = []): void { if (!empty($menu) || !empty($additional)) { $this->context = new CAdminUiContextMenu($menu, $additional); } } private function GetGroupAction() { $actionPanelConstructor = new CAdminUiListActionPanel( $this->table_id, $this->arActions, $this->arActionsParams); return $actionPanelConstructor->getActionPanel(); } public function &AddRow($id = false, $arRes = Array(), $link = false, $title = false) { $row = new CAdminUiListRow($this->aHeaders, $this->table_id); $row->id = ($id ? $id : randString(4)); $row->arRes = $arRes; if ($this->isPublicMode) { $selfFolderUrl = (defined("SELF_FOLDER_URL") ? SELF_FOLDER_URL : "/bitrix/admin/"); $reqValue = "/".str_replace("/", "\/", $selfFolderUrl)."/i"; if (!empty($link) && !preg_match($reqValue, $link) && preg_match("/\.php/i", $link)) { $link = $selfFolderUrl.$link; } } $row->link = $link; $row->title = $title; $row->pList = &$this; $row->bEditMode = true; $this->aRows[] = &$row; return $row; } /** * The method set the default fields for the filter. * * @param array $fields array("fieldId1", "fieldId2", "fieldId3") */ public function setDefaultFilterFields(array $fields) { $filterOptions = new Bitrix\Main\UI\Filter\Options($this->table_id); $filterOptions->setFilterSettings( "default_filter", array("rows" => $fields), false ); $filterOptions->save(); } /** * The method set filter presets. * * @param array $filterPresets array("presetId" => array("name" => "presetName", "fields" => array(...))) */ public function setFilterPresets(array $filterPresets) { $this->filterPresets = $filterPresets; foreach ($filterPresets as $filterPreset) { if (!empty($filterPreset["current"])) { $this->currentPreset = $filterPreset; } } } public function deletePreset($presetId) { $options = new Options($this->table_id); $options->deleteFilter($presetId); $options->save(); } public function DisplayFilter(array $filterFields = array()) { global $APPLICATION; $params = array( "FILTER_ID" => $this->table_id, "GRID_ID" => $this->table_id, "FILTER" => $filterFields, "FILTER_PRESETS" => $this->filterPresets, "ENABLE_LABEL" => true, "ENABLE_LIVE_SEARCH" => true ); if ($this->currentPreset) { $options = new Options($this->table_id, $this->filterPresets); $options->setFilterSettings($this->currentPreset["id"], $this->currentPreset, true, false); $options->save(); } if ($this->context) { $this->context->setFilterContextParam(true); } if ($this->isPublicMode) { ob_start(); ?>
includeComponent( "bitrix:main.ui.filter", "", $params, false, array("HIDE_ICONS" => true) ); ?>
AddViewContent("inside_pagetitle", ob_get_clean()); } else { $APPLICATION->SetAdditionalCSS('/bitrix/css/main/grid/webform-button.css'); ?>
includeComponent( "bitrix:main.ui.filter", "", $params, false, array("HIDE_ICONS" => true) ); ?>
ShowContext(); ?>
createFilterSelectorHandlers($filterFields); ?>