1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
manager.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\Rooms\Categories;
4
5use Bitrix\Calendar\Integration\Bitrix24Manager;
6use Bitrix\Calendar\Integration\Pull\PushCommand;
7use Bitrix\Calendar\Internals\LocationTable;
8use Bitrix\Calendar\Internals\RoomCategoryTable;
9use Bitrix\Calendar\UserSettings;
10use Bitrix\Main\Error;
11use Bitrix\Main\Localization\Loc;
12use Bitrix\Main\Text\Emoji;
13
18{
20 private Category $category;
22 private $error;
23
24 protected function __construct()
25 {
26 }
27
28 public static function createInstance(Category $category): Manager
29 {
30 return (new self())->setCategory($category);
31 }
32
33 public function setCategory(Category $category): Manager
34 {
35 $this->category = $category;
36
37 return $this;
38 }
39
40 private function addError(Error $error): Manager
41 {
42 $this->error = $error;
43
44 return $this;
45 }
46
47 public function getCategory(): Category
48 {
49 return $this->category;
50 }
51
52 public function getError(): ?Error
53 {
54 return $this->error;
55 }
56
62 public function createCategory(): Manager
63 {
64 if($this->getError())
65 {
66 return $this;
67 }
68
69 $this->category->create();
70
71 if($this->category->getError())
72 {
73 $this->addError($this->category->getError());
74 }
75
76 $createdCategoryId = $this->category->getId();
77 $rooms = $this->category->getRooms();
78 if(!empty($rooms) && $createdCategoryId)
79 {
80 foreach ($rooms as &$room)
81 {
82 $room = (int)$room;
83 }
84 global $DB;
85 $tableName = LocationTable::getTableName();
86 $roomsIds = implode(',', $rooms);
87
88 $sqlStr = "
89 UPDATE $tableName
90 SET CATEGORY_ID = $createdCategoryId
91 WHERE SECTION_ID IN ($roomsIds)
92 ";
93 $result = $DB->Query($sqlStr, true);
94 if(!$result)
95 {
96 $this->category->delete();
97 $this->addError(new Error('An error occurred while saving the category'));
98 }
99 }
100
101 return $this;
102 }
103
109 public function updateCategory(): Manager
110 {
111 if ($this->getError())
112 {
113 return $this;
114 }
115
116 $this->category->update();
117
118 if ($this->category->getError())
119 {
120 $this->addError($this->category->getError());
121 }
122
123 global $DB;
124 $tableName = LocationTable::getTableName();
125 $categoryId = $this->category->getId();
126 $rooms = $this->category->getRooms();
127
128 $result = true;
129
130 if(isset($rooms['toAddCategory']))
131 {
132 foreach ($rooms['toAddCategory'] as &$toAddId)
133 {
134 $toAddId = (int)$toAddId;
135 }
136 $toAddIds = implode(',', $rooms['toAddCategory']);
137 $sqlStr = "
138 UPDATE $tableName
139 SET CATEGORY_ID = $categoryId
140 WHERE SECTION_ID IN ($toAddIds)
141 ";
142 $result = $DB->Query($sqlStr, true);
143 }
144
145 if($result && isset($rooms['toRemoveCategory']))
146 {
147 foreach ($rooms['toRemoveCategory'] as &$toRemoveId)
148 {
149 $toRemoveId = (int)$toRemoveId;
150 }
151 $toRemoveIds = implode(',', $rooms['toRemoveCategory']);
152 $sqlStr = "
153 UPDATE $tableName
154 SET CATEGORY_ID = null
155 WHERE SECTION_ID IN ($toRemoveIds)
156 ";
157 $result = $DB->Query($sqlStr, true);
158 }
159
160 if(!$result)
161 {
162 $this->addError(new Error('An error occurred while saving the category'));
163 }
164
165 return $this;
166 }
167
173 public function deleteCategory(): Manager
174 {
175 if ($this->getError())
176 {
177 return $this;
178 }
179
180 $this->category->delete();
181
182 if ($this->category->getError())
183 {
184 $this->addError($this->category->getError());
185 }
186
187 global $DB;
188 $tableName = LocationTable::getTableName();
189 $categoryId = $this->category->getId();
190
191 $DB->Query("
192 UPDATE $tableName
193 SET CATEGORY_ID = null
194 WHERE CATEGORY_ID = $categoryId
195 ");
196
197 return $this;
198 }
199
206 public static function getCategoryList(): array
207 {
208 $result = [];
209
210 $categories = RoomCategoryTable::query()
211 ->setSelect(['ID', 'NAME'])
212 ->setOrder(['ID' => 'ASC'])
213 ->setCacheTtl(86400)
214 ->exec()
215 ;
216
217 while ($category = $categories->fetch())
218 {
219 $category['NAME'] = Emoji::decode($category['NAME']);
220
221 $result[] = $category;
222 }
223
224 return $result;
225 }
226
233 public static function checkCategoryName(?string $name): ?string
234 {
235 $name = trim($name);
236
237 if (empty($name))
238 {
239 return '';
240 }
241
242 return $name;
243 }
244
246 {
247 if ($this->getError())
248 {
249 return $this;
250 }
251
253 $event,
254 \CCalendar::GetCurUserId(),
255 [
256 'ID' => $this->category->getId()
257 ],
258 );
259
260 return $this;
261 }
262
263 public function clearCache(): Manager
264 {
266 RoomCategoryTable::cleanCache();
267
268 return $this;
269 }
270}
setCategory(Category $category)
Определения manager.php:33
addPullEvent(PushCommand $event)
Определения manager.php:245
static checkCategoryName(?string $name)
Определения manager.php:233
static createInstance(Category $category)
Определения manager.php:28
static createInstance()
Определения manager.php:49
static addPullEvent(PushCommand $command, int $userId, array $params=[])
Определения util.php:385
Определения error.php:15
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
global $DB
Определения cron_frame.php:29
$name
Определения menu_edit.php:35
$event
Определения prolog_after.php:141
$error
Определения subscription_card_product.php:20