14 protected const SELECT = [
'*',
'MEMBERS',
'MEMBERS.USER',
'MEMBERS.IMAGE'];
21 if (self::$instance ===
null)
23 self::$instance =
new self();
26 return self::$instance;
48 if ($sharingLink instanceof
UserLink)
72 $sharingLinkEO = SharingLinkTable::query()
73 ->setSelect(self::SELECT)
74 ->where(
'HASH', $hash)
75 ->exec()->fetchObject()
78 if ($sharingLinkEO ===
null)
83 if ($sharingLinkEO->getObjectType() === Helper::USER_SHARING_TYPE)
88 if ($sharingLinkEO->getObjectType() === Helper::EVENT_SHARING_TYPE)
93 if ($sharingLinkEO->getObjectType() === Helper::CRM_DEAL_SHARING_TYPE)
110 '=OBJECT_ID' => $userId,
111 '=OBJECT_TYPE' => Helper::USER_SHARING_TYPE,
127 '=OBJECT_ID' => $userId,
128 '=OBJECT_TYPE' => Helper::USER_SHARING_TYPE,
130 '=MEMBERS_HASH' =>
null,
145 '=OBJECT_ID' => $userId,
146 '=OBJECT_TYPE' => Helper::USER_SHARING_TYPE,
148 '!=MEMBERS_HASH' =>
null,
167 $rule = (
new Rule\Factory())->getRuleBySharingLink($userLink);
168 $userLink->setSharingRule($rule);
189 ->setEventId($params[
'eventId'])
191 ->setHostId($params[
'hostId'])
192 ->setParentLinkHash($params[
'parentLinkHash'])
194 ->setDateExpire($params[
'expiryDate'] ??
null)
195 ->setExternalUserName($params[
'externalUserName'] ??
null)
218 ?
int $contactId =
null,
219 ?
int $contactType =
null,
220 ?
string $channelId =
null,
221 ?
string $senderId =
null
225 ->setOwnerId($ownerId)
227 ->setContactType($contactType)
228 ->setContactId($contactId)
229 ->setChannelId($channelId)
230 ->setSenderId($senderId)
233 Sharing\Helper::createSharingLinkExpireDate(
241 $rule = (
new Rule\Factory())->getRuleBySharingLink($crmDealLink);
242 $crmDealLink->setSharingRule($rule);
255 SharingLinkTable::update($existJointLink->getId(), [
256 'FREQUENT_USE' => $existJointLink->getFrequentUse() + 1,
259 return $existJointLink;
265 ->setMembers($this->getMembersFromIds($memberIds))
266 ->setMembersHash($memberHash)
272 return $userJointLink;
279 ->setMembers($this->getMembersFromIds($memberIds))
288 private function getMembersFromIds(array $memberIds): array
290 $memberIds = array_map(
static function ($memberId) {
291 return (
int)$memberId;
295 $users = UserTable::query()
296 ->whereIn(
'ID', $memberIds)
297 ->where(
'IS_REAL_USER',
'Y')
298 ->setSelect([
'NAME',
'LAST_NAME',
'ID'])
303 foreach ($users as $user)
307 ->setId($user->getId())
308 ->setName($user->getName())
309 ->setLastName($user->getLastName())
319 $memberIds = array_map(
static function ($memberId) {
320 return (
int)$memberId;
324 $implodedUsers = implode(
'|', $memberIds) .
'|' . $userId;
326 return md5($implodedUsers);
340 $sharingLinkEO = SharingLinkTable::query()
342 ->where(
'OBJECT_ID', $eventId)
343 ->where(
'OBJECT_TYPE', Helper::EVENT_SHARING_TYPE)
344 ->where(
'ACTIVE',
'Y')
345 ->exec()->fetchObject()
348 if ($sharingLinkEO ===
null)
367 $sharingLinkEO = SharingLinkTable::query()
368 ->setSelect(self::SELECT)
369 ->where(
'OBJECT_ID', $eventId)
370 ->where(
'OBJECT_TYPE', Helper::EVENT_SHARING_TYPE)
371 ->exec()->fetchObject();
373 if ($sharingLinkEO ===
null)
396 ?
int $contactId =
null,
397 ?
int $contactType =
null
400 $sharingLinkEO = SharingLinkTable::query()
401 ->setSelect(self::SELECT)
402 ->where(
'OBJECT_ID', $entityId)
403 ->where(
'OBJECT_TYPE', Helper::CRM_DEAL_SHARING_TYPE)
404 ->where(
'ACTIVE',
'Y')
405 ->where(
'OWNER_ID', $ownerId)
406 ->where(
'CONTACT_ID', $contactId)
407 ->where(
'CONTACT_TYPE', $contactType)
408 ->where(
'DATE_CREATE',
'>=', (
new DateTime())->setTime(0, 0))
409 ->whereNull(
'MEMBERS.MEMBER_ID')
410 ->exec()->fetchObject();
412 if ($sharingLinkEO ===
null)
422 $sharingLinkEO = SharingLinkTable::query()
423 ->setSelect(self::SELECT)
424 ->where(
'MEMBERS_HASH', $membersHash)
425 ->where(
'ACTIVE',
'Y')
426 ->exec()->fetchObject()
429 if ($sharingLinkEO ===
null)
439 $entityObject = SharingLinkTable::query()
440 ->setSelect([
'PARENT_LINK_HASH'])
441 ->where(
'CONFERENCE_ID', $conferenceId)
442 ->exec()->fetchObject()
445 if (is_null($entityObject))
450 $parentLink = $this->
getLinkByHash($entityObject->getParentLinkHash());
458 ?
int $contactId =
null,
459 ?
int $contactType =
null
462 $sharingLinkEO = SharingLinkTable::query()
463 ->setSelect(self::SELECT)
464 ->where(
'OBJECT_ID', $entityId)
465 ->where(
'OBJECT_TYPE', Helper::CRM_DEAL_SHARING_TYPE)
466 ->where(
'ACTIVE',
'Y')
467 ->where(
'OWNER_ID', $ownerId)
468 ->where(
'CONTACT_ID', $contactId)
469 ->where(
'CONTACT_TYPE', $contactType)
470 ->whereNotNull(
'MEMBERS.MEMBER_ID')
471 ->exec()->fetchObject();
473 if ($sharingLinkEO ===
null)
getLinkArrayByHash(string $hash)
getAllUserLinks(int $userId)
getUserJointLinks($userId)
createUserLink(int $userId)
getLinkByHash(string $hash)
createUserJointLink(int $userId, array $memberIds)
getJointLinkByMembersHash(string $membersHash)
generateMembersHash(int $userId, array $memberIds)
createEventLink(array $params)
getParentLinkByConferenceId(string $conferenceId)
createCrmDealJointLink(CrmDealLink $crmDealLink, array $memberIds)
getCrmDealJointLink(int $entityId, int $ownerId, ?int $contactId=null, ?int $contactType=null)
getEventLinkByEventId(int $eventId)
createCrmDealLink(int $ownerId, int $entityId, ?int $contactId=null, ?int $contactType=null, ?string $channelId=null, ?string $senderId=null)
getCrmDealLink(int $entityId, int $ownerId, ?int $contactId=null, ?int $contactType=null)
getDeletedEventLinkByEventId(int $eventId)