Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
linkmapper.php
1<?php
3
11
12abstract class LinkMapper extends Mapper
13{
21 protected function getDataManagerResult(array $params): Result
22 {
23 return SharingLinkTable::getList($params);
24 }
25
33 protected function getOneEntityByFilter(array $filter): ?object
34 {
35 $sharingLinkEO = SharingLinkTable::query()
36 ->setSelect(static::DEFAULT_SELECT)
37 ->setFilter($filter)
38 ->exec()
39 ->fetchObject();
40
41 if ($sharingLinkEO === null)
42 {
43 return null;
44 }
45
46 return $this->convertToObject($sharingLinkEO);
47 }
48
52 protected function createEntity($entity, array $params = []): ?Link
53 {
54 $data = [
55 'OBJECT_ID' => $entity->getObjectId(),
56 'OBJECT_TYPE' => $entity->getObjectType(),
57 'HASH' => $entity->getHash(),
58 'OPTIONS' => $this->getOptionsJSON($entity),
59 'DATE_CREATE' => new DateTime(),
60 'ACTIVE' => $entity->isActive(),
61 'DATE_EXPIRE' => $entity->getDateExpire(),
62 'JOINT' => $entity->isJoint(),
63 'FREQUENT_USE' => $entity->getFrequentUse(),
64 ];
65 $data = array_merge($data, $this->getSpecificFields($entity));
66
67 $result = SharingLinkTable::add($data);
68
69 if ($result->isSuccess())
70 {
71 $entity->setId($result->getId());
72 $this->createRelated($entity);
73 return $entity;
74 }
75
76 return null;
77 }
78
82 protected function updateEntity($entity, array $params = []): ?Link
83 {
84 $data = [
85 'OPTIONS' => $this->getOptionsJSON($entity),
86 'ACTIVE' => $entity->isActive(),
87 'DATE_EXPIRE' => $entity->getDateExpire(),
88 'FREQUENT_USE' => $entity->getFrequentUse(),
89 ];
90 $data = array_merge($data, $this->getSpecificFields($entity));
91
92 $result = SharingLinkTable::update($entity->getId(), $data);
93
94 if ($result->isSuccess())
95 {
96 return $entity;
97 }
98
99 return null;
100 }
101
107 protected function deleteEntity(EntityInterface $entity, array $params): ?Link
108 {
110 $this->deleteRelated($entity);
111
112 return null;
113 }
114
119 public function convertToArray(Link $sharingLink): array
120 {
121 return [
122 'id' => $sharingLink->getId(),
123 'type' => $sharingLink->getObjectType(),
124 'dateCreate' => $sharingLink->getDateCreate(),
125 'hash' => $sharingLink->getHash(),
126 'url' => $sharingLink->getUrl(),
127 'active' => $sharingLink->isActive(),
128 'frequentUse' => $sharingLink->getFrequentUse(),
129 ];
130 }
131
137 private function getOptionsJSON($entity): ?string
138 {
139 $options = $this->getOptionsArray($entity);
140
141 $result = null;
142 if (!empty($options))
143 {
144 $result = Json::encode($options);
145 }
146 return $result;
147 }
148
153 abstract protected function getOptionsArray($entity): array;
154
159 abstract protected function getSpecificFields($entity): array;
160
161 protected function deleteRelated(EntityInterface $entity): void
162 {
163
164 }
165
166 protected function createRelated($entity): void
167 {
168
169 }
170}
static getList(array $parameters=array())
static update($primary, array $data)