28 $listGrid = Option::get(self::$moduleId,
"listGridToConvert",
"");
31 $listGrid = unserialize($listGrid);
33 $listGrid = is_array($listGrid) ? $listGrid : [];
35 if (!array_key_exists($tableId, $listGrid))
37 $listGrid[$tableId] = [
41 Option::set(self::$moduleId,
"listGridToConvert", serialize($listGrid));
47 $listGrid = Option::get(self::$moduleId,
"listGridToConvert",
"");
48 if ($listGrid !==
"" )
50 $listGrid = unserialize($listGrid);
52 $listGrid = is_array($listGrid) ? $listGrid : [];
55 Option::delete(self::$moduleId, [
"name" =>
"listGridToConvert"]);
56 $GLOBALS[
"CACHE_MANAGER"]->cleanDir(
"user_option");
61 $sqlHelper = $connection->getSqlHelper();
63 foreach ($listGrid as $tableId => $table)
65 $queryObject = $connection->query(
"SELECT * FROM `b_user_option` WHERE `CATEGORY` = 'list' AND `NAME` = '".
66 $sqlHelper->forSql($table[
"tableId"]).
"' ORDER BY ID ASC LIMIT ".$this->limit.
" OFFSET ".$table[
"offset"]);
67 $selectedRowsCount = $queryObject->getSelectedRowsCount();
68 while ($optionOldGrid = $queryObject->fetch())
70 $oldGridData = (!empty($optionOldGrid[
"VALUE"]) ? unserialize($optionOldGrid[
"VALUE"]) : []);
77 $queryResultObject = $connection->query(
78 "SELECT ID FROM `b_user_option` WHERE `CATEGORY` = 'main.interface.grid' AND `NAME` = '".
79 $sqlHelper->forSql($table[
"tableId"]).
"' AND `USER_ID` = '".$optionOldGrid[
"USER_ID"].
"'");
80 if (!$queryResultObject->fetch())
82 if (!array_diff_key(array_flip([
"page_size",
"by",
"order",
"columns"]), $oldGridData))
84 $gridOptions = new \CGridOptions($tableId);
85 $gridOptions->setSorting($oldGridData[
"by"], $oldGridData[
"order"]);
86 $gridOptions->setColumns($oldGridData[
"columns"]);
87 $options = $gridOptions->getOptions();
88 $options[
"views"][
"default"][
"page_size"] = intval($oldGridData[
"page_size"]);
89 \CUserOptions::setOption(
90 "main.interface.grid", $tableId, $options,
false, $optionOldGrid[
"USER_ID"]);
95 if ($selectedRowsCount < $this->limit)
97 unset($listGrid[$tableId]);
101 $listGrid[$tableId][
"offset"] = $listGrid[$tableId][
"offset"] + $selectedRowsCount;
105 $GLOBALS[
"CACHE_MANAGER"]->cleanDir(
"user_option");
107 if (!empty($listGrid))
109 Option::set(self::$moduleId,
"listGridToConvert", serialize($listGrid));
114 Option::delete(self::$moduleId, [
"name" =>
"listGridToConvert"]);