1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
AddMemberHandler.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
5namespace Bitrix\Socialnetwork\Collab\Control\Handler\Add;
6
7use Bitrix\Main\ArgumentException;
8use Bitrix\Main\LoaderException;
9use Bitrix\Main\ObjectPropertyException;
10use Bitrix\Main\SystemException;
11use Bitrix\Socialnetwork\Collab\Integration\IM\ActionMessageBuffer;
12use Bitrix\Socialnetwork\Provider\EmployeeProvider;
13use Bitrix\Socialnetwork\Control\Member\Trait\AddMemberTrait;
14use Bitrix\Socialnetwork\Collab\Integration\IM\ActionType;
15use Bitrix\Socialnetwork\Control\Command\AddCommand;
16use Bitrix\Socialnetwork\Control\Handler\Add\AddHandlerInterface;
17use Bitrix\Socialnetwork\Control\Handler\HandlerResult;
18use Bitrix\Socialnetwork\Control\Member\Trait\GetMembersTrait;
19use Bitrix\Socialnetwork\Integration\HumanResources\AccessCodeConverter;
20use Bitrix\Socialnetwork\Item\Workgroup;
21use Bitrix\Socialnetwork\UserToGroupTable;
22
24{
25 use GetMembersTrait;
26 use AddMemberTrait;
27
34 public function add(AddCommand $command, Workgroup $entity): HandlerResult
35 {
36 $handlerResult = new HandlerResult();
37
38 $members = $command->getMembers();
39 if (empty($members))
40 {
41 return $handlerResult;
42 }
43
44 $membersByCommand = (new AccessCodeConverter(...$members))
45 ->getUsers()
46 ->getUserIds();
47
48 $add = array_diff($membersByCommand, $this->getMemberIds($entity->getId()));
49
50 $handlerResult = $this->addMembers(
51 $entity->getId(),
52 $command->getInitiatorId(),
55 ...$add,
56 );
57
58 if (!$handlerResult->isSuccess())
59 {
60 return $handlerResult;
61 }
62
63 [$employeeIds, $guestIds] = EmployeeProvider::getInstance()->splitIntoEmployeesAndGuests($membersByCommand);
64
65 ActionMessageBuffer::getInstance()
66 ->put(ActionType::AddUser, $entity->getId(), $command->getInitiatorId(), $employeeIds)
67 ->put(ActionType::AddGuest, $entity->getId(), $command->getInitiatorId(), $guestIds);
68
69 return $handlerResult;
70 }
71}
add(AddCommand $command, Workgroup $entity)
Определения AddMemberHandler.php:34
$entity