Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
history.php
1<?php
2
4
7
8class History
9{
10 public static function getForLanding(int $lid): PublicActionResult
11 {
12 $result = new PublicActionResult();
13 $history = new Landing\History($lid, Landing\History::ENTITY_TYPE_LANDING);
14 $result->setResult([
15 'stack' => $history->getJsStack(),
16 'stackCount' => $history->getStackCount(),
17 'step' => $history->getStep(),
18 ]);
19
20 return $result;
21 }
22
23 public static function getForDesignerBlock(int $blockId): PublicActionResult
24 {
25 $result = new PublicActionResult();
26 $history = new Landing\History($blockId, Landing\History::ENTITY_TYPE_DESIGNER_BLOCK);
27
28 $result->setResult([
29 'stack' => $history->getJsStack(),
30 'stackCount' => $history->getStackCount(),
31 'step' => $history->getStep(),
32 ]);
33
34 return $result;
35 }
36
37 public static function undoLanding(int $lid): PublicActionResult
38 {
39 return self::undoForEntity(Landing\History::ENTITY_TYPE_LANDING, $lid);
40 }
41
42 public static function redoLanding(int $lid): PublicActionResult
43 {
44 return self::redoForEntity(Landing\History::ENTITY_TYPE_LANDING, $lid);
45 }
46
47 public static function undoDesignerBlock(int $blockId): PublicActionResult
48 {
49 return self::undoForEntity(Landing\History::ENTITY_TYPE_DESIGNER_BLOCK, $blockId);
50 }
51
52 public static function redoDesignerBlock(int $blockId): PublicActionResult
53 {
54 return self::redoForEntity(Landing\History::ENTITY_TYPE_DESIGNER_BLOCK, $blockId);
55 }
56
57 public static function pushDesignerBlock(int $blockId, string $action, array $data): PublicActionResult
58 {
59 return self::pushForEntity(Landing\History::ENTITY_TYPE_DESIGNER_BLOCK, $blockId, $action, $data);
60 }
61
62 public static function clearDesignerBlock(int $blockId): PublicActionResult
63 {
64 return self::clearForEntity(Landing\History::ENTITY_TYPE_DESIGNER_BLOCK, $blockId);
65 }
66
67 protected static function undoForEntity(string $entityType, int $entityId): PublicActionResult
68 {
69 $result = new PublicActionResult();
70 $error = new \Bitrix\Landing\Error;
71
72 Landing\Landing::setEditMode(true);
73
74 if (in_array($entityType, Landing\History::AVAILABLE_TYPES))
75 {
76 $history = new Landing\History($entityId, $entityType);
77 $command = $history->getJsCommand();
78 if ($history->undo())
79 {
80 $result->setResult($command);
81 }
82 else
83 {
84 $error->addError(
85 'HISTORY_UNDO_ERROR',
86 "History operation Undo fail for entity {$entityType}_{$entityId}"
87 );
88 $result->setError($error);
89 }
90 }
91 else
92 {
93 $error->addError(
94 'HISTORY_WRONG_TYPE',
95 'Wrong history entity type'
96 );
97 $result->setError($error);
98 }
99
100 return $result;
101 }
102
103 protected static function redoForEntity(string $entityType, int $entityId): PublicActionResult
104 {
105 $result = new PublicActionResult();
106 $error = new \Bitrix\Landing\Error;
107
108 Landing\Landing::setEditMode(true);
109
110 if (in_array($entityType, Landing\History::AVAILABLE_TYPES))
111 {
112 $history = new Landing\History($entityId, $entityType);
113 $command = $history->getJsCommand(false);
114 if ($history->redo())
115 {
116 $result->setResult($command);
117 }
118 else
119 {
120 $error->addError(
121 'HISTORY_REDO_ERROR',
122 "History operation Redo fail for entity {$entityType}_{$entityId}"
123 );
124 $result->setError($error);
125 }
126 }
127 else
128 {
129 $error->addError(
130 'HISTORY_WRONG_TYPE',
131 'Wrong history entity type'
132 );
133 $result->setError($error);
134 }
135
136 return $result;
137 }
138
139 protected static function pushForEntity(
140 string $entityType,
141 int $entityId,
142 string $action,
143 array $data
145 {
146 $result = new PublicActionResult();
147 $error = new \Bitrix\Landing\Error;
148
149 Landing\Landing::setEditMode(true);
150
151 if (in_array($entityType, Landing\History::AVAILABLE_TYPES))
152 {
153 $history = new Landing\History($entityId, $entityType);
154 if ($history->push($action, $data))
155 {
156 $result->setResult(true);
157 }
158 else
159 {
160 $error->addError(
161 'HISTORY_PUSH_ERROR',
162 "History operation Push fail for entity {$entityType}_{$entityId}"
163 );
164 $result->setError($error);
165 }
166 }
167 else
168 {
169 $error->addError(
170 'HISTORY_WRONG_TYPE',
171 'Wrong history entity type'
172 );
173 $result->setError($error);
174 }
175
176 return $result;
177 }
178
179 protected static function clearForEntity(string $entityType, int $entityId): PublicActionResult
180 {
181 $result = new PublicActionResult();
182 $error = new \Bitrix\Landing\Error;
183
184 Landing\Landing::setEditMode(true);
185
186 if (in_array($entityType, Landing\History::AVAILABLE_TYPES))
187 {
188 $history = new Landing\History($entityId, $entityType);
189 if ($history->clear())
190 {
191 $result->setResult(true);
192 }
193 else
194 {
195 $error->addError(
196 'HISTORY_CLEAR_ERROR',
197 "History operation Clear fail for entity {$entityType}_{$entityId}"
198 );
199 $result->setError($error);
200 }
201 }
202 else
203 {
204 $error->addError(
205 'HISTORY_WRONG_TYPE',
206 'Wrong history entity type'
207 );
208 $result->setError($error);
209 }
210
211 return $result;
212 }
213}
static redoForEntity(string $entityType, int $entityId)
Definition history.php:103
static pushForEntity(string $entityType, int $entityId, string $action, array $data)
Definition history.php:139
static undoDesignerBlock(int $blockId)
Definition history.php:47
static redoDesignerBlock(int $blockId)
Definition history.php:52
static getForDesignerBlock(int $blockId)
Definition history.php:23
static clearDesignerBlock(int $blockId)
Definition history.php:62
static clearForEntity(string $entityType, int $entityId)
Definition history.php:179
static pushDesignerBlock(int $blockId, string $action, array $data)
Definition history.php:57
static undoForEntity(string $entityType, int $entityId)
Definition history.php:67