Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
gridoption.php
1<?
3
7
13class GridOption extends Stepper
14{
15 protected static $moduleId = "catalog";
16 protected $deleteFile = true;
17
18 protected $limit = 100;
19
26 public static function setGridToConvert($tableId)
27 {
28 $listGrid = Option::get(self::$moduleId, "listGridToConvert", "");
29 if ($listGrid !== "")
30 {
31 $listGrid = unserialize($listGrid);
32 }
33 $listGrid = is_array($listGrid) ? $listGrid : [];
34
35 if (!array_key_exists($tableId, $listGrid))
36 {
37 $listGrid[$tableId] = [
38 "offset" => 0,
39 "tableId"=> $tableId,
40 ];
41 Option::set(self::$moduleId, "listGridToConvert", serialize($listGrid));
42 }
43 }
44
45 public function execute(array &$option)
46 {
47 $listGrid = Option::get(self::$moduleId, "listGridToConvert", "");
48 if ($listGrid !== "" )
49 {
50 $listGrid = unserialize($listGrid);
51 }
52 $listGrid = is_array($listGrid) ? $listGrid : [];
53 if (empty($listGrid))
54 {
55 Option::delete(self::$moduleId, ["name" => "listGridToConvert"]);
56 $GLOBALS["CACHE_MANAGER"]->cleanDir("user_option");
57 return false;
58 }
59
60 $connection = Application::getInstance()->getConnection();
61 $sqlHelper = $connection->getSqlHelper();
62
63 foreach ($listGrid as $tableId => $table)
64 {
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())
69 {
70 $oldGridData = (!empty($optionOldGrid["VALUE"]) ? unserialize($optionOldGrid["VALUE"]) : []);
71
72 if (!$oldGridData)
73 {
74 continue;
75 }
76
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())
81 {
82 if (!array_diff_key(array_flip(["page_size", "by", "order", "columns"]), $oldGridData))
83 {
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"]);
91 }
92 }
93 }
94
95 if ($selectedRowsCount < $this->limit)
96 {
97 unset($listGrid[$tableId]);
98 }
99 else
100 {
101 $listGrid[$tableId]["offset"] = $listGrid[$tableId]["offset"] + $selectedRowsCount;
102 }
103 }
104
105 $GLOBALS["CACHE_MANAGER"]->cleanDir("user_option");
106
107 if (!empty($listGrid))
108 {
109 Option::set(self::$moduleId, "listGridToConvert", serialize($listGrid));
110 return true;
111 }
112 else
113 {
114 Option::delete(self::$moduleId, ["name" => "listGridToConvert"]);
115 return false;
116 }
117 }
118}
static setGridToConvert($tableId)
$GLOBALS['____1444769544']
Definition license.php:1