1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
repo.php
См. документацию.
1<?php
2namespace Bitrix\Landing;
3
4use Bitrix\Landing\Block\BlockRepo;
5use Bitrix\Landing\Site\Type;
6use \Bitrix\Rest\AppTable;
7
9{
14 public static $internalClass = 'RepoTable';
15
21 public static function add($fields)
22 {
23 $res = parent::add($fields);
24
25 if ($res->isSuccess())
26 {
27 Block::clearRepositoryCache();
28 }
29
30 return $res;
31 }
32
39 public static function update($id, $fields = array())
40 {
41 $res = parent::update($id, $fields);
42
43 if ($res->isSuccess())
44 {
45 Block::clearRepositoryCache();
46 }
47
48 return $res;
49 }
50
56 public static function delete($id)
57 {
58 $res = parent::delete($id);
59
60 if ($res->isSuccess())
61 {
62 Block::clearRepositoryCache();
63 }
64
65 return $res;
66 }
67
72 public static function getRepository()
73 {
74 $items = [];
76 $siteTemplateId = Manager::getTemplateId($siteId);
77 $langPortal = LANGUAGE_ID;
78 if (in_array($langPortal, ['ru', 'kz', 'by', 'uz']))
79 {
80 $langPortal = 'ru';
81 }
82
84 'select' => array(
85 'ID', 'NAME', 'DATE_CREATE', 'DESCRIPTION',
86 'SECTIONS', 'PREVIEW', 'APP_CODE', 'MANIFEST',
88 'DATE_CREATE_TIMESTAMP',
89 'UNIX_TIMESTAMP(DATE_CREATE)'
90 )
91 ),
92 'filter' => array(
93 '=ACTIVE' => 'Y',
94 Manager::isTemplateIdSystem($siteTemplateId)
95 ? array(
96 'LOGIC' => 'OR',
97 ['=SITE_TEMPLATE_ID' => $siteTemplateId],
98 ['=SITE_TEMPLATE_ID' => false]
99 )
100 : array(
101 ['=SITE_TEMPLATE_ID' => $siteTemplateId]
102 )
103 ),
104 'order' => array(
105 'ID' => 'DESC'
106 )
107 ));
108 while ($row = $res->fetch())
109 {
110 $manifest = unserialize($row['MANIFEST'], ['allowed_classes' => false]);
111 if (isset($manifest['lang'][$langPortal][$row['NAME']]))
112 {
113 $row['NAME'] = $manifest['lang'][$langPortal][$row['NAME']];
114 }
115 else if (
116 isset($manifest['lang_original']) &&
117 $manifest['lang_original'] != $langPortal &&
118 $manifest['lang']['en'][$row['NAME']]
119 )
120 {
121 $row['NAME'] = $manifest['lang']['en'][$row['NAME']];
122 }
123
124 $blockManifest = [
125 'id' => null,
126 'new' => (time() - $row['DATE_CREATE_TIMESTAMP']) < BlockRepo::NEW_BLOCK_LT,
127 'name' => $row['NAME'],
128 'description' => $row['DESCRIPTION'],
129 'namespace' => $row['APP_CODE'],
130 'type' => (array)($manifest['block']['type'] ?? []),
131 'section' => explode(',', $row['SECTIONS']),
132 'preview' => $row['PREVIEW'],
133 'restricted' => true,
134 'repo_id' => $row['ID'],
135 'app_code' => $row['APP_CODE'],
136 ];
137
138 $blockManifest = Type::prepareBlockManifest(['block' => $blockManifest]);
139 $items['repo_'. $row['ID']] = $blockManifest['block'];
140 }
141
142 return $items;
143 }
144
150 public static function getBlock($id)
151 {
152 static $manifest = array();
153
154 if (!isset($manifest[$id]))
155 {
156 $manifest[$id] = array();
157 if (($block = self::getById($id)->fetch()))
158 {
159 $manifestLocal = unserialize($block['MANIFEST'], ['allowed_classes' => false]);
160 if (!is_array($manifestLocal))
161 {
162 $manifestLocal = array();
163 }
164 if (
165 isset($manifestLocal['block']) &&
166 is_array($manifestLocal['block'])
167 )
168 {
169 $blockDesc = $manifestLocal['block'];
170 }
171 $manifestLocal['block'] = array(
172 'name' => $block['NAME'],
173 'description' => $block['DESCRIPTION'],
174 'namespace' => $block['APP_CODE'],
175 'type' => (array)($blockDesc['type'] ?? []),
176 'section' => explode(',', $block['SECTIONS']),
177 'preview' => $block['PREVIEW'],
178 'restricted' => true,
179 'repo_id' => $block['ID'],
180 'xml_id' => $block['XML_ID'],
181 'app_code' => $block['APP_CODE'],
182 );
183 if (isset($blockDesc['subtype']))
184 {
185 $manifestLocal['block']['subtype'] = $blockDesc['subtype'];
186 $manifestLocal['block']['subtype_params'] = $blockDesc['subtype_params'] ?? [];
187 }
188
189 $manifest[$id] = Type::prepareBlockManifest($manifestLocal);
190 $manifest[$id]['timestamp'] = $block['DATE_MODIFY']->getTimeStamp();
191 }
192 }
193
194 return $manifest[$id];
195 }
196
202 public static function getById($id)
203 {
204 return parent::getList(array(
205 'filter' => array(
206 'ID' => $id
207 )
208 ));
209 }
210
216 public static function deleteByAppCode($code)
217 {
218 $codeToDelete = array();
219 // delete blocks from repo
221 'select' => array(
222 'ID'
223 ),
224 'filter' => array(
225 '=APP_CODE' => $code
226 )
227 ));
228 while ($row = $res->fetch())
229 {
230 self::delete($row['ID']);
231 $codeToDelete[] = 'repo_' . $row['ID'];
232 }
233 // delete added blocks
234 if (!empty($codeToDelete))
235 {
236 Block::deleteByCode($codeToDelete);
237 }
238 }
239
245 public static function getAppInfo(array|int $id): ?array
246 {
247 $isArray = is_array($id);
248 if (!$isArray)
249 {
250 $id = array($id);
251 }
252 $id = array_fill_keys($id, false);
253
254 if ($id)
255 {
256 // get app codes from repo first
258 'select' => array(
259 'ID', 'APP_CODE'
260 ),
261 'filter' => array(
262 'ID' => array_keys($id)
263 )
264 ));
265 while ($row = $res->fetch())
266 {
267 if ($row['APP_CODE'])
268 {
269 $id[$row['ID']] = $row['APP_CODE'];
270 }
271 }
272 // get info about apps
273 $apps = self::getAppByCode($id);
274 // fill result array
275 foreach ($id as &$code)
276 {
277 if ($code && isset($apps[$code]))
278 {
279 $code = $apps[$code];
280 }
281 else
282 {
283 $code = array();
284 }
285 }
286 unset($code);
287 }
288
289 if ($id)
290 {
291 return $isArray ? $id : array_pop($id);
292 }
293
294 return $apps ?? null;
295 }
296
302 public static function getAppByCode($code)
303 {
304 $apps = array();
305
306 if ($code && \Bitrix\Main\Loader::includeModule('rest'))
307 {
308 $res = AppTable::getList(array(
309 'filter' => array(
310 '=CODE' => $code
311 )
312 ));
313 while ($row = $res->fetch())
314 {
315 $row['APP_STATUS'] = AppTable::getAppStatusInfo($row, '');
316 $apps[$row['CODE']] = array(
317 'ID' => $row['ID'],
318 'CODE' => $row['CODE'],
319 'APP_NAME' => $row['APP_NAME'],
320 'CLIENT_ID' => $row['CLIENT_ID'],
321 'VERSION' => $row['VERSION'],
322 'DATE_FINISH' => $row['DATE_FINISH'],
323 'PAYMENT_ALLOW' => $row['APP_STATUS']['PAYMENT_ALLOW']
324 );
325 }
326 }
327
328 if ($apps)
329 {
330 return is_array($code) ? $apps : array_pop($apps);
331 }
332
333 return $apps;
334 }
335}
static getMainSiteId()
Определения manager.php:546
static isTemplateIdSystem($templateId)
Определения manager.php:537
static getTemplateId($siteId=null)
Определения manager.php:513
static getList(array $params=array())
Определения repo.php:625
static deleteByAppCode($code)
Определения repo.php:216
static update($id, $fields=array())
Определения repo.php:39
static $internalClass
Определения repo.php:14
static getAppByCode($code)
Определения repo.php:302
static getRepository()
Определения repo.php:72
static getById($id)
Определения repo.php:202
static add($fields)
Определения repo.php:21
static getAppInfo(array|int $id)
Определения repo.php:245
static getBlock($id)
Определения repo.php:150
</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
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$siteId
Определения ajax.php:8
Определения ufield.php:9
$items
Определения template.php:224
$fields
Определения yandex_run.php:501