%PDF- %PDF- 403WebShell
403Webshell
Server IP : 37.220.80.31  /  Your IP : 18.224.69.83
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux 3051455-guretool.twc1.net 5.15.0-107-generic #117-Ubuntu SMP Fri Apr 26 12:26:49 UTC 2024 x86_64
User : www-root ( 1010)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /var/www/www-root/data/www/dev.artlot24.ru/bitrix/components/bitrix/main.ui.grid/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/www-root/data/www/dev.artlot24.ru/bitrix/components/bitrix/main.ui.grid/class.php
<?

use Bitrix\Main\Localization\Loc;
use Bitrix\Main\Text;
use Bitrix\Main\Grid;
use Bitrix\Main\Type\Collection;
use Bitrix\Main\Web;

if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) die();

Loc::loadMessages(__FILE__);


/**
 * Class CMainUIGrid
 */
class CMainUIGrid extends CBitrixComponent
{
	/** @var \CGridOptions $gridOptions */
	protected $gridOptions;

	/** @var Bitrix\Main\Web\Uri $uri */
	protected $uri;

	/** @var array $options */
	protected $options;

	/** @var array $showedColumnsList */
	protected $showedColumnsList;

	/** @var boolean $editDate default value $this->arResult["EDIT_DATE"] */
	protected $editDate = false;

	/** @var boolean $allowEdit default value $this->arResult["ALLOW_EDIT"] */
	protected $allowEdit = false;

	/** @var boolean $allowEditAll default value $this->arResult["ALLOW_EDIT_ALL"] */
	protected $allowEditAll = false;

	/** @var boolean $allowInlineEdit default value $this->arResult["ALLOW_INLINE_EDIT"] */
	protected $allowInlineEdit = false;

	/** @var boolean $allowInlineEditAll default value $this->arResult["ALLOW_INLINE_EDIT_ALL"] */
	protected $allowInlineEditAll = false;

	/** @var array $dataForEdit default value $this->arResult["DATA_FOR_EDIT"] */
	protected $dataForEdit = array();

	/** @var array $columnsEditMeta default value $this->arResult["COLS_EDIT_META"] */
	protected $columnsEditMeta = array();

	/** @var array $columnsEditMetaAll default value $this->arResult["COLS_EDIT_META_ALL"] */
	protected $columnsEditMetaAll = array();

	/** @var string $navString default value $this->arResult["NAV_STRING"] */
	protected $navString = "";

	/** @var integer $totalRowsCount default value $this->arResult["TOTAL_ROWS_COUNT"] */
	protected $totalRowsCount = 0;

	/** @var boolean $showBottomPanel default value $this->arResult["SHOW_BOTTOM_PANEL"] */
	protected $showBottomPanel = true;

	/** @var boolean $showMoreButton default value $this->arResult["SHOW_MORE_BUTTON"] */
	protected $showMoreButton = false;

	protected $defaultPageSize = 20;

	protected $minColumnWidth = 70;
	protected $jsFolder = "/js/";
	protected $blocksFolder = "/blocks/";
	protected $cssFolder = "/css/";

	protected $defaultHeaderSectionId = '';

	protected function validateColumn($column = array())
	{
		return (is_array($column) && isset($column["id"]) && is_string($column["id"]) && !empty($column["id"]));
	}

	protected function validateColumns($columns = array())
	{
		$result = true;

		foreach ($columns as $key => $column)
		{
			if (!$this->validateColumn($column))
			{
				$result = false;
				break;
			}
		}

		return $result;
	}


	protected function checkRequiredParams()
	{
		$messages = array();
		$returns = true;


		if (!isset($this->arParams["GRID_ID"]) ||
			!is_string($this->arParams["GRID_ID"]) ||
			(is_string($this->arParams["GRID_ID"]) && empty($this->arParams["GRID_ID"])))
		{
			$messages[]["MESSAGE"] = Loc::getMessage("GRID_ID_INCORRECT");
		}

		//region Columns
		if(
			!(isset($this->arParams["COLUMNS"]) && is_array($this->arParams["COLUMNS"])) &&
			!(isset($this->arParams["HEADERS"]) && is_array($this->arParams["HEADERS"]))
		)
		{
			$messages[]["MESSAGE"] = Loc::getMessage("GRID_COLUMNS_INCORRECT");
		}
		//endregion

		if (!empty($messages))
		{
			foreach ($messages as $key => $message)
			{
				ShowMessage($message);
			}

			$returns = false;
		}

		return $returns;
	}

	private function prepareTemplateRow(): void
	{
		$templateRow = [
			'id' => 'template_0',
			'not_count' => true,
			'attrs' => [
				'hidden' => 'true',
			],
		];

		foreach ($this->arParams['ROWS'] as $key => $row)
		{
			if ($row['id'] === 'template_0')
			{
				$templateRow = array_merge($row, $templateRow);
				unset($this->arParams['ROWS'][$key]);
				break;
			}
		}

		array_unshift($this->arParams['ROWS'], $templateRow);
	}

	/**
	 * Prepares arParams
	 * @method prepareParams
	 * @return array
	 */
	protected function prepareParams()
	{
		$this->arParams["GRID_ID"] = Grid\Params::prepareString(
			array($this->arParams["GRID_ID"]),
			""
		);

		$this->arParams["SORT"] = Grid\Params::prepareArray(
			array($this->arParams["SORT"]),
			array()
		);

		//region Columns
		$this->arParams["COLUMNS"] = isset($this->arParams["COLUMNS"]) && is_array($this->arParams["COLUMNS"])
			? $this->arParams["COLUMNS"] : array();
		//For backward compatibility
		if(empty($this->arParams["COLUMNS"]))
		{
			$this->arParams["COLUMNS"] = isset($this->arParams["HEADERS"]) && is_array($this->arParams["HEADERS"])
				? $this->arParams["HEADERS"] : array();
		}
		//endregion



		$this->arParams["ROWS"] = Grid\Params::prepareArray(
			array($this->arParams["ROWS"]),
			array()
		);

		$this->arParams["TOTAL_ROWS_COUNT"] = Grid\Params::prepareInt(
			array($this->arParams["TOTAL_ROWS_COUNT"], $this->arParams["FOOTER"]["TOTAL_ROWS_COUNT"]),
			null
		);

		$this->arParams["AJAX_ID"] = Grid\Params::prepareString(
			array($this->arParams["AJAX_ID"]),
			""
		);

		$this->arParams["AGGREGATE_ROWS"] = Grid\Params::prepareArray(
			array($this->arParams["AGGREGATE_ROWS"]),
			array()
		);

		$this->arParams["NAV_PARAM_NAME"] = Grid\Params::prepareString(
			array($this->arParams["NAV_PARAM_NAME"]),
			null
		);

		$this->arParams["CURRENT_PAGE"] = Grid\Params::prepareInt(
			array($this->arParams["CURRENT_PAGE"]),
			null
		);

		$this->arParams["NAV_STRING"] = Grid\Params::prepareString(
			array($this->arParams["NAV_STRING"], $this->arParams["FOOTER"]["NAV_STRING"]),
			""
		);

		$this->arParams["ACTIONS_LIST"] = Grid\Params::prepareArray(
			array($this->arParams["ACTIONS_LIST"], $this->arParams["ACTIONS"]["list"]),
			array()
		);

		$this->arParams["PAGE_SIZES"] = Grid\Params::prepareArray(
			array($this->arParams["PAGE_SIZES"]),
			array()
		);

		$this->arParams["DEFAULT_PAGE_SIZE"] = Grid\Params::prepareInt(
			array($this->arParams["DEFAULT_PAGE_SIZE"]),
			$this->defaultPageSize
		);

		$this->arParams["ALLOW_INLINE_EDIT"] = Grid\Params::prepareBoolean(
			array($this->arParams["ALLOW_INLINE_EDIT"], $this->arParams["EDITABLE"]),
			true
		);

		$this->arParams["SHOW_ROW_ACTIONS_MENU"] = Grid\Params::prepareBoolean(
			array($this->arParams["SHOW_ROW_ACTIONS_MENU"], $this->arParams["ROW_ACTIONS"]),
			true
		);

		$this->arParams["SHOW_ROW_CHECKBOXES"] = Grid\Params::prepareBoolean(
			array($this->arParams["SHOW_ROW_CHECKBOXES"]),
			true
		);

		$this->arParams["SHOW_NAVIGATION_PANEL"] = Grid\Params::prepareBoolean(
			array($this->arParams["SHOW_NAVIGATION_PANEL"]),
			true
		);

		$this->arParams["ALLOW_GROUP_ACTIONS"] = Grid\Params::prepareBoolean(
			array($this->arParams["ALLOW_GROUP_ACTIONS"], $this->arParams["ACTION_ALL_ROWS"]),
			false
		);

		$this->arParams["SHOW_CHECK_ALL_CHECKBOXES"] = Grid\Params::prepareBoolean(
			array($this->arParams["SHOW_CHECK_ALL_CHECKBOXES"]),
			true
		);

		$this->arParams["ALLOW_CONTEXT_MENU"] = Grid\Params::prepareBoolean(
			array($this->arParams["ALLOW_CONTEXT_MENU"]),
			false
		);

		$this->arParams["SHOW_GROUP_EDIT_BUTTON"] = Grid\Params::prepareBoolean(
			array($this->arParams["SHOW_GROUP_EDIT_BUTTON"]),
			false
		);

		$this->arParams["SHOW_GROUP_DELETE_BUTTON"] = Grid\Params::prepareBoolean(
			array($this->arParams["SHOW_GROUP_DELETE_BUTTON"]),
			false
		);

		$this->arParams["SHOW_GROUP_ACTIONS_HTML"] = Grid\Params::prepareBoolean(
			array($this->arParams["SHOW_GROUP_ACTIONS_HTML"]),
			false
		);

		$this->arParams["SHOW_SELECT_ALL_RECORDS_CHECKBOX"] = Grid\Params::prepareBoolean(
			array($this->arParams["SHOW_SELECT_ALL_RECORDS_CHECKBOX"]),
			false
		);

		$this->arParams["SHOW_GRID_SETTINGS_MENU"] = Grid\Params::prepareBoolean(
			array($this->arParams["SHOW_GRID_SETTINGS_MENU"]),
			true
		);

		$this->arParams["SHOW_MORE_BUTTON"] = Grid\Params::prepareBoolean(
			array($this->arParams["SHOW_MORE_BUTTON"]),
			false
		);

		$this->arParams["SHOW_PAGINATION"] = Grid\Params::prepareBoolean(
			array($this->arParams["SHOW_PAGINATION"]),
			true
		);

		$this->arParams["SHOW_PAGESIZE"] = Grid\Params::prepareBoolean(
			array($this->arParams["SHOW_PAGESIZE"]),
			false
		);

		$this->arParams["SHOW_SELECTED_COUNTER"] = Grid\Params::prepareBoolean(
			array($this->arParams["SHOW_SELECTED_COUNTER"]),
			true
		);

		$this->arParams["SHOW_TOTAL_COUNTER"] = Grid\Params::prepareBoolean(
			array($this->arParams["SHOW_TOTAL_COUNTER"]),
			true
		);

		$this->arParams["ALLOW_COLUMNS_SORT"] = Grid\Params::prepareBoolean(
			array($this->arParams["ALLOW_COLUMNS_SORT"]),
			true
		);

		$this->arParams["ALLOW_ROWS_SORT"] = Grid\Params::prepareBoolean(
			array($this->arParams["ALLOW_ROWS_SORT"]),
			false
		);

		$this->arParams["ALLOW_ROWS_SORT_IN_EDIT_MODE"] = Grid\Params::prepareBoolean(
			array($this->arParams["ALLOW_ROWS_SORT_IN_EDIT_MODE"]),
			false
		);

		$this->arParams["ALLOW_ROWS_SORT_INSTANT_SAVE"] = Grid\Params::prepareBoolean(
			array($this->arParams["ALLOW_ROWS_SORT_INSTANT_SAVE"]),
			true
		);

		$this->arParams["ALLOW_SELECT_ROWS"] = Grid\Params::prepareBoolean(
			array($this->arParams["ALLOW_SELECT_ROWS"]),
			false
		);

		$this->arParams["ALLOW_HORIZONTAL_SCROLL"] = Grid\Params::prepareBoolean(
			array($this->arParams["ALLOW_HORIZONTAL_SCROLL"]),
			true
		);

		$this->arParams["ALLOW_SORT"] = Grid\Params::prepareBoolean(
			array($this->arParams["ALLOW_SORT"]),
			true
		);

		$this->arParams["ALLOW_COLUMNS_RESIZE"] = Grid\Params::prepareBoolean(
			array($this->arParams["ALLOW_COLUMN_RESIZE"]),
			true
		);

		$this->arParams["SHOW_ACTION_PANEL"] = Grid\Params::prepareBoolean(
			array($this->arParams["SHOW_ACTION_PANEL"]),
			true
		);

		$this->arParams["PRESERVE_HISTORY"] = isset($this->arParams["PRESERVE_HISTORY"])
			? (bool)$this->arParams["PRESERVE_HISTORY"] : false;

		$this->arParams["ENABLE_COLLAPSIBLE_ROWS"] = Grid\Params::prepareBoolean(
			array($this->arParams["ENABLE_COLLAPSIBLE_ROWS"]),
			false
		);

		$this->arParams["TILE_GRID_MODE"] = Grid\Params::prepareBoolean(
			array($this->arParams["TILE_GRID_MODE"]),
			false
		);

		$this->arParams["JS_CLASS_TILE_GRID_ITEM"] = Grid\Params::prepareString(
			array($this->arParams["JS_CLASS_TILE_GRID_ITEM"]),
			null
		);

		$this->arParams["TILE_SIZE"] = Grid\Params::prepareString(
			array($this->arParams["TILE_SIZE"]),
			null
		);

		if (is_array($this->arParams["ROW_LAYOUT"]) && !empty($this->arParams["ROW_LAYOUT"]))
		{
			$this->arParams["ALLOW_COLUMNS_SORT"] = false;
			$this->arParams["ALLOW_SORT"] = false;
		}

		$this->arParams["TOP_ACTION_PANEL_PINNED_MODE"] = Grid\Params::prepareBoolean(
			array($this->arParams["TOP_ACTION_PANEL_PINNED_MODE"]),
			false
		);

		$this->arParams["ADVANCED_EDIT_MODE"] = Grid\Params::prepareBoolean(
			array($this->arParams["ADVANCED_EDIT_MODE"]),
			false
		);

		$this->arParams["ALLOW_EDIT_SELECTION"] = Grid\Params::prepareBoolean(
			array($this->arParams["ALLOW_EDIT_SELECTION"]),
			false
		);

		$this->arParams["SETTINGS_WINDOW_TITLE"] = Grid\Params::prepareString(
			array($this->arParams["SETTINGS_WINDOW_TITLE"]),
			""
		);

		return $this->arParams;
	}


