Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
usertogroup.php
1<?php
3
9
11{
12 const GROUP_USER_COPY_ERROR = "GROUP_USER_COPY_ERROR";
13
17 private $userGroupHelper = null;
18
24 public function setUserGroupHelper(UserGroupHelper $userGroupHelper)
25 {
26 $this->userGroupHelper = $userGroupHelper;
27 }
28
36 public function add(Container $container, array $fields)
37 {
38 global $APPLICATION;
39
40 foreach ($fields as $field)
41 {
42 if (!\CSocNetUserToGroup::add($field))
43 {
44 $errorMessage = "";
45 if ($exception = $APPLICATION->getException())
46 {
47 $errorMessage = $exception->getString();
48 $this->result->addError(new Error($errorMessage, self::GROUP_USER_COPY_ERROR));
49 }
50 if ($errorMessage == '')
51 {
52 $this->result->addError(new Error("Error adding a user to the group", self::GROUP_USER_COPY_ERROR));
53 }
54 }
55 }
56
57 if ($this->userGroupHelper)
58 {
59 $this->userGroupHelper->changeModerators($container->getCopiedEntityId());
60 }
61
62 return true;
63 }
64
72 public function getFields(Container $container, $entityId)
73 {
74 $fields = [];
75
76 $filter = [
77 "GROUP_ID" => $entityId,
79 ];
80 if (in_array("UF_SG_DEPT", $this->ufIgnoreList))
81 {
82 $filter["AUTO_MEMBER"] = "N";
83 }
84
85 $dictionary = $container->getDictionary();
86
87 $queryObject = \CSocNetUserToGroup::getList(["ID" => "DESC"], $filter);
88 while ($userToGroup = $queryObject->fetch())
89 {
90 if (
91 isset($dictionary["NEW_OWNER_ID"])
92 && $dictionary["NEW_OWNER_ID"] == $userToGroup["USER_ID"]
93 )
94 {
95 continue;
96 }
97
98 $fields[] = $userToGroup;
99 }
100
101 return $fields;
102 }
103
111 public function prepareFieldsToCopy(Container $container, array $fields)
112 {
113 global $DB;
114
115 foreach ($fields as &$field)
116 {
117 unset($field["ID"]);
118 unset($field["DATE_CREATE"]);
119 unset($field["DATE_UPDATE"]);
120
121 $field["SEND_MAIL"] = "N";
122 $field["=DATE_CREATE"] = $DB->currentTimeFunction();
123 $field["=DATE_UPDATE"] = $DB->currentTimeFunction();
124
125 $field["GROUP_ID"] = $container->getCopiedEntityId();
126 }
127
128 return $fields;
129 }
130
139 public function copyChildren(Container $container, $entityId, $copiedEntityId)
140 {
141 return new Result();
142 }
143}
getFields(Container $container, $entityId)
setUserGroupHelper(UserGroupHelper $userGroupHelper)
add(Container $container, array $fields)
copyChildren(Container $container, $entityId, $copiedEntityId)
prepareFieldsToCopy(Container $container, array $fields)