Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
processparams.php
1<?php
3
5
12{
14 protected array $fieldToStoreInProcess = [];
15
21 public function getProgressParameterOptionName(): string
22 {
23 $settingId = 'translate';
24 if ($this instanceof Translate\Controller\Action)
25 {
26 $controller = $this->getController();
27 $settingId = $controller::SETTING_ID;
28 }
29 elseif ($this instanceof Translate\Controller\Controller)
30 {
31 $settingId = static::SETTING_ID;
32 }
33
34 $classId = \str_replace(['_', '\\'], '', static::class);
35
36 $id = "{$settingId}/{$classId}";
37
38 if (!empty($this->tabId))
39 {
40 $id .= '/'. $this->tabId;
41 }
42
43 return $id;
44 }
45
53 public function keepField($fieldName): self
54 {
55 if (\is_array($fieldName))
56 {
57 $this->fieldToStoreInProcess = \array_merge($this->fieldToStoreInProcess, $fieldName);
58 }
59 else
60 {
61 $this->fieldToStoreInProcess[] = $fieldName;
62 }
63
64 return $this;
65 }
66
72 public function restoreProgressParameters(): self
73 {
74 if (\count($this->fieldToStoreInProcess) > 0)
75 {
76 $progressData = $this->getProgressParameters();
77 if (\count($progressData) > 0)
78 {
79 foreach ($this->fieldToStoreInProcess as $fieldName)
80 {
81 if (isset($progressData[$fieldName]))
82 {
83 $this->{$fieldName} = $progressData[$fieldName];
84 }
85 }
86 }
87 }
88
89 return $this;
90 }
91
97 public function saveProgressParameters(): self
98 {
99 // store state
100 $progressData = [];
101 foreach ($this->fieldToStoreInProcess as $fieldName)
102 {
103 $progressData[$fieldName] = $this->{$fieldName};
104 }
105
106 $optName = \explode('/', $this->getProgressParameterOptionName());
107 $storage =& $_SESSION;
108 for ($d = 0, $depth = \count($optName); $d < $depth; $d++)
109 {
110 if (!isset($storage[$optName[$d]]))
111 {
112 $storage[$optName[$d]] = [];
113 }
114 $storage =& $storage[$optName[$d]];
115 }
116
117 $storage = $progressData;
118
119 return $this;
120 }
121
127 public function getProgressParameters(): array
128 {
129 $optName = \explode('/', $this->getProgressParameterOptionName());
130 $storage =& $_SESSION;
131 for ($d = 0, $depth = \count($optName); $d < $depth; $d++)
132 {
133 if (!isset($storage[$optName[$d]]))
134 {
135 return [];
136 }
137 $storage =& $storage[$optName[$d]];
138 }
139
140 return $storage;
141 }
142
148 public function clearProgressParameters(): self
149 {
150 $optName = \explode('/', $this->getProgressParameterOptionName());
151 $storage =& $_SESSION;
152 for ($d = 0, $depth = \count($optName); $d < $depth; $d++)
153 {
154 if (!isset($storage[$optName[$d]]))
155 {
156 return $this;
157 }
158 $storage =& $storage[$optName[$d]];
159 }
160
161 unset($storage);
162
163 return $this;
164 }
165}