1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
UpdateOptionsHandler.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
5namespace Bitrix\Socialnetwork\Collab\Control\Handler\Update;
6
7use Bitrix\Main\DI\ServiceLocator;
8use Bitrix\SocialNetwork\Collab\Analytics\CollabAnalytics;
9use Bitrix\Socialnetwork\Collab\Collab;
10use Bitrix\Socialnetwork\Collab\Control\Command\CollabUpdateCommand;
11use Bitrix\Socialnetwork\Collab\Control\Handler\Trait\SetOptionsTrait;
12use Bitrix\Socialnetwork\Collab\Control\Option\AbstractOption;
13use Bitrix\Socialnetwork\Collab\Log\CollabLogEntryCollection;
14use Bitrix\Socialnetwork\Collab\Log\Entry\UpdateCollabLogEntry;
15use Bitrix\Socialnetwork\Collab\Property\Option;
16use Bitrix\Socialnetwork\Control\Handler\HandlerResult;
17use Bitrix\Socialnetwork\Control\Handler\Update\UpdateHandlerInterface;
18use Bitrix\Socialnetwork\Control\Command\UpdateCommand;
19use Bitrix\Socialnetwork\Item\Workgroup;
20
22{
23 use SetOptionsTrait;
24
25 public function update(UpdateCommand $command, Workgroup $entityBefore, Workgroup $entityAfter): HandlerResult
26 {
27 $handlerResult = $this->setOptions($command, $entityBefore);
28
29 if (!$handlerResult->isSuccess())
30 {
31 return $handlerResult;
32 }
33
34 $writeToLogResult = $this->writeCollabUpdateToLog($command, $entityBefore);
35
36 return $handlerResult->merge($writeToLogResult);
37 }
38
39 private function writeCollabUpdateToLog(UpdateCommand $command, Workgroup $entityBefore): HandlerResult
40 {
41 $handlerResult = new HandlerResult();
42
43 if (!($command instanceof CollabUpdateCommand) || !($entityBefore instanceof Collab))
44 {
45 return $handlerResult;
46 }
47
48 $logEntryCollection = new CollabLogEntryCollection();
49
50 $newOptions = $command->getOptions()?->getValue();
51
52 if ($newOptions === null)
53 {
54 return $handlerResult;
55 }
56
57 $analytics = CollabAnalytics::getInstance();
58
59 $oldOptions = $entityBefore->getOptions();
60
61 foreach ($newOptions as $newOption)
62 {
64 $oldOption = $this->getOptionByName($oldOptions, $newOption->getName());
65 if ($oldOption === null)
66 {
67 continue;
68 }
69
70 if ($oldOption->value === $newOption->getValue())
71 {
72 continue;
73 }
74
75 $logEntry = new UpdateCollabLogEntry(
76 userId: $command->getInitiatorId(),
77 collabId: $command->getId(),
78 );
79
80 $logEntry
81 ->setFieldName($newOption->getName())
82 ->setPreviousValue($oldOption->value)
83 ->setCurrentValue($newOption->getValue())
84 ;
85
86 $logEntryCollection->add($logEntry);
87
88 $analytics->onSettingsChanged($command->getInitiatorId(), $command->getId(), strtolower($newOption->getName()));
89 }
90
91 if ($logEntryCollection->isEmpty())
92 {
93 return $handlerResult;
94 }
95
96 $service = ServiceLocator::getInstance()->get('socialnetwork.collab.log.service');
97 $service->saveCollection($logEntryCollection);
98
99 return $handlerResult;
100 }
101
102 private function getOptionByName(array $options, string $name): ?Option
103 {
104 foreach ($options as $option)
105 {
107 if ($option->name === $name)
108 {
109 return $option;
110 }
111 }
112
113 return null;
114 }
115}
update(UpdateCommand $command, Workgroup $entityBefore, Workgroup $entityAfter)
Определения UpdateOptionsHandler.php:25
$options
Определения commerceml2.php:49
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$name
Определения menu_edit.php:35
$service
Определения payment.php:18
$option
Определения options.php:1711