1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
StructureService.php
См. документацию.
1<?php
2
4
5use Bitrix\HumanResources\Repository\NodeRelationRepository;
6use Bitrix\HumanResources\Service\NodeMemberService;
7use Bitrix\HumanResources\Service\NodeRelationService;
8use Bitrix\HumanResources\Item\NodeMember;
9use Bitrix\HumanResources\Item\NodeRelation;
10use Bitrix\HumanResources\Service\Container;
11use Bitrix\HumanResources\Type\RelationEntityType;
20
22{
23 private readonly NodeMemberService $memberService;
24 private readonly NodeRelationService $relationService;
25 private readonly NodeRelationRepository $relationRepository;
26
27 public function __construct()
28 {
29 Loader::requireModule('humanresources');
30
31 $this->memberService = Container::getNodeMemberService();
32 $this->relationService = Container::getNodeRelationService();
33 $this->relationRepository = Container::getNodeRelationRepository();
34 }
35
36 public function handleRelationAdded(NodeRelation $relation): Result
37 {
38 $employees = $this->memberService->getPagedEmployees(
39 $relation->nodeId,
40 $relation->withChildNodes,
41 )->getValues()
42 ;
43
44 if (empty($employees))
45 {
46 return new Result();
47 }
48
49 $users = array_map(static fn(NodeMember $employee): array => ['user', $employee->entityId], $employees);
50 $convertedMembers = Converter::convertToFinderCodes($users);
51
52 return $this->addMembersForRelation($relation, $convertedMembers);
53 }
54
55 public function handleMemberAdded(NodeMember $member): CollabResult
56 {
57 $relations = $this->relationRepository->findRelationsByNodeIdAndRelationType(
58 $member->nodeId,
59 RelationEntityType::COLLAB,
60 );
61
62 $convertedMembers = Converter::convertToFinderCodes([['user', $member->entityId]]);
63
64 $result = new CollabResult();
65 foreach ($relations as $relation)
66 {
67 $result->merge($this->addMembersForRelation($relation, $convertedMembers));
68 }
69
70 return $result;
71 }
72
73 public function handleRelationDeleted(NodeRelation $relation): Result
74 {
75 $employees = $this->memberService->getPagedEmployees(
76 $relation->nodeId,
77 $relation->withChildNodes,
78 )->getValues()
79 ;
80
81 $users = array_map(static fn(NodeMember $employee): int => $employee->entityId, $employees);
82
83 return $this->deleteMembersForRelation($relation, $users);
84 }
85
86 public function handleMemberDeleted(NodeMember $member): CollabResult
87 {
88 $relations = $this->relationRepository->findRelationsByNodeIdAndRelationType(
89 $member->nodeId,
90 RelationEntityType::COLLAB,
91 );
92
93 $result = new CollabResult();
94 foreach ($relations as $relation)
95 {
96 $result->merge($this->deleteMembersForRelation($relation, [$member->entityId]));
97 }
98
99 return $result;
100 }
101
102 protected function addMembersForRelation(NodeRelation $relation, array $convertedMembers): Result
103 {
104 $command = (new MembersCommand())
105 ->setMembers($convertedMembers)
106 ->setInitiatorId($relation->createdBy)
107 ->setGroupId($relation->entityId)
108 ->setInitiatedByType(UserToGroupTable::INITIATED_BY_STRUCTURE)
109 ;
110
111 return ServiceLocator::getInstance()->get('socialnetwork.collab.member.facade')->add($command);
112 }
113
114 protected function deleteMembersForRelation(NodeRelation $relation, array $employees): Result
115 {
116 $filteredUsers = $this->relationService->getUsersNotInRelation(
117 RelationEntityType::COLLAB,
118 $relation->entityId,
119 $employees
120 );
121
122 $groupUsers = ServiceLocator::getInstance()
123 ->get(UserToGroupRepository::class)
124 ->getForRelation($relation, $filteredUsers)
125 ;
126
127 $filteredUsers = array_column($groupUsers, 'USER_ID');
128
129 if (empty($filteredUsers))
130 {
131 return new Result();
132 }
133
134 $users = array_map(static fn(int $userId): array => ['user', $userId], $filteredUsers);
135 $convertedMembers = Converter::convertToFinderCodes($users);
136
137 $command = (new MembersCommand())
138 ->setMembers($convertedMembers)
139 ->setInitiatorId($relation->createdBy)
140 ->setGroupId($relation->entityId)
141 ;
142
143 return ServiceLocator::getInstance()->get('socialnetwork.collab.member.facade')->delete($command);
144 }
145}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
Определения loader.php:13
addMembersForRelation(NodeRelation $relation, array $convertedMembers)
Определения StructureService.php:102
deleteMembersForRelation(NodeRelation $relation, array $employees)
Определения StructureService.php:114
</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