Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
crmdeallinkmapper.php
1<?php
2
4
7
9{
14 protected function getOptionsArray($entity): array
15 {
17 $options = [];
18
19 if (!empty($entity->getSlotSize()))
20 {
21 $options['slotSize'] = $entity->getSlotSize();
22 }
23
24 if (!empty($entity->getChannelId()))
25 {
26 $options['channelId'] = $entity->getChannelId();
27 }
28
29 if (!empty($entity->getSenderId()))
30 {
31 $options['senderId'] = $entity->getSenderId();
32 }
33
34 if (!empty($entity->getLastStatus()))
35 {
36 $options['lastStatus'] = $entity->getLastStatus();
37 }
38
39 return $options;
40 }
41
42 protected function getEntityClass(): string
43 {
44 return CrmDealLink::class;
45 }
46
47 protected function convertToObject($objectEO): ?CrmDealLink
48 {
49 $crmDealLink = (new CrmDealLink())
50 ->setId($objectEO->getId())
51 ->setEntityId($objectEO->getObjectId())
52 ->setDateCreate($objectEO->getDateCreate())
53 ->setDateExpire($objectEO->getDateExpire())
54 ->setActive($objectEO->getActive())
55 ->setHash($objectEO->getHash())
56 ->setContactId($objectEO->getContactId())
57 ->setContactType($objectEO->getContactType())
58 ->setOwnerId($objectEO->getOwnerId())
59 ;
60
61 $options = Json::decode($objectEO->getOptions() ?? '');
62 if (!empty($options['slotSize']))
63 {
64 $crmDealLink->setSlotSize($options['slotSize']);
65 }
66
67 if (!empty($options['channelId']))
68 {
69 $crmDealLink->setChannelId($options['channelId']);
70 }
71
72 if (!empty($options['senderId']))
73 {
74 $crmDealLink->setSenderId($options['senderId']);
75 }
76
77 if (!empty($options['lastStatus']))
78 {
79 $crmDealLink->setLastStatus($options['lastStatus']);
80 }
81 //backward compatibility
82 if (empty($crmDealLink->getContactId()) && !empty($options['contactId']))
83 {
84 $crmDealLink->setContactId($options['contactId']);
85 }
86 if (empty($crmDealLink->getContactType()) && !empty($options['contactType']))
87 {
88 $crmDealLink->setContactType($options['contactType']);
89 }
90 if (empty($crmDealLink->getOwnerId()) && !empty($options['ownerId']))
91 {
92 $crmDealLink->setOwnerId($options['ownerId']);
93 }
94
95 $rule = (new Rule\Factory())->getRuleBySharingLink($crmDealLink);
96 $crmDealLink->setSharingRule($rule);
97
98 return $crmDealLink;
99 }
100
104 public function convertToArray($sharingLink): array
105 {
106 $baseArray = parent::convertToArray($sharingLink);
107
108 return array_merge($baseArray, [
109 'slotSize' => $sharingLink->getSlotSize(),
110 'channelId' => $sharingLink->getChannelId(),
111 'senderId' => $sharingLink->getSenderId(),
112 'entityId' => $sharingLink->getEntityId(),
113 'contactId' => $sharingLink->getContactId(),
114 'contactType' => $sharingLink->getContactType(),
115 'ownerId' => $sharingLink->getOwnerId(),
116 'lastStatus' => $sharingLink->getLastStatus(),
117 'rule' => (new Rule\Mapper())->convertToArray($sharingLink->getSharingRule()),
118 ]);
119 }
120
121 protected function getSpecificFields($entity): array
122 {
123 return [
124 'OWNER_ID' => $entity->getOwnerId(),
125 'CONTACT_ID' => $entity->getContactId(),
126 'CONTACT_TYPE' => $entity->getContactType(),
127 ];
128 }
129
130 protected function getEntityName(): string
131 {
132 return 'Crm deal sharing link';
133 }
134}