Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
templateref.php
1<?php
2namespace Bitrix\Landing;
3
4use \Bitrix\Landing\Internals\TemplateRefTable;
5
7{
11 const ENTITY_TYPE_SITE = 'S';
12
17
25 protected static function set($id, $type, array $data = array())
26 {
27 $id = intval($id);
28 $res = TemplateRefTable::getList(array(
29 'select' => array(
30 'ID', 'AREA', 'LANDING_ID'
31 ),
32 'filter' => array(
33 'ENTITY_ID' => $id,
34 '=ENTITY_TYPE' => $type
35 )
36 ));
37 while (($row = $res->fetch()))
38 {
39 if (isset($data[$row['AREA']]) && $data[$row['AREA']] > 0)
40 {
41 if ($row['LANDING_ID'] != $data[$row['AREA']])
42 {
43 TemplateRefTable::update($row['ID'], array(
44 'LANDING_ID' => $data[$row['AREA']]
45 ));
46 }
47 unset($data[$row['AREA']]);
48 }
49 else
50 {
51 TemplateRefTable::delete($row['ID']);
52 }
53 }
54 foreach ($data as $area => $lid)
55 {
56 if ($lid > 0)
57 {
58 TemplateRefTable::add(array(
59 'ENTITY_ID' => $id,
60 'ENTITY_TYPE' => $type,
61 'LANDING_ID' => $lid,
62 'AREA' => $area
63 ));
64 }
65 }
66 }
67
74 protected static function get($id, $type)
75 {
76 static $staticData = array();
77 $id = intval($id);
78
79 if (!isset($staticData[$type . $id]))
80 {
81 $data = array();
82 if ($id > 0)
83 {
84 $res = TemplateRefTable::getList(array(
85 'select' => array(
86 'AREA', 'LANDING_ID'
87 ),
88 'filter' => array(
89 'ENTITY_ID' => $id,
90 '=ENTITY_TYPE' => $type
91 )
92 ));
93 while (($row = $res->fetch()))
94 {
95 $data[$row['AREA']] = $row['LANDING_ID'];
96 }
97 }
98
99 $staticData[$type . $id] = $data;
100 }
101
102 return $staticData[$type . $id];
103 }
104
111 public static function setForSite($id, array $data = array())
112 {
114 {
115 self::set($id, self::ENTITY_TYPE_SITE, $data);
116 }
117 }
118
125 public static function setForLanding($id, array $data = array())
126 {
128 {
129 self::set($id, self::ENTITY_TYPE_LANDING, $data);
130 }
131 }
132
138 public static function getForSite($id)
139 {
140 return self::get($id, self::ENTITY_TYPE_SITE);
141 }
142
148 public static function getForLanding($id)
149 {
150 return self::get($id, self::ENTITY_TYPE_LANDING);
151 }
152
158 public static function landingIsArea($lid)
159 {
160 $res = TemplateRefTable::getList(array(
161 'filter' => array(
162 'LANDING_ID' => $lid
163 )
164 ));
165 if (is_array($lid))
166 {
167 $return = array();
168 foreach ($lid as $id)
169 {
170 $return[(int)$id] = false;
171 }
172 while ($row = $res->fetch())
173 {
174 $return[$row['LANDING_ID']] = true;
175 }
176 return $return;
177 }
178 else
179 {
180 return $res->fetch() ? true : false;
181 }
182 }
183
189 public static function deleteArea($lid)
190 {
191 $lid = intval($lid);
192
193 $res = TemplateRefTable::getList(array(
194 'filter' => array(
195 'LANDING_ID' => $lid
196 )
197 ));
198 while ($row = $res->fetch())
199 {
200 TemplateRefTable::delete($row['ID']);
201 }
202 }
203
209 public static function resolveClassByType($type)
210 {
211 if ($type == self::ENTITY_TYPE_SITE)
212 {
213 return '\Bitrix\Landing\Site';
214 }
215 else if ($type == self::ENTITY_TYPE_LANDING)
216 {
217 return '\Bitrix\Landing\Landing';
218 }
219 return '';
220 }
221}
static hasAccessForLanding($landingId, $accessType)
Definition rights.php:578
static hasAccessForSite($siteId, $accessType, $deleted=false)
Definition rights.php:544
static get($id, $type)
static resolveClassByType($type)
static set($id, $type, array $data=array())
static setForLanding($id, array $data=array())
static setForSite($id, array $data=array())