Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
repo.php
1<?php
2namespace Bitrix\Landing;
3
4use \Bitrix\Rest\AppTable;
5
7{
12 public static $internalClass = 'RepoTable';
13
19 public static function add($fields)
20 {
21 $res = parent::add($fields);
22
23 if ($res->isSuccess())
24 {
25 Block::clearRepositoryCache();
26 }
27
28 return $res;
29 }
30
37 public static function update($id, $fields = array())
38 {
39 $res = parent::update($id, $fields);
40
41 if ($res->isSuccess())
42 {
43 Block::clearRepositoryCache();
44 }
45
46 return $res;
47 }
48
54 public static function delete($id)
55 {
56 $res = parent::delete($id);
57
58 if ($res->isSuccess())
59 {
60 Block::clearRepositoryCache();
61 }
62
63 return $res;
64 }
65
70 public static function getRepository()
71 {
72 $items = array();
73 $siteId = Manager::getMainSiteId();
74 $siteTemplateId = Manager::getTemplateId($siteId);
75 $langPortal = LANGUAGE_ID;
76 if (in_array($langPortal, ['ru', 'kz', 'by']))
77 {
78 $langPortal = 'ru';
79 }
80
81 $res = self::getList(array(
82 'select' => array(
83 'ID', 'NAME', 'DATE_CREATE', 'DESCRIPTION',
84 'SECTIONS', 'PREVIEW', 'APP_CODE', 'MANIFEST',
86 'DATE_CREATE_TIMESTAMP',
87 'UNIX_TIMESTAMP(DATE_CREATE)'
88 )
89 ),
90 'filter' => array(
91 '=ACTIVE' => 'Y',
92 Manager::isTemplateIdSystem($siteTemplateId)
93 ? array(
94 'LOGIC' => 'OR',
95 ['=SITE_TEMPLATE_ID' => $siteTemplateId],
96 ['=SITE_TEMPLATE_ID' => false]
97 )
98 : array(
99 ['=SITE_TEMPLATE_ID' => $siteTemplateId]
100 )
101 ),
102 'order' => array(
103 'ID' => 'DESC'
104 )
105 ));
106 while ($row = $res->fetch())
107 {
108 $manifest = unserialize($row['MANIFEST'], ['allowed_classes' => false]);
109 if (isset($manifest['lang'][$langPortal][$row['NAME']]))
110 {
111 $row['NAME'] = $manifest['lang'][$langPortal][$row['NAME']];
112 }
113 else if (
114 isset($manifest['lang_original']) &&
115 $manifest['lang_original'] != $langPortal &&
116 $manifest['lang']['en'][$row['NAME']]
117 )
118 {
119 $row['NAME'] = $manifest['lang']['en'][$row['NAME']];
120 }
121
122 $items['repo_'. $row['ID']] = array(
123 'id' => null,
124 'name' => $row['NAME'],
125 'namespace' => $row['APP_CODE'],
126 'new' => (time() - $row['DATE_CREATE_TIMESTAMP']) < Block::NEW_BLOCK_LT,
127 'section' => explode(',', $row['SECTIONS']),
128 'description' => $row['DESCRIPTION'],
129 'preview' => $row['PREVIEW'],
130 'restricted' => true,
131 'repo_id' => $row['ID'],
132 'app_code' => $row['APP_CODE']
133 );
134 }
135
136 return $items;
137 }
138
144 public static function getBlock($id)
145 {
146 static $manifest = array();
147
148 if (!isset($manifest[$id]))
149 {
150 $manifest[$id] = array();
151 if (($block = self::getById($id)->fetch()))
152 {
153 $manifestLocal = unserialize($block['MANIFEST'], ['allowed_classes' => false]);
154 if (!is_array($manifestLocal))
155 {
156 $manifestLocal = array();
157 }
158 if (
159 isset($manifestLocal['block']) &&
160 is_array($manifestLocal['block'])
161 )
162 {
163 $blockDesc = $manifestLocal['block'];
164 }
165 $manifestLocal['block'] = array(
166 'name' => $block['NAME'],
167 'description' => $block['DESCRIPTION'],
168 'namespace' => $block['APP_CODE'],
169 'section' => explode(',', $block['SECTIONS']),
170 'preview' => $block['PREVIEW'],
171 'restricted' => true,
172 'repo_id' => $block['ID'],
173 'xml_id' => $block['XML_ID'],
174 'app_code' => $block['APP_CODE']
175 );
176 if (isset($blockDesc['subtype']))
177 {
178 $manifestLocal['block']['subtype'] = $blockDesc['subtype'];
179 }
180 $manifest[$id] = $manifestLocal;
181 $manifest[$id]['timestamp'] = $block['DATE_MODIFY']->getTimeStamp();
182 }
183 }
184
185 return $manifest[$id];
186 }
187
193 public static function getById($id)
194 {
195 return parent::getList(array(
196 'filter' => array(
197 'ID' => $id
198 )
199 ));
200 }
201
207 public static function deleteByAppCode($code)
208 {
209 $codeToDelete = array();
210 // delete blocks from repo
211 $res = self::getList(array(
212 'select' => array(
213 'ID'
214 ),
215 'filter' => array(
216 '=APP_CODE' => $code
217 )
218 ));
219 while ($row = $res->fetch())
220 {
221 self::delete($row['ID']);
222 $codeToDelete[] = 'repo_' . $row['ID'];
223 }
224 // delete added blocks
225 if (!empty($codeToDelete))
226 {
227 Block::deleteByCode($codeToDelete);
228 }
229 }
230
236 public static function getAppInfo($id)
237 {
238 $isArray = is_array($id);
239 if (!$isArray)
240 {
241 $id = array($id);
242 }
243 $id = array_fill_keys($id, false);
244
245 if ($id)
246 {
247 // get app codes from repo first
248 $res = self::getList(array(
249 'select' => array(
250 'ID', 'APP_CODE'
251 ),
252 'filter' => array(
253 'ID' => array_keys($id)
254 )
255 ));
256 while ($row = $res->fetch())
257 {
258 if ($row['APP_CODE'])
259 {
260 $id[$row['ID']] = $row['APP_CODE'];
261 }
262 }
263 // get info about apps
264 $apps = self::getAppByCode($id);
265 // fill result array
266 foreach ($id as &$code)
267 {
268 if ($code && isset($apps[$code]))
269 {
270 $code = $apps[$code];
271 }
272 else
273 {
274 $code = array();
275 }
276 }
277 unset($code);
278 }
279
280 if ($id)
281 {
282 return $isArray ? $id : array_pop($id);
283 }
284
285 return $apps;
286 }
287
293 public static function getAppByCode($code)
294 {
295 $apps = array();
296
297 if ($code && \Bitrix\Main\Loader::includeModule('rest'))
298 {
299 $res = AppTable::getList(array(
300 'filter' => array(
301 '=CODE' => $code
302 )
303 ));
304 while ($row = $res->fetch())
305 {
306 $row['APP_STATUS'] = AppTable::getAppStatusInfo($row, '');
307 $apps[$row['CODE']] = array(
308 'CODE' => $row['CODE'],
309 'APP_NAME' => $row['APP_NAME'],
310 'VERSION' => $row['VERSION'],
311 'DATE_FINISH' => $row['DATE_FINISH'],
312 'PAYMENT_ALLOW' => $row['APP_STATUS']['PAYMENT_ALLOW']
313 );
314 }
315 }
316
317 if ($apps)
318 {
319 return is_array($code) ? $apps : array_pop($apps);
320 }
321
322 return $apps;
323 }
324}
static isTemplateIdSystem($templateId)
Definition manager.php:532
static getTemplateId($siteId=null)
Definition manager.php:508
static getList(array $params=array())
Definition repo.php:533
static deleteByAppCode($code)
Definition repo.php:207
static update($id, $fields=array())
Definition repo.php:37
static $internalClass
Definition repo.php:12
static getAppByCode($code)
Definition repo.php:293
static getRepository()
Definition repo.php:70
static getById($id)
Definition repo.php:193
static add($fields)
Definition repo.php:19
static getBlock($id)
Definition repo.php:144
static getAppInfo($id)
Definition repo.php:236