Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
userlinkmapper.php
1<?php
3
7
9{
10 protected const DEFAULT_SELECT = ['*', 'MEMBERS', 'MEMBERS.USER', 'MEMBERS.IMAGE'];
11
12 protected function convertToObject($objectEO): ?UserLink
13 {
14 $sharingUserLink = (new UserLink())
15 ->setId($objectEO->getId())
16 ->setUserId($objectEO->getObjectId())
17 ->setDateCreate($objectEO->getDateCreate())
18 ->setDateExpire($objectEO->getDateExpire())
19 ->setActive($objectEO->getActive())
20 ->setHash($objectEO->getHash())
21 ->setMembersHash($objectEO->getMembersHash())
22 ->setFrequentUse($objectEO->getFrequentUse())
23 ;
24
25 if ($objectEO->getMembers()?->count() > 0)
26 {
27 $sharingUserLink->setMembers((new Member\Manager())->createMembersFromEntityObject($objectEO->getMembers()));
28 }
29
30 $options = Json::decode($objectEO->getOptions() ?? '');
31 if (!empty($options['slotSize']))
32 {
33 $sharingUserLink->setSlotSize($options['slotSize']);
34 }
35
36 $rule = (new Rule\Factory())->getRuleBySharingLink($sharingUserLink);
37 $sharingUserLink->setSharingRule($rule);
38
39 return $sharingUserLink;
40 }
41
45 public function convertToArray($sharingLink): array
46 {
47 $baseArray = parent::convertToArray($sharingLink);
48
49 return array_merge($baseArray, [
50 'userId' => $sharingLink->getUserId(),
51 'slotSize' => $sharingLink->getSlotSize(),
52 'rule' => (new Rule\Mapper())->convertToArray($sharingLink->getSharingRule()),
53 ]);
54 }
55
56 protected function getOptionsArray($entity): array
57 {
58 $options = [];
59
60 if (!empty($entity->getSlotSize()))
61 {
62 $options['slotSize'] = $entity->getSlotSize();
63 }
64
65 return $options;
66 }
67
68 protected function getSpecificFields($entity): array
69 {
70 return [
71 'MEMBERS_HASH' => $entity->getMembersHash(),
72 ];
73 }
74
75 protected function getEntityClass(): string
76 {
77 return UserLink::class;
78 }
79
80 protected function getEntityName(): string
81 {
82 return 'Calendar sharing user link';
83 }
84}