	/**
	 * Prepares arResult
	 * @method prepareResult
	 * @return $this
	 */
	protected function prepareResult()
	{
		$this->arResult["GRID_ID"] = $this->arParams["GRID_ID"];
		$this->arResult["FORM_ID"] = $this->arParams["FORM_ID"];
		$this->arResult["COLUMNS_ALL"] = $this->prepareColumnsAll();

		if (!empty($this->arParams['HEADERS_SECTIONS']) && is_array($this->arParams['HEADERS_SECTIONS']))
		{
			$this->prepareHeaderSections();
			$this->arResult["COLUMNS_ALL_WITH_SECTIONS"] = $this->getColumnsAllWithSections($this->arResult["COLUMNS_ALL"]);
		}
		$this->arResult["ENABLE_FIELDS_SEARCH"] = (
			isset($this->arParams["ENABLE_FIELDS_SEARCH"])
			&& $this->arParams["ENABLE_FIELDS_SEARCH"] === 'Y'
		);

		$this->arResult["HEADERS_ALL"] = $this->prepareColumnsAll();
		$this->arResult["COLUMNS"] = $this->prepareColumns();
		$this->arResult["HEADERS"] = $this->prepareColumns();
		$this->arResult["OPTIONS"] = $this->getOptions();
		$this->arResult["COLS_NAMES"] = $this->prepareColumnNames();
		$this->arResult["COLS_RESIZE_META"] = $this->prepareColumnsResizeMeta();
		$this->arResult["COLS_EDIT_META"] = $this->prepareColumnsEditMeta();
		$this->arResult["COLS_EDIT_META_ALL"] = $this->prepareColumnsEditMetaAll();
		$this->arResult["ROWS"] = $this->prepareRows();
		$this->arResult["TILE_GRID_ITEMS"] = $this->prepareTileGridItems();
		$this->arResult["HAS_ACTIONS"] = $this->prepareHasActions();
		$this->arResult["EDIT_DATE"] = $this->prepareEditDate();
		$this->arResult["ALLOW_EDIT"] = $this->prepareAllowEdit();
		$this->arResult["ALLOW_EDIT_ALL"] = $this->prepareAllowEditAll();
		$this->arResult["ALLOW_INLINE_EDIT"] = $this->prepareAllowInlineEdit();
		$this->arResult["ALLOW_INLINE_EDIT_ALL"] = $this->prepareAllowInlineEditAll();
		$this->arResult["DATA_FOR_EDIT"] = $this->prepareDataForEdit();
		$this->arResult["NAV_STRING"] = $this->prepareNavString();
		$this->arResult["TOTAL_ROWS_COUNT"] = $this->prepareTotalRowsCount();
		$this->arResult["SHOW_BOTTOM_PANEL"] = $this->prepareShowBottomPanel();
		$this->arResult["SHOW_MORE_BUTTON"] = $this->prepareShowMoreButton();
		$this->arResult["NEXT_PAGE"] = $this->prepareNextPage();
		$this->arResult["NEXT_PAGE_URL"] = $this->prepareNextPageUrl();
		$this->arResult["AGGREGATE"] = $this->prepareAggregate();
		$this->arResult["IS_AJAX"] = $this->prepareIsAjax();
		$this->arResult["IS_INTERNAL"] = $this->prepareIsInternalRequest();
		$this->arResult["OPTIONS_HANDLER_URL"] = $this->prepareOptionsHandlerUrl();
		$this->arResult["OPTIONS_ACTIONS"] = $this->prepareOptionsActions();
		$this->arResult["ACTIONS_LIST_JSON"] = $this->prepareActionsListJson();
		$this->arResult["ACTIONS_LIST_CURRENT_JSON"] = $this->prepareActionsListCurrentJson();
		$this->arResult["PAGE_SIZES_JSON"] = $this->preparePageSizesJson();
		$this->arResult["PANEL_ACTIONS"] = $this->preparePanelActions();
		$this->arResult["PANEL_TYPES"] = $this->preparePanelTypes();
		$this->arResult["EDITOR_TYPES"] = $this->prepareEditorTypes();
		$this->arResult["BACKEND_URL"] = $this->prepareBackendUrl();
		$this->arResult["ALLOW_CONTEXT_MENU"] = $this->arParams["ALLOW_CONTEXT_MENU"];
		$this->arResult["DEFAULT_COLUMNS"] = $this->prepareDefaultColumns();
		$this->arResult["DEPTH"] = $this->prepareDepth();
		$this->arResult["MESSAGES"] = $this->prepareMessages($this->arParams["MESSAGES"]);
		$this->arResult["LAZY_LOAD"] = $this->arParams["LAZY_LOAD"];
		$this->arResult["HAS_STICKED_COLUMNS"] = !empty($this->getGridOptions()->getStickedColumns());
		$this->arResult["HANDLE_RESPONSE_ERRORS"] = (
			isset($this->arParams["HANDLE_RESPONSE_ERRORS"])
			&& $this->arParams["HANDLE_RESPONSE_ERRORS"] === true
		);

		return $this;
	}

	protected function prepareMessages($messages = array())
	{
		$result = array();
		$isArray = is_array($messages);
		$isAssociative = ($isArray && Collection::isAssociative($messages));

		if ($isArray && $isAssociative)
		{
			$result[] = self::prepareMessage($messages);
		}

		if ($isArray && !$isAssociative)
		{
			foreach ($messages as $key => $message)
			{
				$result[] = self::prepareMessage($message);
			}
		}

		if (is_string($messages) && $messages !== "")
		{
			$result[] = self::prepareMessage($messages);
		}

		return $result;
	}


	protected static function prepareMessage($message = array())
	{
		$result = array(
			"TYPE" => Grid\MessageType::MESSAGE,
			"TITLE" => "",
			"TEXT" => ""
		);

		if (is_string($message) && $message !== "")
		{
			$result["TEXT"] = $message;
		}

		if (is_array($message))
		{
			if (isset($message["TEXT"]))
			{
				$result["TEXT"] = $message["TEXT"];
			}

			if (isset($message["TITLE"]))
			{
				$result["TITLE"] = $message["TITLE"];
			}

			if (isset($message["TYPE"]))
			{
				$result["TYPE"] = $message["TYPE"];
			}
		}

		return $result;
	}

	protected function prepareDepth()
	{
		$request = $this->request;
		return $request["depth"] !== null ? $request["depth"] : 0;
	}

