1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
CollabService.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
5namespace Bitrix\Socialnetwork\Collab\Control;
6
7use Bitrix\Main\Error;
8use Bitrix\Main\Validation\ValidationError;
9use Bitrix\Socialnetwork\Collab\Collab;
10use Bitrix\Socialnetwork\Collab\Control\Command\CollabAddCommand;
11use Bitrix\Socialnetwork\Collab\Control\Command\CollabDeleteCommand;
12use Bitrix\Socialnetwork\Collab\Control\Command\CollabUpdateCommand;
13use Bitrix\Socialnetwork\Collab\Control\Event\BeforeCollabUpdateEvent;
14use Bitrix\Socialnetwork\Collab\Control\Event\CollabAddEvent;
15use Bitrix\Socialnetwork\Collab\Control\Event\CollabDeleteEvent;
16use Bitrix\Socialnetwork\Collab\Control\Event\CollabUpdateEvent;
17use Bitrix\Socialnetwork\Collab\Control\Handler\Add\AddInviteHandler;
18use Bitrix\Socialnetwork\Collab\Control\Handler\Add\AddLogEntryHandler;
19use Bitrix\Socialnetwork\Collab\Control\Handler\Add\AddMemberHandler;
20use Bitrix\Socialnetwork\Collab\Control\Handler\Add\AddMessageHandler;
21use Bitrix\Socialnetwork\Collab\Control\Handler\Add\AddModeratorsHandler;
22use Bitrix\Socialnetwork\Collab\Control\Handler\Add\AddOptionsHandler;
23use Bitrix\Socialnetwork\Collab\Control\Handler\Add\AddThemeHandler;
24use Bitrix\Socialnetwork\Collab\Control\Handler\Delete\DeleteChatHandler;
25use Bitrix\Socialnetwork\Collab\Control\Handler\Delete\DeleteOptionsHandler;
26use Bitrix\Socialnetwork\Collab\Control\Handler\Update\UpdateInviteHandler;
27use Bitrix\Socialnetwork\Collab\Control\Handler\Update\UpdateLogEntryHandler;
28use Bitrix\Socialnetwork\Collab\Control\Handler\Update\UpdateMemberHandler;
29use Bitrix\Socialnetwork\Collab\Control\Handler\Update\UpdateModeratorsHandler;
30use Bitrix\Socialnetwork\Collab\Control\Handler\Update\UpdateOptionsHandler;
31use Bitrix\Socialnetwork\Collab\Control\Handler\Update\UpdateOwnerHandler;
32use Bitrix\Socialnetwork\Collab\Integration\IM\ActionMessageBuffer;
33use Bitrix\Socialnetwork\Collab\Provider\CollabProvider;
34use Bitrix\Socialnetwork\Collab\Registry\CollabRegistry;
35use Bitrix\Socialnetwork\Control\AbstractGroupService;
36use Bitrix\Socialnetwork\Control\Command\AbstractCommand;
37use Bitrix\Socialnetwork\Control\Command\AddCommand;
38use Bitrix\Socialnetwork\Control\Command\DeleteCommand;
39use Bitrix\Socialnetwork\Control\Command\UpdateCommand;
40use Bitrix\Socialnetwork\Control\GroupResult;
41use Bitrix\Socialnetwork\Control\Handler\Add\AddFeatureHandler;
42use Bitrix\Socialnetwork\Control\Handler\Update\UpdatePermissionsHandler;
43use Bitrix\Socialnetwork\Item\Workgroup;
44use Bitrix\SocialNetwork\Validation\Validator\NotContainsUrlValidator;
45
47{
48 protected function getAddHandlers(): array
49 {
50 return [
52 new AddThemeHandler(),
54 new AddInviteHandler(),
55 new AddMemberHandler(),
59 ];
60 }
61
62 protected function getUpdateHandlers(): array
63 {
64 return [
72 ];
73 }
74
75 protected function getDeleteHandlers(): array
76 {
77 return [
80 ];
81 }
82
83 protected function init(): void
84 {
85 parent::init();
86 $this->registry = CollabRegistry::getInstance();
87 }
88
89 protected function checkAddCommand(AbstractCommand $command): GroupResult
90 {
91 $result = new GroupResult();
92 if (!$command instanceof CollabAddCommand)
93 {
94 $result->addError(new Error('Wrong command type'));
95 }
96
97 return $result;
98 }
99
100 protected function checkUpdateCommand(UpdateCommand $command): GroupResult
101 {
102 $result = new GroupResult();
103 if (!$command instanceof CollabUpdateCommand)
104 {
105 $result->addError(new Error('Wrong command type'));
106 }
107
108 return $result;
109 }
110
111 protected function checkDeleteCommand(DeleteCommand $command): GroupResult
112 {
113 $result = new GroupResult();
114 if (!$command instanceof CollabDeleteCommand)
115 {
116 $result->addError(new Error('Wrong command type'));
117 }
118
119 return $result;
120 }
121
123 {
124 $this->remapValidationErrors($result);
125
126 return $this->setCollabToResult($result);
127 }
128
130 {
131 $this->remapValidationErrors($result);
132
133 return $this->setCollabToResult($result);
134 }
135
136 protected function sendAddEvent(AddCommand $command, Workgroup $entity): void
137 {
138 if (!$command instanceof CollabAddCommand || !$entity instanceof Collab)
139 {
140 return;
141 }
142
143 ActionMessageBuffer::getInstance()->flush();
144
145 $event = new CollabAddEvent($command, $entity);
146
147 $event->send();
148 }
149
150 protected function sendBeforeUpdateEvent(UpdateCommand $command, Workgroup $entity): void
151 {
152 if (!$command instanceof CollabUpdateCommand || !$entity instanceof Collab)
153 {
154 return;
155 }
156
157 $event = new BeforeCollabUpdateEvent($command, $entity);
158
159 $event->send();
160 }
161
162 protected function sendUpdateEvent(UpdateCommand $command, Workgroup $entityBefore, Workgroup $entityAfter): void
163 {
164 if (!$command instanceof CollabUpdateCommand || !$entityBefore instanceof Collab || !$entityAfter instanceof Collab)
165 {
166 return;
167 }
168
169 ActionMessageBuffer::getInstance()->flush();
170
171 $event = new CollabUpdateEvent($command, $entityBefore, $entityAfter);
172
173 $event->send();
174 }
175
176 protected function sendDeleteEvent(DeleteCommand $command, Workgroup $entityBefore): void
177 {
178 if (!$command instanceof CollabDeleteCommand || !$entityBefore instanceof Collab)
179 {
180 return;
181 }
182
183 $event = new CollabDeleteEvent($command, $entityBefore);
184
185 $event->send();
186 }
187
188 private function setCollabToResult(GroupResult $result): CollabResult
189 {
190 $collabResult = (new CollabResult())->merge($result);
191 if (!$collabResult->isSuccess())
192 {
193 return $collabResult;
194 }
195
196 $provider = CollabProvider::getInstance();
197
198 $collab = $provider->getCollab((int)$collabResult->getCollab()?->getId());
199 if ($collab === null)
200 {
201 $collabResult->addError(new Error('Collab not found'));
202
203 return $collabResult;
204 }
205
206 $collabResult->setGroup($collab);
207
208 return $collabResult;
209 }
210
211 private function remapValidationErrors(GroupResult $result): void
212 {
213 if (!$result->isSuccess())
214 {
215 foreach ($result->getErrorCollection() as $error)
216 {
217 if ($error instanceof ValidationError)
218 {
219 if (
220 $error->getCode() === 'name'
221 && $error->getFailedValidator() instanceof NotContainsUrlValidator
222 )
223 {
224 $error->setCode('ERROR_NAME_CONTAINS_URL');
225 break;
226 }
227 }
228 }
229 }
230 }
231}
if(!Loader::includeModule('messageservice')) $provider
Определения callback_ednaruimhpx.php:21
Определения error.php:15
sendAddEvent(AddCommand $command, Workgroup $entity)
Определения CollabService.php:136
sendUpdateEvent(UpdateCommand $command, Workgroup $entityBefore, Workgroup $entityAfter)
Определения CollabService.php:162
sendDeleteEvent(DeleteCommand $command, Workgroup $entityBefore)
Определения CollabService.php:176
checkDeleteCommand(DeleteCommand $command)
Определения CollabService.php:111
checkAddCommand(AbstractCommand $command)
Определения CollabService.php:89
sendBeforeUpdateEvent(UpdateCommand $command, Workgroup $entity)
Определения CollabService.php:150
finalizeAddResult(GroupResult $result)
Определения CollabService.php:122
finalizeUpdateResult(GroupResult $result)
Определения CollabService.php:129
checkUpdateCommand(UpdateCommand $command)
Определения CollabService.php:100
Определения AddLogEntryHandler.php:18
Определения UpdateLogEntryHandler.php:19
</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
$entity
$event
Определения prolog_after.php:141
$error
Определения subscription_card_product.php:20