1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
templateref.php
См. документацию.
1<?php
2namespace Bitrix\Landing;
3
4use \Bitrix\Landing\Internals\TemplateRefTable;
5
7{
11 const ENTITY_TYPE_SITE = 'S';
12
17
18 private const CACHE_DIR = '/landing/is_area/';
19
27 protected static function set($id, $type, array $data = array())
28 {
29 $id = intval($id);
30 $res = TemplateRefTable::getList(array(
31 'select' => array(
32 'ID', 'AREA', 'LANDING_ID'
33 ),
34 'filter' => array(
35 'ENTITY_ID' => $id,
36 '=ENTITY_TYPE' => $type
37 )
38 ));
39 while (($row = $res->fetch()))
40 {
41 if (isset($data[$row['AREA']]) && $data[$row['AREA']] > 0)
42 {
43 if ($row['LANDING_ID'] != $data[$row['AREA']])
44 {
45 TemplateRefTable::update($row['ID'], array(
46 'LANDING_ID' => $data[$row['AREA']]
47 ));
48 BXClearCache(true, self::CACHE_DIR);
49 }
50 unset($data[$row['AREA']]);
51 }
52 else
53 {
54 TemplateRefTable::delete($row['ID']);
55 BXClearCache(true, self::CACHE_DIR);
56 }
57 }
58 foreach ($data as $area => $lid)
59 {
60 if ($lid > 0)
61 {
62 TemplateRefTable::add(array(
63 'ENTITY_ID' => $id,
64 'ENTITY_TYPE' => $type,
65 'LANDING_ID' => $lid,
66 'AREA' => $area
67 ));
68 BXClearCache(true, self::CACHE_DIR);
69 }
70 }
71 }
72
79 protected static function get($id, $type)
80 {
81 static $staticData = array();
82 $id = intval($id);
83
84 if (!isset($staticData[$type . $id]))
85 {
86 $data = array();
87 if ($id > 0)
88 {
89 $res = TemplateRefTable::getList(array(
90 'select' => array(
91 'AREA', 'LANDING_ID'
92 ),
93 'filter' => array(
94 'ENTITY_ID' => $id,
95 '=ENTITY_TYPE' => $type
96 )
97 ));
98 while (($row = $res->fetch()))
99 {
100 $data[$row['AREA']] = $row['LANDING_ID'];
101 }
102 }
103
104 $staticData[$type . $id] = $data;
105 }
106
107 return $staticData[$type . $id];
108 }
109
116 public static function setForSite($id, array $data = array())
117 {
119 {
120 self::set($id, self::ENTITY_TYPE_SITE, $data);
121 }
122 }
123
130 public static function setForLanding($id, array $data = array())
131 {
133 {
134 self::set($id, self::ENTITY_TYPE_LANDING, $data);
135 }
136 }
137
143 public static function getForSite($id)
144 {
145 return self::get($id, self::ENTITY_TYPE_SITE);
146 }
147
153 public static function getForLanding($id)
154 {
155 return self::get($id, self::ENTITY_TYPE_LANDING);
156 }
157
165 public static function landingIsArea(int|array $lid): bool|array
166 {
167 $cache = new \CPHPCache();
168 $cacheTime = 3600;
169 $cacheId = is_array($lid) ? md5(serialize($lid)) : (int)$lid;
170
171 if ($cache->InitCache($cacheTime, $cacheId, self::CACHE_DIR))
172 {
173 $result = $cache->GetVars();
174 }
175 else
176 {
177 $cache->StartDataCache();
178
179 $res = TemplateRefTable::getList([
180 'filter' => [
181 'LANDING_ID' => $lid,
182 ],
183 ]);
184
185 if (is_array($lid))
186 {
187 $result = [];
188 foreach ($lid as $id)
189 {
190 $result[(int)$id] = false;
191 }
192 while ($row = $res->fetch())
193 {
194 $result[$row['LANDING_ID']] = true;
195 }
196 }
197 else
198 {
199 $result = (bool)$res->fetch();
200 }
201
202 $cache->EndDataCache($result);
203 }
204
205 return $result;
206 }
207
213 public static function deleteArea($lid)
214 {
215 $lid = intval($lid);
216
217 $res = TemplateRefTable::getList(array(
218 'filter' => array(
219 'LANDING_ID' => $lid
220 )
221 ));
222 while ($row = $res->fetch())
223 {
224 TemplateRefTable::delete($row['ID']);
225 BXClearCache(true, self::CACHE_DIR);
226 }
227 }
228
234 public static function resolveClassByType($type)
235 {
236 if ($type == self::ENTITY_TYPE_SITE)
237 {
238 return '\Bitrix\Landing\Site';
239 }
240 else if ($type == self::ENTITY_TYPE_LANDING)
241 {
242 return '\Bitrix\Landing\Landing';
243 }
244 return '';
245 }
246}
$type
Определения options.php:106
static hasAccessForLanding($landingId, $accessType)
Определения rights.php:580
const ACCESS_TYPES
Определения rights.php:21
static hasAccessForSite($siteId, $accessType, $deleted=false)
Определения rights.php:546
static get($id, $type)
Определения templateref.php:79
static getForLanding($id)
Определения templateref.php:153
static landingIsArea(int|array $lid)
Определения templateref.php:165
static resolveClassByType($type)
Определения templateref.php:234
const ENTITY_TYPE_SITE
Определения templateref.php:11
static set($id, $type, array $data=array())
Определения templateref.php:27
static getForSite($id)
Определения templateref.php:143
static deleteArea($lid)
Определения templateref.php:213
const ENTITY_TYPE_LANDING
Определения templateref.php:16
static setForLanding($id, array $data=array())
Определения templateref.php:130
static setForSite($id, array $data=array())
Определения templateref.php:116
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
BXClearCache($full=false, $initdir='')
Определения tools.php:5150