	protected function prepareDefaultColumns()
	{
		$columns = array();
		$commonColumns = null;

		global $USER;
		if (!$USER->CanDoOperation("edit_other_settings"))
		{
			$commonOptions = CUserOptions::getOption("main.interface.grid", $this->arParams["GRID_ID"], array());
			if (!empty($commonOptions) &&
				isset($commonOptions["views"]["default"]["columns"]) &&
				!empty($commonOptions["views"]["default"]["columns"]))
			{
				$commonColumns = explode(",", $commonOptions["views"]["default"]["columns"]);
			}
		}

		foreach ($this->arParams["COLUMNS"] as $key => $column)
		{
			$columns[$column["id"]] = $column;
			$columns[$column["id"]]["sort_url"] = $this->arResult["COLUMNS_ALL"][$column["id"]]["sort_url"];
			$columns[$column["id"]]["sort_by"] = $this->arResult["COLUMNS_ALL"][$column["id"]]["sort"];
			$columns[$column["id"]]["sort_order"] = $this->arResult["COLUMNS_ALL"][$column["id"]]["next_sort_order"];

			if (is_array($commonColumns))
			{
				$columns[$column["id"]]["default"] = in_array($column["id"], $commonColumns);
			}
		}

		return $columns;
	}

	protected function prepareBackendUrl()
	{
		$url = $this->arParams["BACKEND_URL"];

		if (!isset($this->arParams["BACKEND_URL"]) ||
			!is_string($this->arParams["BACKEND_URL"]) ||
			empty($this->arParams["BACKEND_URL"]))
		{
			$url = $this->getUri()->getUri();
		}

		return $url;
	}

	protected function prepareEditorTypes()
	{
		return Grid\Editor\Types::getList();
	}

	protected function preparePanelTypes()
	{
		return Grid\Panel\Types::getList();
	}

	protected function preparePanelActions()
	{
		return Grid\Panel\Actions::getList();
	}

	protected function preparePageSizesJson()
	{
		if (empty($this->arResult["PAGE_SIZES_JSON"]))
		{
			$this->arResult["PAGE_SIZES_JSON"] = $this->arParams["PAGE_SIZES"];
			$this->arResult["PAGE_SIZES_JSON"] = Web\Json::encode($this->arResult["PAGE_SIZES_JSON"]);
			$this->arResult["PAGE_SIZES_JSON"] = Text\Converter::getHtmlConverter()->encode($this->arResult["PAGE_SIZES_JSON"]);
		}

		return $this->arResult["PAGE_SIZES_JSON"];
	}


	protected function prepareActionsListJson()
	{
		if (empty($this->arResult["ACTIONS_LIST_JSON"]))
		{
			$this->arResult["ACTIONS_LIST_JSON"] = $this->arParams["ACTIONS_LIST"];
			$this->arResult["ACTIONS_LIST_JSON"] = Web\Json::encode($this->arResult["ACTIONS_LIST_JSON"]);
			$this->arResult["ACTIONS_LIST_JSON"] = Text\Converter::getHtmlConverter()->encode($this->arResult["ACTIONS_LIST_JSON"]);
		}

		return $this->arResult["ACTIONS_LIST_JSON"];
	}


	protected function prepareActionsListCurrentJson()
	{
		if (empty($this->arResult["ACTIONS_LIST_CURRENT_JSON"]))
		{
			$this->arResult["ACTIONS_LIST_CURRENT_JSON"] = $this->arParams["ACTIONS_LIST"][0];
			$this->arResult["ACTIONS_LIST_CURRENT_JSON"] = Web\Json::encode($this->arResult["ACTIONS_LIST_CURRENT_JSON"]);
			$this->arResult["ACTIONS_LIST_CURRENT_JSON"] = Text\Converter::getHtmlConverter()->encode($this->arResult["ACTIONS_LIST_CURRENT_JSON"]);
		}

		return $this->arResult["ACTIONS_LIST_JSON"];
	}

	protected function prepareOptionsActions()
	{
		return Grid\Actions::getList();
	}

	/**
	 * @return string
	 */
	protected function prepareOptionsHandlerUrl()
	{
		return join("/", array($this->getPath(), "settings.ajax.php"));
	}


	/**
	 * Checks request is ajax
	 * @return bool
	 */
	protected function prepareIsAjax()
	{
		return $this->request->isAjaxRequest();
	}


	/**
	 * Checks request is internal
	 * @return bool
	 */
	protected function prepareIsInternalRequest()
	{
		return (bool)$this->request->get("internal");
	}


	/**
	 * Prepares aggregate data
	 * @method prepareAggregate
	 * @return array
	 */
	protected function prepareAggregate()
	{
		if (empty($this->arResult["AGGREGATE"]))
		{
			$this->arResult["AGGREGATE"] = $this->arParams["AGGREGATE"];
		}

		return $this->arResult["AGGREGATE"];
	}


	/**
	 * Applies user settings
	 * @method applyUserSettings
	 * @return null
	 */
	protected function applyUserSettings()
	{
		$this->applyColumnsCustomNames();
		$this->applyColumnsDisplay();
		$this->applyRowsSort();
		$this->applyColumnsSticked();
		$this->applyColumnsSort();
		$this->applyColumnsSizes();
		return $this;
	}


	protected function applyColumnsSticked()
	{
		$gridOptions = $this->getGridOptions();
		$stickedColumns = $gridOptions->getStickedColumns();

		if (is_array($stickedColumns))
		{
			$this->arResult["HAS_STICKED_COLUMNS"] = false;

			foreach ($this->arResult["COLUMNS_ALL"] as $key => $column)
			{
				$this->arResult["COLUMNS_ALL"][$key]["sticked"] = in_array($column["id"], $stickedColumns);

				if ($this->isShownColumn($column))
				{
					$this->arResult["COLUMNS"][$key]["sticked"] = in_array($column["id"], $stickedColumns);

					if (!$this->arResult["HAS_STICKED_COLUMNS"] && $this->arResult["COLUMNS"][$key]["sticked"])
					{
						$this->arResult["HAS_STICKED_COLUMNS"] = true;
					}
				}
			}
		}

		Collection::sortByColumn($this->arResult["COLUMNS"], [
			"sticked" => SORT_DESC,
			"sort_index" => SORT_ASC
		]);
	}


	/**
	 * Applies columns sort setting
	 */
	protected function applyColumnsSort()
	{
		if (count($this->getShowedColumnsList()) > 0)
		{
			$this->arResult["COLUMNS"] = array();

			foreach ($this->getShowedColumnsList() as $key => $item)
			{
				$this->arResult["COLUMNS"][$item] = $this->arResult["COLUMNS_ALL"][$item];
				$this->arResult["COLUMNS"][$item]["sort_index"] = $key;
			}

			Collection::sortByColumn($this->arResult["COLUMNS"], [
				"sticked" => SORT_DESC,
				"sort_index" => SORT_ASC
			]);
		}
	}


	/**
	 * Applies rows sort setting
	 */
	protected function applyRowsSort()
	{
		$options = $this->getCurrentOptions();
		$this->getUri()->addParams(array(
			"by" => $options["last_sort_by"],
			"order" => $options["last_sort_order"]
		));

		$this->prepareNextPageUrl();
	}


	/**
	 * Applies custom column names
	 * @method applyColumnsCustomNames
	 * @return null
	 */
	protected function applyColumnsCustomNames()
	{
		if (is_array($this->getCustomNames()) && count($this->getCustomNames()) > 0)
		{
			foreach ($this->getCustomNames() as $key => $value)
			{
				if ($this->columnExists($key))
				{
					$this->arResult["COLUMNS_ALL"][$key]["name"] = Bitrix\Main\Text\Converter::getHtmlConverter()->decode($value);
				}
			}
		}

		return $this;
	}


	/**
	 * Applies custom column display
	 * @method applyColumnsDisplay
	 * @return null
	 */
	protected function applyColumnsDisplay()
	{
		if (count($this->getShowedColumnsList()) > 0)
		{
			$this->arResult["COLUMNS"] = array();

			foreach ($this->getShowedColumnsList() as $key => $id)
			{
				$this->arResult["COLUMNS_ALL"][$id]["is_shown"] = true;
				$this->arResult["COLUMNS"][$id] = $this->arResult["COLUMNS_ALL"][$id];
				$this->arResult["COLUMNS"][$id]["sort_index"] = $key;
			}
		}

		return $this;
	}


	/**
	 * Applies custom column sizes
	 * @return $this
	 */
	protected function applyColumnsSizes()
	{
		$options = $this->getCurrentOptions();
		$colSizes = $options["columns_sizes"]["columns"];

		foreach ($this->arResult["COLUMNS"] as $key => $item)
		{
			$colSize = $colSizes[$item["id"]];

			if (is_numeric($colSize) && $item["resizeable"] !== false)
			{
				$this->arResult["COLUMNS"][$key]["width"] = $colSize;
			}
		}

		return $this;
	}


	/**
	 * Prepares next page url
	 * @method prepareNextPageUrl
	 * @return string URI
	 */
	protected function prepareNextPageUrl()
	{
		$this->getUri()->addParams(array(
			$this->arParams["NAV_PARAM_NAME"] => $this->prepareNextPage()
		));

		$this->arResult["NEXT_PAGE_URL"] = $this->getUri()->getUri();

		return $this->arResult["NEXT_PAGE_URL"];
	}


	/**
	 * Prepares next page number
	 * @method prepareNextPage
	 * @return int Page number
	 */
	protected function prepareNextPage()
	{
		if (!$this->arResult["NEXT_PAGE"])
		{
			$this->arResult["NEXT_PAGE"] = $this->arParams["CURRENT_PAGE"] + 1;
		}

		return $this->arResult["NEXT_PAGE"];
	}


	/**
	 * Prepares show more button
	 * @method prepareShowMoreButton
	 * @return boolean
	 */
	protected function prepareShowMoreButton()
	{
		$this->arResult["SHOW_MORE_BUTTON"] = $this->showMoreButton;

		if ($this->arParams["ENABLE_NEXT_PAGE"] &&
			!empty($this->arParams["NAV_PARAM_NAME"]) &&
			is_string($this->arParams["NAV_PARAM_NAME"]) &&
			!empty($this->arParams["CURRENT_PAGE"]) &&
			is_numeric($this->arParams["CURRENT_PAGE"])
		)
		{
			$this->arResult["SHOW_MORE_BUTTON"] = true;
		}

		return $this->arResult["SHOW_MORE_BUTTON"];
	}


	/**
	 * Prepares show bottom panels
	 * @method prepareShowBottomPanel
	 * @return boolean
	 */
	protected function prepareShowBottomPanel()
	{
		if (!is_bool($this->arResult["SHOW_BOTTOM_PANEL"]))
		{
			$this->arResult["SHOW_MORE_BUTTON"] = $this->showBottomPanel;

			if (!$this->prepareNavString() && !$this->prepareTotalRowsCount())
			{
				$this->arResult["SHOW_BOTTOM_PANEL"] = false;
			}
		}

		return $this->arResult["SHOW_BOTTOM_PANEL"];
	}



