36 || !isset($params[
'group_id'])
37 || !self::getUseChat()
38 || !Loader::includeModule(
'im')
44 if (!is_array($params[
'group_id']))
46 $params[
'group_id'] = array($params[
'group_id']);
49 $cacheKey = serialize($params);
50 if (isset(self::$staticCache[$cacheKey]))
52 return self::$staticCache[$cacheKey];
55 $params[
'group_id'] = array_values(array_unique(array_filter(array_map(
57 return (is_array($groupId) || intval($groupId) <= 0 ?
false : intval($groupId));
63 !isset($params[
'skipAvailabilityCheck'])
64 || !$params[
'skipAvailabilityCheck']
67 foreach($params[
'group_id'] as $key => $value)
69 if (!self::getGroupChatAvailable($value))
71 unset($params[
'group_id'][$key]);
76 $res = ChatTable::getList(array(
77 'select' => Array(
'ID',
'ENTITY_ID'),
79 '=ENTITY_TYPE' => self::CHAT_ENTITY_TYPE,
80 '@ENTITY_ID' => $params[
'group_id']
83 while ($chat = $res->fetch())
85 $result[$chat[
'ENTITY_ID']] = $chat[
'ID'];
88 self::$staticCache[$cacheKey] = $result;
120 || !isset($params[
'group_id'])
121 || intval($params[
'group_id']) <= 0
122 || !self::getUseChat()
123 || !Loader::includeModule(
'im')
129 $groupItem = Item\Workgroup::getById($params[
'group_id']);
135 $groupFields = $groupItem->getFields();
136 $project = $groupItem->isProject();
138 $userIdList = array();
140 $res = UserToGroupTable::getList(array(
142 'GROUP_ID' => $params[
'group_id'],
145 'select' => array(
'USER_ID')
148 while($relation = $res->fetch())
150 $userIdList[] = intval($relation[
'USER_ID']);
153 if (empty($userIdList))
155 $userIdList = array($groupFields[
'OWNER_ID']);
159 'TITLE' => self::buildChatName($groupFields[
'NAME'], array(
160 'project' => $project
162 'TYPE' => IM_MESSAGE_CHAT,
163 'ENTITY_TYPE' => self::CHAT_ENTITY_TYPE,
164 'ENTITY_ID' => intval($params[
'group_id']),
165 'SKIP_ADD_MESSAGE' =>
'Y',
166 'AUTHOR_ID' => $groupFields[
'OWNER_ID'],
167 'USERS' => $userIdList
170 $groupItem = Item\Workgroup::getById($params[
'group_id'],
false);
173 $groupFields = $groupItem->getFields();
174 if (!empty($groupFields[
'IMAGE_ID']))
176 $chatFields[
'AVATAR_ID'] = $groupFields[
'IMAGE_ID'];
180 $chat = new \CIMChat(0);
181 $result = $chat->add($chatFields);
185 self::$staticCache = array();
216 || !isset($params[
'group_id'])
217 || intval($params[
'group_id']) <= 0
218 || !isset($params[
'user_id'])
219 || !self::getUseChat()
220 || !Loader::includeModule(
'im')
226 $userIdList = (is_array($params[
'user_id']) ? $params[
'user_id'] : array($params[
'user_id']));
227 $groupId = intval($params[
'group_id']);
228 $setFlag = (isset($params[
'set']) && $params[
'set']);
230 $chatData = self::getChatData(array(
231 'group_id' => $groupId
236 || empty($chatData[$groupId])
237 || intval($chatData[$groupId]) <= 0
243 $chatId = $chatData[$groupId];
245 $chat = new \CIMChat();
247 $managersInfo = array();
248 foreach($userIdList as $userId)
250 $managersInfo[$userId] = $setFlag;
253 return $chat->setManagers($chatId, $managersInfo,
false);
262 || !isset($params[
'group_id'])
263 || intval($params[
'group_id']) <= 0
264 || !self::getUseChat()
265 || !Loader::includeModule(
'im')
271 $groupItem = Item\Workgroup::getById($params[
'group_id']);
277 $groupFields = $groupItem->getFields();
279 $chatMessageFields = array(
280 "MESSAGE" => str_replace(
'#GROUP_NAME#', $groupFields[
'NAME'],
Loc::getMessage($groupItem->isProject() ?
"SOCIALNETWORK_WORKGROUP_CHAT_UNLINKED_PROJECT" :
"SOCIALNETWORK_WORKGROUP_CHAT_UNLINKED")),
284 $res = ChatTable::getList(array(
285 'select' => Array(
'ID'),
287 '=ENTITY_TYPE' => self::CHAT_ENTITY_TYPE,
288 '=ENTITY_ID' => $params[
'group_id']
291 while ($chat = $res->fetch())
293 if (ChatTable::update($chat[
'ID'], array(
294 'ENTITY_TYPE' =>
false,
298 return \CIMChat::addMessage(array_merge(
299 $chatMessageFields, array(
300 "TO_CHAT_ID" => $chat[
'ID']