Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
syspage.php
1<?php
2namespace Bitrix\Landing;
3
4use \Bitrix\Landing\Internals\SyspageTable;
5
6class Syspage
7{
12 protected static $allowedTypes = array(
13 'mainpage',
14 'catalog',
15 'personal',
16 'cart',
17 'order',
18 'payment',
19 'compare',
20 'feedback',
21 );
22
30 public static function set($id, $type, $lid = false)
31 {
32 if (!is_string($type))
33 {
34 return;
35 }
36
37 $id = intval($id);
38 $type = trim($type);
39
40 if (!in_array($type, self::$allowedTypes))
41 {
42 return;
43 }
44
46 {
47 return;
48 }
49
50 $res = SyspageTable::getList(array(
51 'select' => array(
52 'ID'
53 ),
54 'filter' => array(
55 'SITE_ID' => $id,
56 '=TYPE' => $type
57 )
58 ));
59 if ($row = $res->fetch())
60 {
61 if ($lid === false)
62 {
63 SyspageTable::delete($row['ID']);
64 }
65 else
66 {
67 SyspageTable::update($row['ID'], array(
68 'LANDING_ID' => (int)$lid
69 ));
70 }
71 }
72 else if ($lid !== false)
73 {
74 $check = Site::getList([
75 'select' => [
76 'ID'
77 ],
78 'filter' => [
79 'ID' => $id
80 ]
81 ])->fetch();
82 if ($check)
83 {
84 SyspageTable::add(array(
85 'SITE_ID' => $id,
86 'TYPE' => $type,
87 'LANDING_ID' => (int)$lid
88 ));
89 }
90 }
91 }
92
100 public static function get(int $id, bool $active = false, bool $force = false): array
101 {
102 static $types = array();
103 $id = intval($id);
104
105 // check items for un active elements
106 $removeHidden = function(array $items) use($active)
107 {
108 if (!$active)
109 {
110 return $items;
111 }
112 foreach ($items as $k => $item)
113 {
114 if (
115 $item['DELETED'] == 'Y' ||
116 $item['ACTIVE'] == 'N'
117 )
118 {
119 unset($items[$k]);
120 }
121 }
122 return $items;
123 };
124
125 if (
126 !$force
127 && isset($types[$id])
128 && count($types[$id]) > 0
129 )
130 {
131 return $removeHidden($types[$id]);
132 }
133
134 $types[$id] = array();
135
136 $res = SyspageTable::getList(array(
137 'select' => array(
138 'TYPE',
139 'LANDING_ID',
140 'TITLE' => 'LANDING.TITLE',
141 'DELETED' => 'LANDING.DELETED',
142 'ACTIVE' => 'LANDING.ACTIVE'
143 ),
144 'filter' => array(
145 'SITE_ID' => $id
146 ),
147 'runtime' => array(
148 new \Bitrix\Main\Entity\ReferenceField(
149 'LANDING',
150 '\Bitrix\Landing\Internals\LandingTable',
151 array('=this.LANDING_ID' => 'ref.ID')
152 )
153 )
154 ));
155 while ($row = $res->fetch())
156 {
157 $types[$id][$row['TYPE']] = $row;
158 }
159
160 // event for external changes
161 $event = new \Bitrix\Main\Event('landing', 'onLandingSyspageRetrieve', [
162 'types' => $types
163 ]);
164 $event->send();
165 foreach ($event->getResults() as $result)
166 {
167 $params = $result->getParameters();
168 if (is_array($params))
169 {
170 $types = $params;
171 }
172 }
173
174 return $removeHidden($types[$id]);
175 }
176
182 public static function deleteForSite($id)
183 {
184 $id = intval($id);
185 $res = SyspageTable::getList(array(
186 'filter' => array(
187 'SITE_ID' => $id
188 )
189 ));
190 while ($row = $res->fetch())
191 {
192 SyspageTable::delete($row['ID']);
193 }
194 }
195
201 public static function deleteForLanding($id)
202 {
203 $id = intval($id);
204 $res = SyspageTable::getList(array(
205 'filter' => array(
206 'LANDING_ID' => $id
207 )
208 ));
209 while ($row = $res->fetch())
210 {
211 SyspageTable::delete($row['ID']);
212 }
213 }
214
223 public static function getSpecialPage($siteId, $type, array $additional = [])
224 {
225 $url = '';
226 $siteId = (int)$siteId;
227
228 if (!is_string($type))
229 {
230 return $url;
231 }
232
233 $res = SyspageTable::getList([
234 'select' => [
235 'LANDING_ID'
236 ],
237 'filter' => [
238 'SITE_ID' => $siteId,
239 '=TYPE' => $type
240 ]
241 ]);
242 if ($row = $res->fetch())
243 {
244 $landing = Landing::createInstance(0);
245 $url = $landing->getPublicUrl($row['LANDING_ID']);
246 if ($additional)
247 {
248 $uri = new \Bitrix\Main\Web\Uri($url);
249 $uri->addParams($additional);
250 $url = $uri->getUri();
251 unset($uri);
252 }
253 }
254 unset($row, $res);
255
256 return $url;
257 }
258}
static getList(array $params=[], $initiator=null)
Definition site.php:99
static hasAccessForSite($siteId, $accessType, $deleted=false)
Definition rights.php:544
static deleteForSite($id)
Definition syspage.php:182
static getSpecialPage($siteId, $type, array $additional=[])
Definition syspage.php:223
static deleteForLanding($id)
Definition syspage.php:201