Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
usergrouphelper.php
1<?php
3
6
8{
9 private $executiveUserId;
10 private $moderatorsIds = [];
11
12 public function __construct($executiveUserId, array $moderatorsIds)
13 {
14 $this->executiveUserId = $executiveUserId;
15 $this->moderatorsIds = $moderatorsIds;
16 }
17
18 public function changeModerators($groupId)
19 {
20 $currentModeratorsIds = $this->getCurrentModerators($groupId);
21
22 $addIds = array_diff($this->moderatorsIds, $currentModeratorsIds);
23 $deleteIds = array_diff($currentModeratorsIds, $this->moderatorsIds);
24
25 if ($addIds)
26 {
27 UserToGroup::addModerators([
28 "group_id" => $groupId,
29 "user_id" => $addIds,
30 "current_user_id" => $this->executiveUserId
31 ]);
32 }
33
34 if ($deleteIds)
35 {
36 $resRelation = UserToGroupTable::getList([
37 "filter" => [
38 "GROUP_ID" => $groupId,
39 "@USER_ID" => $deleteIds
40 ],
41 "select" => ["ID"]
42 ]);
43 while ($relation = $resRelation->fetch())
44 {
45 \CSocNetUserToGroup::delete($relation["ID"]);
46 }
47 }
48 }
49
50 private function getCurrentModerators($groupId)
51 {
52 $ids = [];
53
54 $queryObject = UserToGroupTable::getList([
55 "filter" => [
57 "GROUP_ID" => $groupId,
58 "=USER.ACTIVE" => "Y"
59 ],
60 "select" => ["USER_ID"]
61 ]);
62 while ($relation = $queryObject->fetch())
63 {
64 $ids[] = $relation["USER_ID"];
65 }
66
67 return $ids;
68 }
69}
__construct($executiveUserId, array $moderatorsIds)