1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
UpdateMemberRoleTrait.php
См. документацию.
1<?php
2
3namespace Bitrix\Socialnetwork\Control\Member\Trait;
4
5use Bitrix\Main\ArgumentException;
6use Bitrix\Main\Error;
7use Bitrix\Main\ObjectPropertyException;
8use Bitrix\Main\SystemException;
9use Bitrix\Main\Type\DateTime;
10use Bitrix\Socialnetwork\Control\Handler\HandlerResult;
11use Bitrix\Socialnetwork\UserToGroupTable;
12use CSocNetUserToGroup;
13
14trait UpdateMemberRoleTrait
15{
16 private function updateMembersRole(int $groupId, int $initiatorId, string $role, int ...$members): HandlerResult
17 {
18 $handlerResult = new HandlerResult();
19
20 if (empty($members))
21 {
22 return $handlerResult;
23 }
24
25 $handlerResult->setGroupChanged();
26
27 $relationList = $this->getRelationList($groupId, ...$members);
28 foreach ($members as $userId)
29 {
30 $user = [
31 'ROLE' => $role,
32 'DATE_CREATE' => new DateTime(),
33 'DATE_UPDATE' => new DateTime(),
34 'INITIATED_BY_TYPE' => UserToGroupTable::INITIATED_BY_GROUP,
35 'INITIATED_BY_USER_ID' => $initiatorId,
36 ];
37
38 if (!isset($relationList[$userId]))
39 {
40 $handlerResult->addError(new Error("User {$userId} not found in group {$groupId}"));
41 }
42
44 if ($result === false)
45 {
46 $handlerResult->addApplicationError();
47 }
48 }
49
50 return $handlerResult;
51 }
52
58 private function getRelationList(int $groupId, int ...$memberIds): array
59 {
60 $relationCollection = UserToGroupTable::query()
61 ->setSelect(['ID', 'USER_ID', 'GROUP_ID'])
62 ->setFilter([
63 '@USER_ID' => $memberIds,
64 '=GROUP_ID' => $groupId,
65 ])
66 ->fetchCollection()
67 ;
68
69 $result = [];
70 foreach ($relationCollection as $relation)
71 {
72 $result[$relation['USER_ID']] = $relation['ID'];
73 }
74
75 return $result;
76 }
77}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
Определения error.php:15
static Update($ID, $arFields)
Определения user_group.php:137
</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
$user
Определения mysql_to_pgsql.php:33