	/**
	 * Prepares total rows count
	 * @method prepareTotalRowsCount
	 * @return integer
	 */
	protected function prepareTotalRowsCount()
	{
		if (!is_numeric($this->arResult["TOTAL_ROWS_COUNT"]))
		{
			$this->arResult["TOTAL_ROWS_COUNT"] = $this->arParams["TOTAL_ROWS_COUNT"];

			if (!is_numeric($this->arResult["TOTAL_ROWS_COUNT"]))
			{
				$this->arResult["TOTAL_ROWS_COUNT"] = $this->totalRowsCount;
			}
		}

		return $this->arResult["TOTAL_ROWS_COUNT"];
	}


	/**
	 * Prepares pagination string
	 * @method prepareNavString
	 * @return string
	 */
	protected function prepareNavString()
	{
		global $APPLICATION;

		if (!is_string($this->arResult["NAV_STRING"]))
		{
			$this->arResult["NAV_STRING"] = $this->navString;

			if ($this->arParams["NAV_STRING"] <> '')
			{
				$this->arResult["NAV_STRING"] = $this->arParams["NAV_STRING"];
			}
			elseif(is_object($this->arParams["NAV_OBJECT"]))
			{
				if(!is_array($this->arParams["~NAV_PARAMS"]))
				{
					$this->arParams["~NAV_PARAMS"] = array();
				}

				if(($nav = $this->arParams["NAV_OBJECT"]) instanceof \Bitrix\Main\UI\PageNavigation)
				{
					$params = array_merge(
						array(
							"NAV_OBJECT" => $nav,
							"PAGE_WINDOW" => 5,
							"SHOW_ALWAYS" => true,
						),
						$this->arParams["~NAV_PARAMS"]
					);

					ob_start();

					$APPLICATION->IncludeComponent(
						"bitrix:main.pagenavigation",
						"grid",
						$params,
						false,
						array(
							"HIDE_ICONS" => "Y",
						)
					);

					$this->arResult["NAV_STRING"] = ob_get_clean();
				}
				else
				{
					/** @noinspection PhpUndefinedClassInspection */
					/** @var CDBResult $nav */
					$nav = $this->arParams["NAV_OBJECT"];
					$nav->nPageWindow = 5;
					$this->arResult["NAV_STRING"] = $nav->GetPageNavStringEx($dummy, "", "grid", true, null, $this->arParams["~NAV_PARAMS"]);
				}
			}
		}

		return $this->arResult["NAV_STRING"];
	}


	/**
	 * Prepares data for edit form
	 * @method prepareDataForEdit
	 * @return array
	 */
	protected function prepareDataForEdit()
	{
		if (!is_array($this->arResult["DATA_FOR_EDIT"]))
		{
			$this->arResult["DATA_FOR_EDIT"] = $this->dataForEdit;

			foreach ($this->prepareRows() as $rowKey => $rowItem)
			{
				if ($rowItem["editable"] === false)
				{
					continue;
				}

				$id = !empty($rowItem["id"]) ? $rowItem["id"] : $rowItem["data"]["ID"];

				foreach ($this->prepareColumnsAll() as $headerKey => $headerItem)
				{
					if (isset($headerItem["editable"]) && $headerItem["editable"] !== false)
					{
						if (isset($rowItem["editable"][$headerKey]) && $rowItem["editable"][$headerKey] === false)
						{
							$this->arResult["DATA_FOR_EDIT"][$id][$headerKey] = false;
						}
						else
						{
							$this->arResult["DATA_FOR_EDIT"][$id][$headerKey] = isset($rowItem["data"]["~".$headerKey])
								? $rowItem["data"]["~".$headerKey] : $rowItem["data"][$headerKey];
						}
					}
				}
			}
		}

		return $this->arResult["DATA_FOR_EDIT"];
	}


	/**
	 * Prepares $this->arResult["ALLOW_INLINE_EDIT_ALL"] value
	 * @method prepareAllowInlineEditAll
	 * @return boolean
	 */
	protected function prepareAllowInlineEditAll()
	{
		if (!is_bool($this->arResult["ALLOW_INLINE_EDIT_ALL"]))
		{
			$this->arResult["ALLOW_INLINE_EDIT_ALL"] = $this->allowInlineEditAll;

			foreach ($this->prepareColumnsAll() as $key => $item)
			{
				if (isset($item["editable"]) && $item["editable"])
				{
					$this->arResult["ALLOW_INLINE_EDIT_ALL"] = true;
					break;
				}
			}
		}

		return $this->arResult["ALLOW_INLINE_EDIT_ALL"];
	}


	/**
	 * Prepares $this->arResult["ALLOW_INLINE_EDIT"] value
	 * @method prepareAllowInlineEdit
	 * @return boolean
	 */
	protected function prepareAllowInlineEdit()
	{
		if (!is_bool($this->arResult["ALLOW_INLINE_EDIT"]))
		{
			$this->arResult["ALLOW_INLINE_EDIT"] = $this->allowInlineEdit;

			foreach ($this->prepareRows() as $key => $item)
			{
				if (
					$item['id'] !== 'template_0'
					&& $this->arResult["ALLOW_INLINE_EDIT"] === $this->allowInlineEdit
				)
				{
					$this->arResult["ALLOW_INLINE_EDIT"] = ($item["editable"] !== false);
				}
			}
		}

		return $this->arResult["ALLOW_INLINE_EDIT"];
	}


	/**
	 * Prepares $this->arResult["ALLOW_EDIT"] value
	 * @method prepareAllowEdit
	 * @return boolean
	 */
	protected function prepareAllowEdit()
	{
		if (!is_bool($this->arResult["ALLOW_EDIT"]))
		{
			$this->arResult["ALLOW_EDIT"] = $this->allowEdit;
			$this->arResult["ALLOW_EDIT"] = $this->prepareAllowInlineEdit() || $this->prepareHasActions();
		}

		return $this->arResult["ALLOW_EDIT"];
	}


	/**
	 * Prepares $arResult["ALLOW_EDIT"] value
	 * @method prepareAllowEdit
	 * @return boolean
	 */
	protected function prepareAllowEditAll()
	{
		if (!is_bool($this->arResult["ALLOW_EDIT_ALL"]))
		{
			if ($this->arParams["EDITABLE"] && $this->prepareHasActions())
			{
				$this->arResult["ALLOW_EDIT_ALL"] = true;
			}
		}

		return $this->arResult["ALLOW_EDIT_ALL"];
	}


	/**
	 * Prepares $this->arResult["EDIT_DATE"]) value
	 * @method prepareEditDate
	 * @return boolean
	 */
	protected function prepareEditDate()
	{
		if (!is_bool($this->arResult["EDIT_DATE"]))
		{
			$this->arResult["EDIT_DATE"] = $this->editDate;

			foreach ($this->prepareColumnsAll() as $key => $item)
			{
				if ($this->arParams["EDITABLE"] && $item["editable"] !== false && $item["type"] === "date")
				{
					$this->arResult["EDIT_DATE"] = true;
					break;
				}
			}
		}

		return $this->arResult["EDIT_DATE"];
	}


	/**
	 * Prepares $this->arResult["HAS_ACTION"]) value
	 * @method prepareHasActions
	 * @return boolean
	 */
	protected function prepareHasActions()
	{
		if (!is_bool($this->arResult["HAS_ACTIONS"]))
		{
			$this->arResult["HAS_ACTIONS"] = (
				is_array($this->arParams["ACTIONS"]) &&
				count($this->arParams["ACTIONS"]) > 0
			);
		}

		return $this->arResult["HAS_ACTIONS"];
	}

	protected function compatibleActions($actions, &$row)
	{
		foreach ($actions as $key => $action)
		{
			if (isset($action["SEPARATOR"]))
			{
				$isDelimiter = $action["SEPARATOR"];

				$actions[$key]["delimiter"] = $isDelimiter;
				unset($actions[$key]["SEPARATOR"]);

				if($isDelimiter)
				{
					continue;
				}
			}

			if (isset($action["ICONCLASS"]))
			{
				$actions[$key]["className"] = $action["ICONCLASS"];
				unset($actions[$key]["ICONCLASS"]);
			}

			if (isset($action["TITLE"]))
			{
				$actions[$key]["title"] = $action["TITLE"];
				unset($actions[$key]["TITLE"]);
			}

			if (isset($action["TEXT"]))
			{
				$actions[$key]["text"] = $action["TEXT"];
				unset($actions[$key]["TEXT"]);
			}

			if (isset($action["ONCLICK"]))
			{
				$actions[$key]["onclick"] = $action["ONCLICK"];
				unset($actions[$key]["ONCLICK"]);
			}

			if (isset($action["DEFAULT"]))
			{
				$actions[$key]["default"] = $action["DEFAULT"];
				unset($actions[$key]["DEFAULT"]);
			}

			if (isset($action["MENU"]) && is_array($action["MENU"]) && !empty($action["MENU"]))
			{
				$actions[$key]["items"] = $this->compatibleActions($action["MENU"], $row);
				unset($actions[$key]["MENU"]);
			}

			if (isset($action["HREF"]))
			{
				$actions[$key]["href"] = $action["HREF"];
				unset($actions[$key]["HREF"]);
			}

			if (isset($row["default_action"]) && is_array($row["default_action"]))
			{
				if (isset($row["default_action"]["href"]) && is_string($row["default_action"]["href"]))
				{
					$row["default_action"]["js"] = "(window.location = '".$row["default_action"]["href"]."')";
				}
				elseif (isset($row["default_action"]["onclick"]) && is_string($row["default_action"]["onclick"]))
				{
					$row["default_action"]["js"] = $row["default_action"]["onclick"];
				}
			}
			else
			{
				if ($action["default"] === true)
				{
					$row["default_action"] = array();

					if (isset($action["onclick"]) && is_string($action["onclick"]))
					{
						$row["default_action"]["js"] = $action["onclick"];
					}

					if (isset($action["href"]) && is_string($action["href"]))
					{
						$row["default_action"]["js"] = "(window.location = '".$action["href"]."')";
					}

					$row["default_action"]["title"] = isset($action["text"]) ? $action["text"] : "";
				}
			}
		}

		return $actions;
	}


	protected function compatibleRow($row)
	{
		if (isset($row["actions"]) && is_array($row["actions"]) && !empty($row["actions"]))
		{
			$row["actions"] = $this->compatibleActions($row["actions"], $row);
		}

		if(!isset($row["id"]))
		{
			$row["id"] = $row["data"]["ID"];
		}

		return $row;
	}


