Exemplo n.º 1
0
 /**
  * Return configuration in JSON format
  *
  * @param $appCode - application code
  * @param bool $platform - platform code
  *
  * @see ConfigTable::getSupportedPlatforms for details on availible platforms
  * @return string
  * @throws \Bitrix\Main\ArgumentException
  */
 public static function getConfigJSON($appCode, $platform = false)
 {
     $map = new \Bitrix\MobileApp\Designer\ConfigMap();
     $res = ConfigTable::getList(array("filter" => array("APP_CODE" => $appCode)));
     $configs = $res->fetchAll();
     $targetConfig = array();
     for ($i = 0; $i < count($configs); $i++) {
         if ($configs[$i]["PLATFORM"] == $platform) {
             $targetConfig = $configs[$i];
             break;
         } elseif ($configs[$i]["PLATFORM"] == "global") {
             $targetConfig = $configs[$i];
         }
     }
     $params = array_key_exists("PARAMS", $targetConfig) ? $targetConfig["PARAMS"] : array();
     $imageParamList = $map->getParamsByType(ParameterType::IMAGE);
     $imageSetParamList = $map->getParamsByType(ParameterType::IMAGE_SET);
     $structuredConfig = array();
     foreach ($params as $key => $value) {
         if (!$map->has($key)) {
             continue;
         }
         if (array_key_exists($key, $imageParamList)) {
             $imagePath = \CFile::GetPath($value);
             if (strlen($imagePath) > 0) {
                 $value = $imagePath;
             } else {
                 continue;
             }
         }
         if (array_key_exists($key, $imageSetParamList)) {
             $tmpValue = array();
             foreach ($value as $imageCode => $imageId) {
                 $imagePath = \CFile::GetPath($imageId);
                 if (strlen($imagePath) > 0) {
                     $tmpValue[$imageCode] = $imagePath;
                 } else {
                     continue;
                 }
             }
             $value = $tmpValue;
         }
         $structuredConfig = array_merge_recursive(self::nameSpaceToArray($key, $value), $structuredConfig);
     }
     $structuredConfig["info"] = array("designer_version" => ConfigMap::VERSION, "platform" => $platform);
     if (toUpper(SITE_CHARSET) != "UTF-8") {
         $structuredConfig = Encoding::convertEncodingArray($structuredConfig, SITE_CHARSET, "UTF-8");
     }
     return json_encode($structuredConfig);
 }