141 $params[
'EXTERNAL_AUTH_ID'] === \CSocServBitrix24Net::ID
145 $notificationOptions = \CUserOptions::getOption(
"socialservices",
"notifications", array());
148 if(isset($notificationOptions[
"CONTACTS_NOTIFY_DATE"]))
150 $lastDate = $notificationOptions[
"CONTACTS_NOTIFY_DATE"];
153 if($lastDate < time() - 86400)
155 static::notifyPossible($USER->getId());
157 $notificationOptions[
"CONTACTS_NOTIFY_DATE"] = time();
158 \CUserOptions::setOption(
"socialservices",
"notifications", $notificationOptions);
165 $contactsList = array();
166 $possibleContactsList = array();
168 if(isset($data[
"contact"]) && is_array($data[
"contact"]))
170 foreach($data[
"contact"] as $contact)
172 if(!isset($contactsList[$contact[
'CONTACT_OWNER']]))
174 $contactsList[$contact[
'CONTACT_OWNER']] = array();
177 $contactsList[$contact[
'CONTACT_OWNER']][] = $contact;
181 if(isset($data[
"contact_possible"]) && is_array($data[
"contact_possible"]))
183 foreach($data[
"contact_possible"] as $contact)
185 if(!isset($possibleContactsList[$contact[
'CONTACT_OWNER']]))
187 $possibleContactsList[$contact[
'CONTACT_OWNER']] = array();
190 $possibleContactsList[$contact[
'CONTACT_OWNER']][] = $contact;
194 $dbRes = UserTable::getList(array(
196 '=EXTERNAL_AUTH_ID' => \CSocServBitrix24Net::ID,
197 '=XML_ID' => array_unique(
199 array_keys($contactsList),
200 array_keys($possibleContactsList)
204 'select' => array(
'ID',
'USER_ID',
'XML_ID')
207 while($owner = $dbRes->fetch())
210 count($contactsList) > 0
211 && isset($contactsList[$owner[
"XML_ID"]])
212 && is_array($contactsList[$owner[
"XML_ID"]])
213 && count($contactsList[$owner[
"XML_ID"]]) > 0
216 static::processContacts($owner, $contactsList[$owner[
"XML_ID"]]);
220 count($possibleContactsList) > 0
221 && isset($possibleContactsList[$owner[
"XML_ID"]])
222 && is_array($possibleContactsList[$owner[
"XML_ID"]])
223 && count($possibleContactsList[$owner[
"XML_ID"]]) > 0
226 static::processPossibleContacts($owner, $possibleContactsList[$owner[
"XML_ID"]]);
233 if(!Main\Loader::includeModule(
'rest'))
238 $existedContacts = array();
239 $dbRes = ContactTable::getList(array(
241 '=USER_ID' => $owner[
"USER_ID"],
243 'select' => array(
'ID',
'CONTACT_XML_ID')
245 while($existedContact = $dbRes->fetch())
247 $existedContacts[$existedContact[
'CONTACT_XML_ID']] = $existedContact[
'ID'];
250 foreach($contactsList as $contact)
252 $contactFields = array(
253 "USER_ID" => $owner[
"USER_ID"],
254 "CONTACT_XML_ID" => $contact[
"CONTACT_ID"],
255 "CONTACT_NAME" => $contact[
"NAME"],
256 "CONTACT_LAST_NAME" => $contact[
"LAST_NAME"],
257 "CONTACT_PHOTO" => $contact[
"PHOTO"],
258 "NOTIFY" => $contact[
"NOTIFY"],
263 if(isset($existedContacts[$contactFields[
"CONTACT_XML_ID"]]))
265 $contactId = $existedContacts[$contactFields[
"CONTACT_XML_ID"]];
266 $result = static::update($contactId, $contactFields);
267 if(!$result->isSuccess())
269 AddMessage2Log($result->getErrorMessages());
274 $result = static::add($contactFields);
275 if($result->isSuccess())
277 $contactId = $result->getId();
281 AddMessage2Log($result->getErrorMessages());
287 && isset($contact[
"profile"])
288 && count($contact[
"profile"]) > 0
291 if(isset($existedContacts[$contactFields[
"CONTACT_XML_ID"]]))
296 foreach($contact[
"profile"] as $profile)
298 $connectFields = array(
299 'CONTACT_ID' => $contactId,
300 'CONTACT_PROFILE_ID' => $profile[
'PROFILE_ID'],
301 'CONTACT_PORTAL' => $profile[
'PORTAL'],
302 'CONNECT_TYPE' => $profile[
'TYPE'],
306 $r = ContactConnectTable::add($connectFields);
309 if(!isset($contactFields[
"CONNECT"]))
311 $contactFields[
"CONNECT"] = array($connectFields);
315 $contactFields[
"CONNECT"][] = $connectFields;
320 if(!isset($existedContacts[$contactFields[
"CONTACT_XML_ID"]]))
322 static::notifyJoin($contactId, $contactFields);
327 static::notifyJoinFinish($owner[
"USER_ID"]);
332 if(!Main\Loader::includeModule(
'rest'))
337 $existedContacts = array();
340 '=SOCSERV_USER_ID' => $owner[
"ID"],
341 '=SOCSERV_USER.EXTERNAL_AUTH_ID' => \CSocServBitrix24Net::ID,
343 'select' => array(
'ID',
'LINK_UID')
345 while($existedContact = $dbRes->fetch())
347 $existedContacts[$existedContact[
'LINK_UID']] = $existedContact[
'ID'];
350 foreach($contactsList as $contact)
352 $contactFields = array(
353 "USER_ID" => $owner[
"USER_ID"],
354 "SOCSERV_USER_ID" => $owner[
"ID"],
355 "LINK_UID" => $contact[
"CONTACT_ID"],
356 "LINK_NAME" => $contact[
"NAME"],
357 "LINK_LAST_NAME" => $contact[
"LAST_NAME"],
358 "LINK_PICTURE" => $contact[
"PHOTO"],
362 if(isset($existedContacts[$contactFields[
"LINK_UID"]]))
364 $linkId = $existedContacts[$contactFields[
"LINK_UID"]];
370 if($result->isSuccess())
372 $linkId = $result->getId();
378 && isset($contact[
"profile"])
379 && count($contact[
"profile"]) > 0
382 if(isset($existedContacts[$contactFields[
"LINK_UID"]]))
387 foreach($contact[
"profile"] as $profile)
389 $result = ContactConnectTable::add(array(
390 'LINK_ID' => $linkId,
391 'CONTACT_PROFILE_ID' => $profile[
'PROFILE_ID'],
392 'CONTACT_PORTAL' => $profile[
'PORTAL'],
393 'CONNECT_TYPE' => $profile[
'TYPE'],
415 $network->isOptionEnabled()
416 && count(static::$notifyStack) > 0
417 && Main\Loader::includeModule(
'im')
420 $attach = new \CIMMessageParamAttach(
null, \CIMMessageParamAttach::NORMAL);
423 foreach(static::$notifyStack as $contactInfo)
425 if(++$count > static::NOTIFY_CONTACT_COUNT)
427 $attach->AddHtml(
'<a href="'.str_replace(
"#USER_ID#", $userId, Option::get(
"intranet",
"path_user",
"/company/persona/user/#USER_ID#/")).
'">'.
Loc::getMessage(
"SS_JOIN_NOTIFY_MORE", array(
"#NUM#" => count(static::$notifyStack)-$count+1)).
'</a>');
432 $attachParams = array(
433 "NAME" => \CUser::FormatName(\CSite::GetNameFormat(), array(
434 "NAME" => $contactInfo[
"CONTACT_NAME"],
435 "LAST_NAME" => $contactInfo[
"CONTACT_LAST_NAME"]
438 if($contactInfo[
"CONTACT_PHOTO"])
440 $attachParams[
"AVATAR"] = $contactInfo[
"CONTACT_PHOTO"];
442 $attachParams[
"NETWORK_ID"] = static::getConnectId($contactInfo[
"CONNECT"][0]);
444 $attach->AddUser($attachParams);
448 $messageFields = array(
449 "TO_USER_ID" => $userId,
451 "NOTIFY_TYPE" => IM_NOTIFY_SYSTEM,
452 "NOTIFY_MODULE" =>
"socialservices",
453 "NOTIFY_EVENT" =>
"multiple_contacts",
455 "NOTIFY_MESSAGE_OUT" => IM_MAIL_SKIP,
456 "ATTACH" => array($attach),
459 \CIMNotify::Add($messageFields);
461 static::$notifyStack = array();