	/**
	 * Prepares rows
	 * @method prepareRows
	 * @return array
	 */
	protected function prepareRows()
	{
		foreach ($this->arParams["ROWS"] as $key => $row)
		{
			//Prepare default values
			$actualRow = $this->compatibleRow($row);
			if(isset($this->arParams["COLUMNS"]) && (isset($actualRow["columns"]) || isset($actualRow["data"])))
			{
				foreach($this->arParams["COLUMNS"] as $header)
				{
					$id = $header["id"];
					if(!isset($actualRow["columns"][$id]) && isset($actualRow["data"][$id]))
					{
						$actualRow["columns"][$id] = $actualRow["data"][$id];
					}
				}
			}
			$this->arParams["ROWS"][$key] = $actualRow;

			if (!isset($this->arParams["ROWS"][$key]["editableColumns"]))
			{
				$this->arParams["ROWS"][$key]["editableColumns"] = [];
			}
		}

		return $this->arParams["ROWS"];
	}

	protected function prepareTileGridItems()
	{
		if (!$this->arParams['TILE_GRID_MODE'])
		{
			return null;
		}
		$this->setTemplateName('tilegrid');

		if (isset($this->arParams['TILE_GRID_ITEMS']))
		{
			return $this->arParams['TILE_GRID_ITEMS'];
		}

		return $this->reformatRowsToTileGridItems($this->arParams['ROWS']);
	}

	protected function reformatRowsToTileGridItems($rows)
	{
		$items = [];

		foreach ($rows as $row)
		{
			$items[] = [
				'id' => $row['ID'],
				'name' => isset($row['NAME'])? $row['NAME'] : null,
				'image' => isset($row['IMAGE'])? $row['IMAGE'] : null,
			];
		}

		return $items;
	}

	protected function prepareColumnsEditMeta()
	{
		if (!is_array($this->arResult["COLS_EDIT_META"]))
		{
			$this->arResult["COLS_EDIT_META"] = $this->columnsEditMeta;
			$columns = $this->prepareColumnsEditMetaAll();

			foreach ($this->prepareColumns() as $key => $item)
			{
				$this->arResult["COLS_EDIT_META"][$key] = $columns[$key];
			}
		}

		return $this->arResult["COLS_EDIT_META"];
	}


	/**
	 * Prepares $this->arResult["COLS_EDIT_META_ALL"] value
	 * @method prepareColumnsEditMetaAll
	 * @return array
	 */
	protected function prepareColumnsEditMetaAll()
	{
		if (!is_array($this->arResult["COLS_EDIT_META_ALL"]))
		{
			$this->arResult["COLS_EDIT_META_ALL"] = $this->columnsEditMetaAll;

			foreach ($this->prepareColumnsAll() as $key => $item)
			{
				$this->arResult["COLS_EDIT_META_ALL"][$key] = array(
					"editable" => $item["editable"] ? true : false,
					"type" => $item["type"] ? $item["type"] : Grid\Types::GRID_TEXT
				);

				if ($this->arParams["EDITABLE"] && is_array($item["editable"]))
				{
					foreach ($item["editable"] as $attrKey => $attrValue)
					{
						$this->arResult["COLS_EDIT_META_ALL"][$key][$attrKey] = $attrValue;
					}
				}
			}
		}

		return $this->arResult["COLS_EDIT_META_ALL"];
	}


	/**
	 * Prepares $this->arResult["COLS_RESIZE_META"] value
	 * @method prepareColumnsResizeMeta
	 * @return array
	 */
	protected function prepareColumnsResizeMeta()
	{
		if (empty($this->arResult["COLS_RESIZE_META"]))
		{
			$this->arResult["COLS_RESIZE_META"] = array("expand" => 1, "columns" => array());
		}

		return $this->arResult["COLS_RESIZE_META"];
	}


	/**
	 * Prepares $this->arResult["COLS_NAMES"] value
	 * @method prepareColumnNames
	 * @return array
	 */
	protected function prepareColumnNames()
	{
		if (empty($this->arResult["COLS_NAMES"]))
		{
			$this->arResult["COLS_NAMES"] = array();

			foreach ($this->prepareColumnsAll() as $key => $item)
			{
				$this->arResult["COLS_NAMES"][$key] = $item["name"];
			}
		}

		return $this->arResult["COLS_NAMES"];
	}


	/**
	 * Gets deleted query string params
	 * @method getDeleteParams
	 * @return array params list
	 */
	protected function getDeleteParams()
	{
		$sortParams = array(
			"bxajaxid",
			"AJAX_CALL",
			$this->arParams["SORT_VARS"]["by"],
			$this->arParams["SORT_VARS"]["order"]
		);

		return $sortParams;
	}


	/**
	 * Gets options
	 * @method getOptions
	 * @return array
	 */
	protected function getOptions()
	{
		return $this->getGridOptions()->GetOptions();
	}


	/**
	 * @return Grid\Options|CGridOptions
	 */
	protected function getGridOptions()
	{
		if (!($this->gridOptions instanceof Grid\Options))
		{
			$this->gridOptions = new Grid\Options($this->arParams["GRID_ID"]);
		}

		return $this->gridOptions;
	}


	/**
	 * Gets current view options
	 * @method getCurrentOptions
	 * @return array
	 */
	protected function getCurrentOptions()
	{
		$options = $this->getOptions();
		return $options["views"][$options["current_view"]];
	}


	/**
	 * Gets uri object
	 * @method getUri
	 * @return Bitrix\Main\Web\Uri instance with current request uri
	 */
	protected function getUri()
	{
		if (!($this->uri instanceof Web\Uri))
		{
			$this->uri = new Web\Uri($this->request->getRequestUri());
			$this->uri->deleteParams($this->getDeleteParams());

			if (!empty($this->arParams['TAB_ID']) && !empty($this->arParams["FORM_ID"]))
			{
				$this->uri->addParams(array(
					$this->arParams["FORM_ID"]."_active_tab" => $this->arParams["TAB_ID"]
				));
			}
		}

		return $this->uri;
	}


	/**
	 * Gets sort url
	 * @method getSortUrl
	 * @param  array $headerItem
	 * @return string sort url
	 */
	protected function getSortUrl(array $headerItem)
	{
		$this->getUri()->addParams(array(
			"by" => $headerItem["sort"],
			"order" => $headerItem["next_sort_order"]
		));

		return $this->getUri()->getUri();
	}

	protected function columnExists($id)
	{
		$result = false;

		if (is_array($this->arParams["COLUMNS"]) && !empty($this->arParams["COLUMNS"]))
		{
			foreach ($this->arParams["COLUMNS"] as $key => $column)
			{
				if ($column["id"] == $id)
				{
					$result = true;
				}
			}
		}

		return $result;
	}

	/**
	 * Gets showed columns list
	 * @method getShowedColumnsList
	 * @return array
	 */
	protected function getShowedColumnsList()
	{
		if (empty($this->showedColumnsList))
		{
			$options = $this->getCurrentOptions();
			$tmp = explode(",", $options["columns"]);

			$this->showedColumnsList = array();

			foreach ($tmp as $key => $item)
			{
				$item = trim($item);

				if (!empty($item) && $this->columnExists($item))
				{
					$this->showedColumnsList[] = $item;
				}
			}
		}

		return $this->showedColumnsList;
	}


	/**
	 * Checks is user enabled column
	 * @method isUserShowedColumn
	 * @param  string $id column id
	 * @return boolean
	 */
	protected function isUserShowedColumn($id)
	{
		return in_array($id, $this->getShowedColumnsList());
	}


	/**
	 * Prepares align value
	 * @method prepareAlign
	 * @param  array $headerItem header item
	 * @return string css align property value
	 */
	protected function prepareAlign($headerItem)
	{
		return $headerItem['align'] ?? "left";
	}


	/**
	 * Prepares string
	 * @method prepareString
	 * @param  string $text source string
	 * @return string prepared string
	 */
	protected function prepareString($text)
	{
		return Text\Converter::getHtmlConverter()->encode($text);
	}


	/**
	 * Gets custom column names
	 * @method getCustomNames
	 * @return array [column_id] => column_name
	 */
	protected function getCustomNames()
	{
		$options = $this->getCurrentOptions();
		return $options["custom_names"];

	}


	/**
	 * Prepares header name
	 * @method prepareHeaderName
	 * @param  array $headerItem header item
	 * @return string prepared header name
	 */
	protected function prepareHeaderName(array $headerItem)
	{
		return $headerItem["name"];
	}


	/**
	 * Checks is shown header name for current header item
	 * @method isShowHeaderName
	 * @param  array $headerItem
	 * @return boolean
	 */
	protected function isShowHeaderName(array $headerItem)
	{
		$isShow = true;

		if ($headerItem['showname'] === false || $headerItem['showname'] === "N")
		{
			$isShow = false;
		}

		return $isShow;
	}


	/**
	 * Prepares sort order value
	 * @method prepareSortOrder
	 * @param  array $headerItem header item
	 * @return string sort order value ["desc", "asc"]
	 */
	protected function prepareSortOrder(array $headerItem)
	{
		$sort = $headerItem["ORDER"] === "desc" ? "desc" : "asc";

		if (isset($headerItem["first_order"]) && is_string($headerItem["first_order"]))
		{
			$sort = $headerItem["first_order"];
		}

		return $sort;
	}


	/**
	 * Checks is shown current column
	 * @method isShownColumn
	 * @param  array $headerItem header item
	 * @return boolean
	 */
	protected function isShownColumn(array $headerItem)
	{
		return $headerItem["default"];
	}


	/**
	 * Prepares sort state value
	 * @method prepareSortState
	 * @param  array $headerItem header item
	 * @return string ["desc", "asc"]
	 */
	protected function prepareSortState(array $headerItem)
	{
		$state = null;

		if (isset($this->arParams["SORT"]) &&
			is_array($this->arParams["SORT"]) &&
			(is_string($headerItem["sort"]) || is_int($headerItem["sort"])) &&
			array_key_exists($headerItem["sort"], $this->arParams["SORT"]))
		{
			$state = $this->arParams["SORT"][$headerItem["sort"]];
		}
		else
		{
			$options = $this->getCurrentOptions();

			if ($options["last_sort_by"] === $headerItem["sort"])
			{
				$state = $options["last_sort_order"];
			}
		}

		return $state;
	}

	protected function prepareNextSortOrder(array $headerItem)
	{
		$sortState = $this->prepareSortState($headerItem);

		if ($sortState)
		{
			$nextSort = $sortState === "asc" ? "desc" : "asc";
		}
		else
		{
			$nextSort = $this->prepareSortOrder($headerItem);
		}

		return $nextSort;
	}

	protected function prepareSort($sort)
	{
		return $sort;
	}


