1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
manager.php
См. документацию.
1<?php
2namespace Bitrix\MobileApp\Designer;
3
4
5use Bitrix\Main\Application;
6use Bitrix\Main\Entity\FieldError;
7use Bitrix\Main\IO\Directory;
8use Bitrix\Main\IO\File;
9use Bitrix\Main\Text\Encoding;
10
12{
14 const SUCCESS = 1;
15 const FAIL = 0;
16 const EMPTY_REQUIRED = 4;
18 const PREVIEW_IMAGE_SIZE = 150;
19
20 const SIMPLE_APP_TEMPLATE = "simple";
21
33 public static function createApp($appCode = "", $data = array(), $initConfig = array())
34 {
35 $result = self::SUCCESS;
36 $fields = $data;
37 $fields["CODE"] = $appCode;
38 $dbResult = AppTable::add($fields);
39 if (!$dbResult->isSuccess())
40 {
41 $errors = $dbResult->getErrors();
42 if ($errors[0]->getCode() == FieldError::INVALID_VALUE)
43 {
44 $result = self::IS_ALREADY_EXISTS;
45 }
46 elseif ($errors[0]->getCode() == FieldError::EMPTY_REQUIRED)
47 {
48 $result = self::EMPTY_REQUIRED;
49 }
50 }
51 else
52 {
53
54 self::addConfig($appCode, "global", $initConfig);
55 }
56
57 return $result;
58 }
59
60 private static function getTemplateList()
61 {
62 return array(
63 "simple",
64 "api"
65 );
66 }
67
75 public static function removeApp($appCode)
76 {
77 $result = AppTable::delete($appCode);
78 return $result->isSuccess();
79 }
80
87 public static function registerFileInApp(&$fileArray, $appCode)
88 {
89 $result = AppTable::getById($appCode);
90 $appData = $result->fetchAll();
91 if (count($appData) > 0)
92 {
93 if(!is_array($appData[0]["FILES"]))
94 $appData[0]["FILES"] = [];
95 $appData[0]["FILES"][] = $fileArray["fileID"];
96 AppTable::update($appCode, array("FILES" => $appData[0]["FILES"]));
97 $arImage = \CFile::ResizeImageGet(
98 $fileArray["fileID"],
99 array("width" => self::PREVIEW_IMAGE_SIZE, "height" => self::PREVIEW_IMAGE_SIZE),
101 false,
102 false,
103 true
104 );
105 $fileArray["img_source_src"] = $arImage["src"];
106 }
107
108 }
109
116 public static function unregisterFileInApp($fileId, $appCode)
117 {
118 $result = AppTable::getById($appCode);
119 $appData = $result->fetchAll();
120 if (count($appData) > 0)
121 {
122
123 $index = array_search($fileId, $appData[0]["FILES"]);
124 if ($index !== false)
125 {
126 unset($appData[0]["FILES"][$index]);
127 AppTable::update($appCode, array("FILES" => $appData[0]["FILES"]));
128 }
129 die();
130
131 }
132
133 }
134
147 public static function addConfig($appCode = "", $platform, $config = array())
148 {
149 if (ConfigTable::isExists($appCode, $platform))
150 {
151 return false;
152 }
153
154 $fields = array(
155 "APP_CODE" => $appCode,
156 "PLATFORM" => $platform,
157 "PARAMS" => $config
158 );
159
160 $result = ConfigTable::add($fields);
161
162 return $result->isSuccess();
163
164 }
165
175 public static function removeConfig($appCode = "", $platform = array())
176 {
177 $filter = array(
178 "APP_CODE" => $appCode,
179 "PLATFORM" => $platform,
180 );
181
182 $result = ConfigTable::delete($filter);
183
184 return $result->isSuccess();
185
186 }
187
199 public static function updateConfig($appCode = "", $platform = "", $config = array())
200 {
201 if (!ConfigTable::isExists($appCode, $platform))
202 {
203 return false;
204 }
205
206 $map = new ConfigMap();
207 foreach ($config as $paramName => $value)
208 {
209 if (!$map->has($paramName))
210 {
211 unset($config[$paramName]);
212 }
213 }
214
215 $data = array(
216 "PARAMS" => $config
217 );
218
219 $result = ConfigTable::update(array("APP_CODE" => $appCode, "PLATFORM" => $platform), $data);
220
221 return $result->isSuccess();
222
223 }
224
235 public static function getConfigJSON($appCode, $platform = false)
236 {
237 $map = new \Bitrix\MobileApp\Designer\ConfigMap();
238 $res = ConfigTable::getList(array(
239 "filter" => array(
240 "APP_CODE" => $appCode,
241 )
242 ));
243
244 $configs = $res->fetchAll();
245 $targetConfig = array();
246
247 for ($i = 0; $i < count($configs); $i++)
248 {
249 if ($configs[$i]["PLATFORM"] == $platform)
250 {
251 $targetConfig = $configs[$i];
252 break;
253 }
254 elseif ($configs[$i]["PLATFORM"] == "global")
255 {
256 $targetConfig = $configs[$i];
257 }
258 }
259
260 $params = array_key_exists("PARAMS", $targetConfig) ? $targetConfig["PARAMS"]: array() ;
261 $imageParamList = $map->getParamsByType(ParameterType::IMAGE);
262 $imageSetParamList = $map->getParamsByType(ParameterType::IMAGE_SET);
263 $structuredConfig = array();
264
265 foreach ($params as $key => $value)
266 {
267 if (!$map->has($key))
268 {
269 continue;
270 }
271
272 if (array_key_exists($key, $imageParamList))
273 {
274 $imagePath = \CFile::GetPath($value);
275 if($imagePath <> '')
276 $value = $imagePath;
277 else
278 continue;
279 }
280
281 if (array_key_exists($key, $imageSetParamList))
282 {
283 $tmpValue = array();
284 foreach ($value as $imageCode => $imageId)
285 {
286 $imagePath = \CFile::GetPath($imageId);
287 if($imagePath <> '')
288 $tmpValue[$imageCode] = $imagePath;
289 else
290 continue;
291 }
292 $value = $tmpValue;
293 }
294 $structuredConfig = array_merge_recursive(self::nameSpaceToArray($key, $value), $structuredConfig);
295 }
296
297 self::addVirtualParams($structuredConfig, $platform);
298
299 return json_encode($structuredConfig);
300 }
301
313
314 public static function copyFromTemplate($folder, $appCode, $useOffline = false, $templateCode = "simple")
315 {
316 if(!in_array($templateCode, self::getTemplateList()))
317 {
318 $templateCode = "simple";
319 }
320
321 $appFolderPath = Application::getDocumentRoot() . "/" . $folder . "/";
322 $offlineTemplate = Application::getDocumentRoot() . "/bitrix/modules/mobileapp/templates_app/offline/";
323 $templatePath = Application::getDocumentRoot() . "/bitrix/modules/mobileapp/templates_app/".$templateCode."/";
324
325 $directory = new Directory($templatePath);
326 if($directory->isExists())
327 {
328 if (!Directory::isDirectoryExists($appFolderPath))
329 {
330 if($useOffline)
331 {
332 CopyDirFiles($offlineTemplate, $appFolderPath."/offline");
333 }
334
335 $items = $directory->getChildren();
336 foreach ($items as $entry)
337 {
341 $filePath = $entry->getPath();
342 $appFilePath = $appFolderPath . $entry->getName();
343
344 if($entry instanceof Directory)
345 {
346 CopyDirFiles($filePath, $appFolderPath."/".$entry->getName(),true,true);
347 }
348 else
349 {
350 $file = new File($entry->getPath());
351 File::putFileContents(
352 $appFilePath,
353 str_replace(Array("#folder#", "#code#"), Array($folder, $appCode),$file->getContents())
354 );
355 }
356 }
357 }
358 }
359 }
360
368 public static function bindTemplate($templateId, $folder, $createNew)
369 {
370 $arFields = Array("TEMPLATE" => Array());
371 if ($createNew)
372 {
374 Application::getDocumentRoot() . "/bitrix/modules/mobileapp/templates/default_app/",
375 Application::getDocumentRoot() . "/bitrix/templates/" . $templateId, True, True
376 );
377
378 File::putFileContents(
379 Application::getDocumentRoot() . "/bitrix/templates/" . $templateId . "/description.php",
380 str_replace(Array("#mobile_template_name#"), Array($templateId), File::getFileContents(Application::getDocumentRoot() . "/bitrix/templates/" . $templateId . "/description.php"))
381 );
382
383 $arFields["TEMPLATE"][] = Array(
384 "SORT" => 1,
385 "CONDITION" => "CSite::InDir('/" . $folder . "/')",
386 "TEMPLATE" => $templateId
387 );
388 }
389
390 $default_site_id = \CSite::GetDefSite();
391 if ($default_site_id)
392 {
393 $dbTemplates = \CSite::GetTemplateList($default_site_id);
394 $arFields["LID"] = $default_site_id;
395 $isTemplateFound = false;
396 while ($template = $dbTemplates->Fetch())
397 {
398 $arFields["TEMPLATE"][] = array(
399 "TEMPLATE" => $template['TEMPLATE'],
400 "SORT" => $template['SORT'],
401 "CONDITION" => $template['CONDITION']
402 );
403
404 if ($template["TEMPLATE"] == $templateId && !$createNew && !$isTemplateFound)
405 {
406 $isTemplateFound = true;
407
408 $arFields["TEMPLATE"][] = Array(
409 "SORT" => 1,
410 "CONDITION" => "CSite::InDir('/" . $folder . "/')",
411 "TEMPLATE" => $templateId
412 );
413 }
414 }
415
416 $obSite = new \CSite;
417 $obSite->Update($default_site_id, $arFields);
418 }
419 }
420
426 public static function getAppFiles($appCode)
427 {
428 $result = AppTable::getById($appCode);
429 $appData = $result->fetchAll();
430 $files = [];
431 if (count($appData) > 0 && is_array($appData[0]['FILES']))
432 {
433 //TODO fix, use module_id in the filter
434 $result = \CFile::GetList(['ID' => 'desc'], ['@ID' => implode(',', $appData[0]['FILES'])]);
435 while ($file = $result->Fetch())
436 {
437 $image = \CFile::ResizeImageGet(
438 $file['ID'],
439 ['width' => self::PREVIEW_IMAGE_SIZE, 'height' => self::PREVIEW_IMAGE_SIZE],
441 false,
442 false,
443 true
444 );
445 $files['file_' . $file['ID']] = [
446 'id' => $file['ID'],
447 'src' => \CFile::GetFileSRC($file),
448 'preview' => $image['src']
449 ];
450 }
451 }
452
453 return $files;
454 }
455
484 private static function nameSpaceToArray($namespace, $value)
485 {
486 $keys = explode("/", $namespace);
487 $result = array();
488 $temp = & $result;
489 for ($i = 0; $i < count($keys); $i++)
490 {
491 $temp = & $temp[$keys[$i]];
492 }
493
494 $temp = $value;
495
496 return $result;
497
498 }
499
500 private static function addVirtualParams(&$structuredConfig, $platform)
501 {
502 if($structuredConfig["offline"] && !empty($structuredConfig["offline"]["file_list"]))
503 {
504 $offlineParams = &$structuredConfig["offline"];
505 $offlineParams["file_list"]["bitrix_mobile_core.js"] = Tools::getMobileJSCorePath();
506 $changeMark = Tools::getArrayFilesHash($offlineParams["file_list"]);
507 $offlineParams["change_mark"] = $changeMark;
508 }
509
510 if($structuredConfig["buttons"]["badge"])
511 {
512 $structuredConfig["buttons_badge"] = $structuredConfig["buttons"]["badge"];
513 unset($structuredConfig["buttons"]["badge"]);
514 }
515
516 $structuredConfig["info"] = array(
517 "designer_version"=> ConfigMap::VERSION,
518 "platform"=>$platform
519 );
520 }
521
522
523}
524
525
526
527
528
static isExists($appCode, $platform)
Определения config.php:141
const SIMPLE_APP_TEMPLATE
Определения manager.php:20
const IS_ALREADY_EXISTS
Определения manager.php:13
static createApp($appCode="", $data=array(), $initConfig=array())
Определения manager.php:33
static removeApp($appCode)
Определения manager.php:75
static getConfigJSON($appCode, $platform=false)
Определения manager.php:235
static registerFileInApp(&$fileArray, $appCode)
Определения manager.php:87
static bindTemplate($templateId, $folder, $createNew)
Определения manager.php:368
static getAppFiles($appCode)
Определения manager.php:426
static removeConfig($appCode="", $platform=array())
Определения manager.php:175
static unregisterFileInApp($fileId, $appCode)
Определения manager.php:116
const EMPTY_REQUIRED
Определения manager.php:16
static updateConfig($appCode="", $platform="", $config=array())
Определения manager.php:199
static addConfig($appCode="", $platform, $config=array())
Определения manager.php:147
const PREVIEW_IMAGE_SIZE
Определения manager.php:18
const APP_TEMPLATE_IS_NOT_EXISTS
Определения manager.php:17
static getMobileJSCorePath()
Определения tools.php:13
static getArrayFilesHash($fileList=array())
Определения tools.php:61
$templateId
Определения component_props2.php:51
$arFields
Определения dblapprove.php:5
$data['IS_AVAILABLE']
Определения .description.php:13
$template
Определения file_edit.php:49
</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
$errors
Определения iblock_catalog_edit.php:74
$filter
Определения iblock_catalog_list.php:54
const BX_RESIZE_IMAGE_EXACT
Определения constants.php:12
CopyDirFiles($path_from, $path_to, $ReWrite=true, $Recursive=false, $bDeleteAfterCopy=false, $strExclude="")
Определения tools.php:2732
$map
Определения config.php:5
$platform
Определения settings.php:7
$files
Определения mysql_to_pgsql.php:30
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$config
Определения quickway.php:69
if(empty($signedUserToken)) $key
Определения quickway.php:257
die
Определения quickway.php:367
$i
Определения factura.php:643
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$items
Определения template.php:224
$dbResult
Определения updtr957.php:3
$fields
Определения yandex_run.php:501