22 foreach ($item as $key => $value)
24 $key = mb_strtoupper($key);
25 if (isset($filter[$key]))
27 $value = (array)$value;
28 $filter[$key] = (array)$filter[$key];
29 if (!array_intersect($value, $filter[$key]))
47 protected static function getFilesList($type, $page =
false, array $filter = [])
51 if (!is_string($type))
56 $componentName =
'bitrix:landing.demo';
57 $className = \CBitrixComponent::includeComponentClass($componentName);
58 $demoCmp =
new $className;
59 $demoCmp->initComponent($componentName);
60 $demoCmp->arParams = [
61 'TYPE' => mb_strtoupper($type),
67 $data = $demoCmp->getDemoPage();
71 $data = $demoCmp->getDemoSite();
76 foreach ($data as $key => &$item)
80 !self::isItemSuitable($item, $filter)
86 if (isset($item[
'DATA'][
'items']))
89 $item[
'DATA'][
'encoded'] =
true;
90 $item[
'DATA'][
'charset'] =
'UTF-8';
91 $item[
'DATA'][
'items'] = \Bitrix\Main\Text\Encoding::convertEncoding(
92 $item[
'DATA'][
'items'],
101 $result->setResult($data);
140 if (!is_string($code) || !is_string($type))
145 $componentName =
'bitrix:landing.demo';
146 $className = \CBitrixComponent::includeComponentClass($componentName);
147 $demoCmp =
new $className;
148 $demoCmp->initComponent($componentName);
149 $demoCmp->arParams = array(
150 'TYPE' => mb_strtoupper($type)
153 $result->setResult($demoCmp->getUrlPreview($code));
165 public static function register(array $data = array(), array $params = array())
168 $error = new \Bitrix\Landing\Error;
170 $themeCodeTypo =
null;
174 isset($data[
'items'])
177 if (is_array($data[
'items']))
179 $dataPages = $data[
'items'];
183 $dataPages = array();
185 unset($data[
'items']);
187 if (isset($data[
'fields'][
'ADDITIONAL_FIELDS'][
'THEME_CODE']))
189 $themeCode = $data[
'fields'][
'ADDITIONAL_FIELDS'][
'THEME_CODE'];
191 if (isset($data[
'fields'][
'ADDITIONAL_FIELDS'][
'THEME_CODE_TYPO']))
193 $themeCodeTypo = $data[
'fields'][
'ADDITIONAL_FIELDS'][
'THEME_CODE_TYPO'];
195 foreach ($dataPages as &$page)
198 !isset($page[
'fields']) ||
199 !is_array($page[
'fields'])
202 $page[
'fields'] = array();
205 !isset($page[
'fields'][
'ADDITIONAL_FIELDS']) ||
206 !is_array($page[
'fields'][
'ADDITIONAL_FIELDS'])
209 $page[
'fields'][
'ADDITIONAL_FIELDS'] = array();
211 if (!isset($page[
'fields'][
'ADDITIONAL_FIELDS'][
'THEME_CODE']))
213 $page[
'fields'][
'ADDITIONAL_FIELDS'][
'THEME_CODE'] = $themeCode;
215 if (!isset($page[
'fields'][
'ADDITIONAL_FIELDS'][
'THEME_CODE_TYPO']))
217 $page[
'fields'][
'ADDITIONAL_FIELDS'][
'THEME_CODE_TYPO'] = $themeCodeTypo;
222 $data[
'items'] = array_keys($dataPages);
224 $data = array_merge([$data], $dataPages);
227 if (empty($data) || !is_array($data))
230 'REGISTER_ERROR_DATA',
233 $result->setError($error);
238 if (($app = \
Bitrix\
Landing\PublicAction::restApplication()))
240 $appCode = $app[
'CODE'];
247 $deleteAdded =
function(array $added)
249 foreach ($added as $id)
251 DemoCore::delete($id);
256 $success = $return = array();
258 'TYPE',
'TPL_TYPE',
'SHOW_IN_LIST',
'TITLE',
'DESCRIPTION',
259 'PREVIEW_URL',
'PREVIEW',
'PREVIEW2X',
'PREVIEW3X'
261 foreach ($data as $item)
266 'APP_CODE' => $appCode,
270 if (isset($params[
'site_template_id']))
272 $fields[
'SITE_TEMPLATE_ID'] = $params[
'site_template_id'];
276 $fields[
'SITE_TEMPLATE_ID'] =
'';
278 if (isset($item[
'code']))
280 $fields[
'XML_ID'] = trim($item[
'code']);
282 if (isset($item[
'name']))
284 $fields[
'TITLE'] = $item[
'name'];
286 if (isset($params[
'lang']))
288 $fields[
'LANG'][
'lang'] = $params[
'lang'];
290 if (isset($params[
'lang_original']))
292 $fields[
'LANG'][
'lang_original'] = $params[
'lang_original'];
294 if (isset($item[
'items']) && !is_array($item[
'items']))
298 foreach ($fieldCode as $code)
300 $codel = mb_strtolower($code);
301 if (isset($item[$codel]))
303 $fields[$code] = $item[$codel];
307 $item = (array) $item;
308 $fields[
'LANG'] = (array) $fields[
'LANG'];
309 $fields[
'MANIFEST'] = serialize($item);
312 $fields[
'LANG'] = serialize($fields[
'LANG']);
316 unset($fields[
'LANG']);
318 if (isset($item[
'fields'][
'ADDITIONAL_FIELDS']))
320 unset($item[
'fields'][
'ADDITIONAL_FIELDS']);
322 \Bitrix\Landing\Manager::sanitize(
331 ' [code: ' . $fields[
'XML_ID'] .
']'
333 $result->setError($error);
334 $deleteAdded($success);
339 if ($fields[
'XML_ID'])
341 $check = DemoCore::getList(array(
346 isset($fields[
'APP_CODE'])
348 '=XML_ID' => $fields[
'XML_ID'],
349 '=APP_CODE' => $fields[
'APP_CODE'],
350 '=TPL_TYPE' => $fields[
'TPL_TYPE']
353 '=XML_ID' => $fields[
'XML_ID'],
354 '=TPL_TYPE' => $fields[
'TPL_TYPE']
362 $res = DemoCore::update($check[
'ID'], $fields);
366 $res = DemoCore::add($fields);
367 if ($res->isSuccess())
369 $success[] = $res->getId();
372 if ($res->isSuccess())
374 $return[] = (int)$res->getId();
378 $error->addFromResult($res);
379 $result->setError($error);
380 $deleteAdded($success);
385 $result->setResult($return);
398 $error = new \Bitrix\Landing\Error;
400 $result->setResult(
false);
402 if (!is_string($code))
411 $app = \Bitrix\Landing\PublicAction::restApplication();
413 $res = DemoCore::getList(array(
421 '=APP_CODE' => $app[
'CODE']
427 while ($row = $res->fetch())
430 $resDel = DemoCore::delete($row[
'ID']);
431 if ($resDel->isSuccess())
433 $result->setResult(
true);
437 $error->addFromResult($resDel);
438 $result->setError($error);
452 public static function getList(array $params = array())
455 $params = $result->sanitizeKeys($params);
457 if (!is_array($params))
462 !isset($params[
'filter']) ||
463 !is_array($params[
'filter'])
466 $params[
'filter'] = array();
470 if (($app = \
Bitrix\
Landing\PublicAction::restApplication()))
472 $params[
'filter'][
'=APP_CODE'] = $app[
'CODE'];
476 $res = DemoCore::getList($params);
477 while ($row = $res->fetch())
479 if (isset($row[
'DATE_CREATE']))
481 $row[
'DATE_CREATE'] = (string) $row[
'DATE_CREATE'];
483 if (isset($row[
'DATE_MODIFY']))
485 $row[
'DATE_MODIFY'] = (string) $row[
'DATE_MODIFY'];
487 $row[
'MANIFEST'] = unserialize($row[
'MANIFEST'], [
'allowed_classes' =>
false]);
490 $row[
'LANG'] = unserialize($row[
'LANG'], [
'allowed_classes' =>
false]);
494 $result->setResult($data);