	protected function prepareEditable($column)
	{
		$result = isset($column["editable"]) ? $column["editable"] : false;
		//For backward compatibility
		if($result === true)
		{
			$result = array();
		}

		if(is_array($result))
		{
			if(!(isset($result["NAME"]) && is_string($result["NAME"]) && $result["NAME"] !== ""))
			{
				$result["NAME"] = $column["id"];
			}

			$typeName = isset($result["TYPE"]) && is_string($result["TYPE"]) ? $result["TYPE"] : "";
			if($typeName === "")
			{
				$columnTypeName = isset($column["type"]) && is_string($column["type"]) ? $column["type"] : "";
				if($columnTypeName === "")
				{
					$columnTypeName = "text";
				}

				if($columnTypeName === "text")
				{
					$typeName = Grid\Editor\Types::TEXT;
				}
				elseif($columnTypeName === "int" || $columnTypeName === "double" || $columnTypeName === "number")
				{
					$typeName = Grid\Editor\Types::NUMBER;
				}
				elseif($columnTypeName === "checkbox")
				{
					$typeName = Grid\Editor\Types::CHECKBOX;
				}
				elseif($columnTypeName === "date")
				{
					$typeName = Grid\Editor\Types::DATE;
				}
				elseif($columnTypeName === "list")
				{
					$typeName = Grid\Editor\Types::DROPDOWN;
				}
				elseif($columnTypeName === "multiselect")
				{
					$typeName = Grid\Editor\Types::MULTISELECT;
				}
				elseif($columnTypeName === "money")
				{
					$typeName = Grid\Editor\Types::MONEY;
				}
				$result["TYPE"] = $typeName;
			}

			if($result["TYPE"] === Grid\Editor\Types::MONEY	&& is_array($result["CURRENCY_LIST"]))
			{
				$currencyList = is_array($result["CURRENCY_LIST"]) ? $result["CURRENCY_LIST"] : [];
				$result["CURRENCY_LIST"] = [];
				foreach($currencyList as $k => $v)
				{
					$result["CURRENCY_LIST"][] = array("VALUE" => $k, "NAME" => $v);
				}
			}

			if (
				(
					$result["TYPE"] === Grid\Editor\Types::DROPDOWN
					|| $result["TYPE"] === Grid\Editor\Types::MULTISELECT
				)
				&& $result["items"] && is_array($result["items"])
				&& !(
					isset($result["DATA"])
					&& isset($result["DATA"]["ITEMS"])
					&& is_array($result["DATA"]["ITEMS"])
				)
			)
			{
				if(!isset($result["DATA"]))
				{
					$result["DATA"] = array();
				}

				if(!isset($result["DATA"]["ITEMS"]))
				{
					$result["DATA"]["ITEMS"] = array();
				}

				foreach($result["items"] as $k => $v)
				{
					$result["DATA"]["ITEMS"][] = array("VALUE" => $k, "NAME" => $v);
				}

				unset($result["items"]);
			}
		}

		return $result;
	}


	/**
	 * Prepares each column
	 * @method prepareColumn
	 * @param  array $column header item
	 * @return array prepared header item
	 */
	protected function prepareColumn(array $column)
	{
		$column["sort_state"] = $this->prepareSortState($column);
		$column["next_sort_order"] = $this->prepareNextSortOrder($column);
		$column["order"] = $this->prepareSortOrder($column);
		$column["sort_url"] = $this->getSortUrl($column);
		$column["sort"] = $this->prepareSort($column["sort"]);
		$column["showname"] = $this->isShowHeaderName($column);
		$column["original_name"] = $column["name"];
		$column["name"] = $this->prepareHeaderName($column);
		$column["align"] = $this->prepareAlign($column);
		$column["is_shown"] = $this->isShownColumn($column);
		$column["class"] = $this->prepareHeaderClass($column);
		$column["width"] = $this->prepareColumnWidth($column);
		$column["editable"] = $this->prepareEditable($column);
		$column["prevent_default"] = $this->preparePreventDefault($column);
		$column["sticked"] = $this->prepareSticked($column);
		$column["sticked_default"] = json_encode($this->prepareSticked($column));
		return $column;
	}

	protected function prepareColumnHeaderLayout($column): array
	{
		return [
			"cell" => [
				"class" => $this->prepareColumnHeaderClass($column),
				"attributes" => static::stringifyAttrs([
					"data-edit" => $column["editable"],
					"data-name" => $column["id"],
					"data-sort-url" => $column["sort_url"],
					"data-sort-by" => $column["sort"],
					"data-sort-order" => $column["next_sort_order"],
					"title" => $column["title"],
					"style" => $this->prepareColumnHeaderStyle($column),
				]),
			],
			"container" => [
				"attributes" => static::stringifyAttrs([
					"style" => $this->prepareColumnHeaderContainerStyle($column),
				]),
			],
		];
	}

	protected function prepareRowClass($row, $options = []): string
	{
		$rowClass = "";
		if (isset($row["not_count"]) && $row["not_count"])
		{
			$rowClass .= " main-grid-not-count";
		}

		if (isset($row["expand"]) && $row["expand"])
		{
			$rowClass .= " main-grid-row-expand";
		}

		if (isset($row["draggable"]) && $row["draggable"] === false)
		{
			$rowClass .= " main-grid-row-drag-disabled";
		}

		if (
			isset($this->arParams["ENABLE_COLLAPSIBLE_ROWS"])
			&& $this->arParams["ENABLE_COLLAPSIBLE_ROWS"]
			&& isset($row["parent_group_id"])
			&& $row["parent_group_id"] === $options['lastCollapsedGroupId']
		)
		{
			$rowClass .= " main-grid-hide";
		}

		return $rowClass;
	}

	protected function prepareRowLayout($row, $options = []): array
	{
		$attributes = [
			"data-child-loaded" => (bool)$row["expand"],
			"data-depth" => (int)$row["depth"],
			"data-id" => $row["id"],
		];

		if (isset($this->arParams["ENABLE_COLLAPSIBLE_ROWS"]))
		{
			$attributes["data-parent-id"] = $row["parent_id"];
		}

		if (isset($row["default_action"]) && !empty($row["default_action"]))
		{
			$attributes["data-default-action"] = $row["default_action"]["js"];
			$attributes["title"] = Loc::getMessage("interface_grid_dblclick") . $row["default_action"]["title"];
		}

		if (isset($row["attrs"]) && is_array($row["attrs"]))
		{
			$attributes = array_merge($row["attrs"], $attributes);
		}

		return [
			"row" => [
				"class" => $this->prepareRowClass($row, $options['lastCollapsedGroupId']),
				"attributes" => static::stringifyAttrs($attributes),
			],
			"columns" => $this->prepareRowColumns($row, $options),
		];
	}

	protected function prepareRowColumns($row, $options): array
	{
		$checkboxInputAttributes = [
			"id" => "checkbox_" . $this->arParams["GRID_ID"] . "_" . $row["id"],
			"name" => "ID[]",
			"value" => $row["id"],
		];

		if ($row["editable"] !== false)
		{
			$checkboxInputAttributes["title"] = Loc::getMessage("interface_grid_check");
		}

		if (!$this->arResult["ALLOW_EDIT"] || $row["editable"] === false)
		{
			$checkboxInputAttributes["data-disabled"] = 1;
			$checkboxInputAttributes["disabled"] = "";
		}

		$columns = [
			"drag" => [
				"cell" => [
					"enabled" => (
						$this->arParams["ALLOW_ROWS_SORT"]
						&& $row["draggable"] !== false
					),
				],
			],
			"checkbox" => [
				"cell" => [
					"enabled" => $this->arParams["SHOW_ROW_CHECKBOXES"],
				],
				"input" => [
					"attributes" => static::stringifyAttrs($checkboxInputAttributes),
				],
			],
			"actions" => [
				"cell" => [
					"enabled" => (
						$this->arParams["SHOW_ROW_ACTIONS_MENU"]
						|| $this->arParams["SHOW_GRID_SETTINGS_MENU"]
					),
				],
				"button" => [
					"enabled" => (
						!empty($row["actions"])
						&& $this->arParams["SHOW_ROW_ACTIONS_MENU"]
					),
					"attributes" => static::stringifyAttrs([
						"data-actions" => $row["actions"],
					]),
				],
			],
		];

		foreach ($this->arResult["COLUMNS"] as $columnId => $column)
		{
			$cellClass = "main-grid-cell";
			if (isset($column["align"]) && is_string($column["align"]))
			{
				$cellClass .= " main-grid-cell-{$column["align"]}";
			}
			if (
				isset($row["columnClasses"])
				&& is_array($row["columnClasses"])
				&& array_key_exists($column["id"], $row["columnClasses"])
			)
			{
				$cellClass .= " {$row["columnClasses"][$column["id"]]}";
			}

			$cellAttributes = [];
			$cellStyle = "";
			if (
				$this->arParams["ENABLE_COLLAPSIBLE_ROWS"]
				&& isset($column["shift"])
				&& $column["shift"] === true
			)
			{
				$cellAttributes["data-shift"] = true;
				if (isset($row["depth"]) && $row["depth"] > 0)
				{
					$offsetLeft = 20;
					$paddingLeft = $row["depth"] * $offsetLeft;
					$cellStyle .= "padding-left: {$paddingLeft}px";
				}
			}

			if (
				isset($column["color"])
				&& is_string($column["color"])
			)
			{
				if (
					strpos($column["color"], "#") === 0
					|| strpos($column["color"], "rgb") === 0
					|| strpos($column["color"], "hsl") === 0
				)
				{
					$cellStyle .= "background-color: {$column["color"]}";
				}
				else
				{
					$cellClass .= " " . $column["color"];
				}
			}

			$cellAttributes["data-editable"] = (
				!isset($row["editableColumns"][$column["id"]])
				|| (
					isset($row["editableColumns"][$column["id"]])
					&& $row["editableColumns"][$column["id"]] === true
				)
			);

			$cellAttributes["style"] = $cellStyle;

			$containerAttributes = [];
			if (isset($column["prevent_default"]))
			{
				$containerAttributes["data-prevent-default"] = $column["prevent_default"] ? "true" : "false";
			}

			$isPlusButtonEnabled = (
				$this->arParams["ENABLE_COLLAPSIBLE_ROWS"]
				&& $row["has_child"] === true
				&& $column["shift"] === true
			);

			$isCellActionsEnabled = $options["hasCellActions"][$column['id']] === true;
			$cellActions = [];
			if (
				isset($row['cellActions'][$column['id']])
				&& is_array($row['cellActions'][$column['id']])
				&& !empty($row['cellActions'][$column['id']])
			)
			{
				$isCellActionsEnabled = true;
				foreach ($row['cellActions'][$column['id']] as $action)
				{
					$buttonClass = $action['class'];
					if (is_array($buttonClass))
					{
						$buttonClass = implode(' ', $buttonClass);
					}


					$actionAttributes = [];
					if (isset($action['events']) && is_array($action['events']))
					{
						$actionAttributes['data-events'] = $action['events'];
					}

					if (isset($action['attributes']) && is_array($action['attributes']))
					{
						$actionAttributes = array_merge(
							$actionAttributes,
							$action['attributes']
						);
					}

					$cellActions[] = array_merge(
						$action,
						[
							'class' => ' ' . $buttonClass,
							'attributes' => static::stringifyAttrs($actionAttributes),
						]
					);
				}
			}

			$counter = [
				"enabled" => false,
				"inner" => [
					"enabled" => false,
				],
				"counter" => [
					"class" => " " . Grid\Counter\Color::DANGER,
					"attributes" => "",
				],
			];
			if (
				isset($row["counters"])
				&& is_array($row["counters"])
				&& isset($row["counters"][$column["id"]])
				&& is_array($row["counters"][$column["id"]])
				&& !empty($row["counters"][$column["id"]])
			)
			{
				$counter["enabled"] = true;

				$counterOptions = $row["counters"][$column["id"]];
				if (isset($counterOptions["type"]) && is_string($counterOptions["type"]))
				{
					if ($counterOptions["type"] === Grid\Counter\Type::LEFT)
					{
						$counter["class"] = " main-grid-cell-counter-left";
						$counter["align"] = "left";
					}

					if ($counterOptions["type"] === Grid\Counter\Type::LEFT_ALIGNED)
					{
						$counter["class"] = " main-grid-cell-counter-left-aligned";
						$counter["align"] = "left";
					}

					if ($counterOptions["type"] === Grid\Counter\Type::RIGHT)
					{
						$counter["class"] = " main-grid-cell-counter-right";
						$counter["align"] = "right";
					}
				}

				if (
					isset($counterOptions["value"])
					&& !empty($counterOptions["value"])
					&& (
						is_string($counterOptions["value"])
						|| is_numeric($counterOptions["value"])
					)
				)
				{
					$counter["inner"]["enabled"] = true;
				}

				if (
					isset($counterOptions["color"])
					&& !empty($counterOptions["color"])
					&& is_string($counterOptions["color"])
				)
				{
					$counter["counter"]["class"] = " " . $counterOptions["color"];
				}

				if (
					isset($counterOptions["size"])
					&& !empty($counterOptions["size"])
					&& is_string($counterOptions["size"])
				)
				{
					$counter["counter"]["class"] .= " " . $counterOptions["size"];
				}
				if (isset($counterOptions["events"]) && is_array($counterOptions["events"]))
				{
					$counter["counter"]["attributes"] = static::stringifyAttrs([
						"data-events" => $counterOptions["events"],
					]);
				}
				if (isset($counterOptions["class"]) && is_string($counterOptions["class"]))
				{
					$counter["counter"]["class"] .= " " . $counterOptions["class"];
				}
			}
			else if ($column["layout"]["hasLeftAlignedCounter"])
			{
				$counter["enabled"] = true;
				$counter["class"] = " main-grid-cell-counter-left-aligned";
				$counter["align"] = "left";
			}

			$content = [];
			if (
				isset($column["type"])
				&& $column["type"] === Grid\Column\Type::LABELS
				&& isset($row["columns"][$column["id"]])
				&& is_array($row["columns"][$column["id"]])
			)
			{
				foreach ($row["columns"][$column["id"]] as $labelKey => $label)
				{
					$labelClass = "";
					if (isset($label["color"]) && is_string($label["color"]))
					{
						$labelClass .= " " . $label["color"];
					}

					if (isset($label["size"]) && is_string($label["size"]))
					{
						$labelClass .= " " . $label["size"];
					}

					if (!isset($label["light"]) || (isset($label["light"]) && $label["light"] !== true))
					{
						$labelClass .= " ui-label-fill";
					}

					$labelEvents = [];
					if (isset($label["events"]) && is_array($label["events"]))
					{
						$labelEvents = $label["events"];

						if (isset($label["events"]["click"]))
						{
							$labelClass .= " ui-label-link";
						}
					}

					$removeButton = [
						"enabled" => false,
					];
					if (
						isset($label["removeButton"])
						&& is_array($label["removeButton"])
					)
					{
						$removeButton["enabled"] = true;
						if (
							isset($label["removeButton"]["type"])
							&& is_string($label["removeButton"]["type"])
						)
						{
							$removeButton["class"] = " " . $label["removeButton"]["type"];
							$removeButton["type"] = $label["removeButton"]["type"];
						}
						else
						{
							$removeButton["class"] = " " . Grid\Cell\Label\RemoveButtonType::INSIDE;
							$removeButton["type"] = Grid\Cell\Label\RemoveButtonType::INSIDE;
						}

						if (
							isset($label["removeButton"]["events"])
							&& is_array($label["removeButton"]["events"])
						)
						{
							$removeButton["attributes"] = static::stringifyAttrs([
								"data-events" => $label["removeButton"]["events"],
								"data-target" => ".ui-label",
							]);
						}
					}

					$content[$labelKey] = [
						"class" => Text\HtmlFilter::encode($labelClass),
						"attributes" => static::stringifyAttrs([
							"data-events" => $labelEvents,
						]),
						"removeButton" => $removeButton,
					];
				}
			}

			if (
				isset($column["type"])
				&& $column["type"] === Grid\Column\Type::TAGS
				&& isset($row["columns"][$column["id"]])
				&& is_array($row["columns"][$column["id"]])
			)
			{
				$addButtonEvents = [];
				$addButtonEnabled = false;
				if (
					isset($row["columns"][$column["id"]]["addButton"])
					&& is_array($row["columns"][$column["id"]]["addButton"])
					&& isset($row["columns"][$column["id"]]["addButton"]["events"])
					&& is_array($row["columns"][$column["id"]]["addButton"]["events"])
				)
				{
					$addButtonEvents = $row["columns"][$column["id"]]["addButton"]["events"];
					$addButtonEnabled = true;
				}

				$items = [];
				foreach ($row["columns"][$column["id"]]["items"] as $tagKey => $tag)
				{
					$item = [];
					$item["class"] = "";
					$item["active"] = false;
					if (isset($tag["active"]) && $tag["active"] === true)
					{
						$item["class"] = " main-grid-tag-active";
						$item["active"] = true;
					}

					$tagEvents = [];
					if (isset($tag["events"]) && is_array($tag["events"]))
					{
						$tagEvents = $tag["events"];
					}

					$item["attributes"] = static::stringifyAttrs([
						"data-events" => $tagEvents,
					]);

					$removeButtonEvents = [];
					if (
						isset($tag["removeButton"])
						&& is_array($tag["removeButton"])
						&& isset($tag["removeButton"]["events"])
						&& is_array($tag["removeButton"]["events"])
					)
					{
						$removeButtonEvents = $tag["removeButton"]["events"];
					}

					$item["removeButton"] = [
						"attributes" => static::stringifyAttrs([
							"data-events" => $removeButtonEvents,
						]),
					];

					$items[] = $item;
				}

				$content = [
					"addButton" => [
						"enabled" => $addButtonEnabled,
						"attributes" => static::stringifyAttrs([
							"data-events" => $addButtonEvents,
						]),
					],
					"items" => $items,
				];
			}

			$columns[$column["id"]] = [
				"cell" => [
					"class" => $cellClass,
					"attributes" => static::stringifyAttrs($cellAttributes),
				],
				"container" => [
					"attributes" => static::stringifyAttrs($containerAttributes),
				],
				"plusButton" => [
					"enabled" => $isPlusButtonEnabled,
				],
				"cellActions" => [
					"enabled" => $isCellActionsEnabled,
					"items" => $cellActions,
				],
				"counter" => $counter,
				"content" => $content,
			];
		}

		return $columns;
	}

	protected static function stringifyAttrs($attrs): string
	{
		$attrsString = "";
		if (is_array($attrs) && !empty($attrs))
		{
			$attrsString = " ";
			foreach ($attrs as $key => $value)
			{
				if (is_array($value))
				{
					$escapedValue = "(" . Text\HtmlFilter::encode(CUtil::PhpToJSObject($value)) . ")";
				}
				else
				{
					if (is_bool($value))
					{
						$escapedValue = $value ? "true" : "false";
					}
					else
					{
						$escapedValue = Text\HtmlFilter::encode($value);
					}
				}

				$escapedKey = Text\HtmlFilter::encode($key);
				$attrsString .= $escapedKey."=\"".$escapedValue."\"";
			}

			$attrsString .= " ";
		}

		return $attrsString;
	}

	protected function prepareColumnHeaderStyle($column): string
	{
		$style = "";
		if (isset($column["width"]))
		{
			$style .= "width: {$column["width"]}px; ";
		}

		if (
			isset($column["color"])
			&& is_string($column["color"])
			&& (
				strpos($column["color"], "#") === 0
				|| strpos($column["color"], "rgb") === 0
				|| strpos($column["color"], "hsl") === 0
			)
		)
		{
			$style .= "background-color: {$column["color"]};";
		}

		return $style;
	}

	protected function prepareColumnHeaderContainerStyle($column): string
	{
		$style = "";
		if (isset($column["width"]))
		{
			$style .= "width: {$column["width"]}px; ";
		}

		return $style;
	}

	protected function prepareColumnHeaderClass($column): string
	{
		$result = "";
		if (isset($column["class"]) && is_string($column["class"]))
		{
			$result .= " " . $column["class"];
		}

		if ($this->arParams["ALLOW_COLUMNS_SORT"])
		{
			$result .= " main-grid-draggable";
		}

		if ($this->arParams["ALLOW_STICKED_COLUMNS"] && $column["sticked"])
		{
			$result .= " main-grid-sticked-column";
		}

		if (
			isset($column["color"])
			&& is_string($column["color"])
			&& (
				strpos($column["color"], "#") === false
				&& strpos($column["color"], "rgb") === false
				&& strpos($column["color"], "hsl") === false
			)
		)
		{
			$result .= " " . $column["color"];
		}

		return $result;
	}

	/**
	 * Prepares sticked value
	 * @param array $column
	 * @return bool
	 */
	protected function prepareSticked($column)
	{
		return is_bool($column["sticked"]) ? $column["sticked"] : false;
	}

	protected function preparePreventDefault(array $column)
	{
		$result = true;

		if (isset($column["prevent_default"]))
		{
			$result = (bool) $column["prevent_default"];
		}

		return $result;
	}

	protected function prepareColumnWidth(array $column)
	{
		$width = null;

		if (is_numeric($column["width"]))
		{
			$width = $column["width"];
		}
		else
		{
			$columns = $this->prepareColumnsResizeMeta();
			if (is_numeric($columns["columns"][$column["id"]]))
			{
				$width = $columns["columns"][$column["id"]];
			}

		}

		return $width;
	}


	/**
	 * Prepares additional class for column header
	 * @param array $headerItem
	 *
	 * @return string
	 */
	protected function prepareHeaderClass(array $headerItem)
	{
		$classList = array();

		if ($headerItem["class"])
		{
			$classList[] = $headerItem["class"];
		}

		if ($align = $this->prepareAlign($headerItem))
		{
			$classList[] = "main-grid-cell-".$align;
		}

		if ($this->prepareSort($headerItem["sort"]) && $this->arParams["ALLOW_SORT"])
		{
			$classList[] = "main-grid-col-sortable";
		}
		else
		{
			$classList[] = "main-grid-col-no-sortable";
		}

		return join(" ", $classList);
	}

	protected function getColumnsAllWithSections(array $columns): array
	{
		$result = [];
		foreach($columns as $column)
		{
			if (!empty($column['section_id']))
			{
				$result[$column['section_id']][] = $column;
			}
			else
			{
				$result[$this->defaultHeaderSectionId][] = $column;
			}
		}

		return $result;
	}

	protected function prepareHeaderSections(): void
	{
		foreach($this->arParams['HEADERS_SECTIONS'] as $section)
		{
			$this->arResult['HEADERS_SECTIONS'][$section['id']] = $section;
			if (!empty($section['default']))
			{
				$this->defaultHeaderSectionId = $section['id'];
			}
		}
	}

	/**
	 * Prepares each header items
	 * @return array prepares header
	 */
	protected function prepareColumnsAll()
	{
		if (empty($this->arResult["COLUMNS_ALL"]))
		{
			$this->arResult["COLUMNS_ALL"] = array();

			foreach ($this->arParams["COLUMNS"] as $key => $item)
			{
				$this->arResult["COLUMNS_ALL"][$item["id"]] = $this->prepareColumn($item);
			}

			$allColumns = array_keys($this->arResult["COLUMNS_ALL"]);
			$allColumns = array_combine($allColumns, $allColumns);
			$showedColumns = $this->getShowedColumnsList();
			$resultColumns = array();
			$counter = 0;

			foreach ($allColumns as $allKey => $allColumn)
			{
				$key = $allKey;

				if (in_array($allKey, $showedColumns))
				{
					$key = $showedColumns[$counter];
					$counter++;
				}

				$resultColumns[$key] = $this->arResult["COLUMNS_ALL"][$key];
			}

			$this->arResult["COLUMNS_ALL"] = $resultColumns;
		}

		return $this->arResult["COLUMNS_ALL"];
	}


	/**
	 * Prepares visible headers
	 * @method prepareHeaders
	 * @return array
	 */
	protected function prepareColumns()
	{
		if (empty($this->arResult["COLUMNS"]))
		{
			$this->arResult["COLUMNS"] = array();

			$index = 0;
			foreach ($this->prepareColumnsAll() as $key => $item)
			{
				if ($item["is_shown"])
				{
					$this->arResult["COLUMNS"][$key] = $item;
					$this->arResult["COLUMNS"][$key]["sort_index"] = $index++;
				}
			}
		}

		return $this->arResult["COLUMNS"];
	}


	protected function prepareDefaultOptions()
	{
		$options = $this->getCurrentOptions();
		$gridOptions = $this->getGridOptions();
		$isNeedSave = false;

		if (!isset($options["columns_sizes"]) ||
			empty($options["columns_sizes"]) ||
			!is_array($options["columns_sizes"]))
		{
			$columns = $this->prepareColumns();
			$columnsSizes = array();
			$isNeedSave = true;

			foreach ($columns as $key => $item)
			{
				if (is_numeric($item["width"]))
				{
					$columnsSizes[$key] = $item["width"];
				}
			}

			$gridOptions->setColumnsSizes(null, $columnsSizes);
		}

		if ($gridOptions->getStickedColumns() === null)
		{
			$stickedColumns = [];

			foreach ($this->arResult["COLUMNS_ALL"] as $key => $column)
			{
				if ($column["sticked"] && $this->isShownColumn($column))
				{
					$stickedColumns[] = $key;
				}
			}

			$gridOptions->setStickedColumns($stickedColumns);
			$isNeedSave = true;
		}

		if ($isNeedSave)
		{
			$gridOptions->Save();
			$this->arResult["OPTIONS"] = $this->getOptions();
		}
	}

	protected function getJsFolder()
	{
		return $this->jsFolder;
	}

	protected function getBlocksFolder()
	{
		return $this->blocksFolder;
	}

	protected function getCssFolder()
	{
		return $this->cssFolder;
	}

	protected function includeScripts($folder)
	{
		$tmpl = $this->getTemplate();
		$absPath = $_SERVER["DOCUMENT_ROOT"].$tmpl->GetFolder().$folder;
		$relPath = $tmpl->GetFolder().$folder;

		if (is_dir($absPath))
		{
			$dir = opendir($absPath);

			if($dir)
			{
				while(($file = readdir($dir)) !== false)
				{
					$ext = getFileExtension($file);

					if ($ext === 'js' && !(mb_strpos($file, 'map.js') !== false || mb_strpos($file, 'min.js') !== false))
					{
						$tmpl->addExternalJs($relPath.$file);
					}
				}

				closedir($dir);
			}
		}
	}

	protected function includeComponentBlocks()
	{
		$blocksFolder = $this->getBlocksFolder();
		$this->includeScripts($blocksFolder);
	}

	protected function includeComponentScripts()
	{
		$scriptsFolder = $this->getJsFolder();
		$this->includeScripts($scriptsFolder);
	}

	protected static function sortMultilevelRows($rows, &$resultRows, $parent = 0, $depth = 0)
	{
		foreach ($rows as $key => $row)
		{
			if ($row["parent_id"] === $parent)
			{
				$row["depth"] = $depth;
				$resultRows[] = $row;
				unset($rows[$key]);
				self::sortMultilevelRows($rows, $resultRows, $row["id"], $depth + 1);
			}
		}
		return $resultRows;
	}

	protected static function normalizeParentIds(&$rows)
	{
		$ids = array();

		foreach ($rows as $key => $row)
		{
			$ids[] = $row["id"];
		}

		foreach ($rows as $key => $row)
		{
			if (!in_array($row["parent_id"], $ids))
			{
				$rows[$key]["parent_id"] = 0;
			}
		}
	}

	protected static function restoreExpandedRowsState(&$rows, $expandedIds)
	{
		if (is_array($expandedIds) && !empty($expandedIds))
		{
			foreach ($rows as $key => $row)
			{
				$rows[$key]["expand"] = !isset($row["custom"]) && in_array($row["id"], $expandedIds);
			}
		}
	}


	protected static function restoreCollapsedGroupsState(&$rows, $collapsedIds)
	{
		if (is_array($collapsedIds) && !empty($collapsedIds))
		{
			foreach ($rows as $key => $row)
			{
				if (isset($row["custom"]))
				{
					$rows[$key]["expand"] = !in_array($row["id"], $collapsedIds);
				}
			}
		}
		else
		{
			foreach ($rows as $key => $row)
			{
				if (isset($row["custom"]))
				{
					$rows[$key]["expand"] = true;
				}
			}
		}
	}

	protected function prepareMultilevelRows()
	{
		$result = array();
		$parent = 0;
		$depth = 0;
		$request = $this->request;

		if ($request["action"] === Grid\Actions::GRID_GET_CHILD_ROWS && $request["parent_id"] !== null)
		{
			$parent = $request["parent_id"];
			$depth = $request["depth"];
		}
		else
		{
			self::normalizeParentIds($this->arParams["ROWS"]);
		}

		self::sortMultilevelRows($this->arParams["ROWS"], $result, $parent, $depth);

		$expandedRows = $this->getGridOptions()->getExpandedRows();
		$collapsedGroups = $this->getGridOptions()->getCollapsedGroups();
		self::restoreExpandedRowsState($result, $expandedRows);
		self::restoreCollapsedGroupsState($result, $collapsedGroups);

		$this->arParams["ROWS"] = $result;
	}

	protected function prepareTemplateData()
	{
		foreach ($this->arResult["COLUMNS"] as $columnId => $column)
		{
			$column["layout"] = $this->prepareColumnHeaderLayout($column);
			$this->arResult["COLUMNS"][$columnId] = $column;
		}

		$options = [
			"lastCollapsedGroupId" => null,
			"hasCellActions" => [],
		];

		foreach ($this->arParams["ROWS"] as $rowId => $row)
		{
			if (isset($row["cellActions"]) && is_array($row["cellActions"]))
			{
				foreach ($row["cellActions"] as $actions => $columnCellId)
				{
					if (is_array($actions) && !empty($actions))
					{
						$options["hasCellActions"][$columnCellId] = true;
					}
				}
			}

			if (isset($row["counters"]) && is_array($row["counters"]))
			{
				foreach ($row["counters"] as $columnId => $counter)
				{
					if (
						is_array($counter)
						&& isset($counter["type"])
						&& $counter["type"] === Grid\Counter\Type::LEFT_ALIGNED
					)
					{
						foreach ($this->arResult["COLUMNS"] as $colKey => $column)
						{
							$this->arResult["COLUMNS"][$colKey]["layout"]["hasLeftAlignedCounter"] = false;
							if ($column["id"] === $columnId)
							{
								$this->arResult["COLUMNS"][$colKey]["layout"]["hasLeftAlignedCounter"] = true;
							}
						}
					}
				}
			}
		}

		foreach ($this->arParams["ROWS"] as $rowId => $row)
		{
			if (!empty($row["custom"]))
			{
				$options["lastCollapsedGroupId"] = $row["expand"] === false ? $row["group_id"] : null;
			}

			$row["layout"] = $this->prepareRowLayout($row, $options);
			$this->arParams["ROWS"][$rowId] = $row;
		}
	}

	public function executeComponent()
	{
		if ($this->checkRequiredParams())
		{
			if (!is_array($this->arParams['ROWS']))
			{
				$this->arParams['ROWS'] = [];
			}

			$this->prepareTemplateRow();
			$this->prepareParams();
			$this->prepareResult();
			$this->prepareDefaultOptions();
			$this->applyUserSettings();

			if ($this->arParams["ENABLE_COLLAPSIBLE_ROWS"])
			{
				$this->prepareMultilevelRows();
			}

			$this->prepareTemplateData();

			$templateName = $this->getTemplateName();
			if ( (empty($templateName) || $templateName === ".default") && $this->arParams['TILE_GRID_MODE'])
			{
				$this->setTemplateName('tilegrid');
			}

			$this->includeComponentTemplate();

			$templateName = $this->getTemplateName();
			if ($templateName !== '.default' && $templateName !== '')
			{
				$this->includeComponentScripts();
				$this->includeComponentBlocks();
			}
		}
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit