<?php if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) { die; } global $APPLICATION; $arResult = array(); $arResult["URL"] = $APPLICATION->GetCurDir(); $arResult["GEO"] = \Hawkart\Megatv\CityTable::getGeoCity(); $arResult["ITEMS"] = array(); $arResult["CUR_CITY"] = array(); $arFilter = array("=UF_ACTIVE" => 1); $arSelect = array("ID", "UF_TITLE", "UF_ISO"); $obCache = new \CPHPCache(); if ($obCache->InitCache(86400, serialize($arFilter) . serialize($arSelect), "/langList/")) { $arResult["ITEMS"] = $obCache->GetVars(); } elseif ($obCache->StartDataCache()) { $result = \Hawkart\Megatv\CountryTable::getList(array('filter' => $arFilter, 'select' => $arSelect, 'order' => array("UF_TITLE" => "ASC"))); while ($arLang = $result->fetch()) { $arResult["ITEMS"][] = $arLang; } $obCache->EndDataCache($arResult["ITEMS"]); } foreach ($arResult["ITEMS"] as $arLang) { if ($arResult["GEO"]["UF_COUNTRY_ID"] == $arLang["ID"]) { $arResult["CUR_LANG"] = $arLang; } } $this->IncludeComponentTemplate();
/** * Import countries from xml EPG * * @return array */ public static function importCountry() { $file = "http://xmldata.epgservice.ru/EPGService/hs/xmldata/saturn/country_list"; $xml = simplexml_load_file($file); $arList = array(); $result = CountryTable::getList(array('filter' => array("!UF_EPG_ID" => false), 'select' => array("UF_EPG_ID", "ID", "UF_TITLE"))); while ($row = $result->fetch()) { $arList[$row["UF_EPG_ID"]] = $row; } foreach ($xml->element as $arElement) { $json = json_encode($arElement); $arElement = json_decode($json, TRUE); $epg_id = (string) $arElement["@attributes"]["id"]; $title = (string) $arElement["name"]; $iso = (string) $arElement["@attributes"]["ISO"]; if (!is_array($arList[$epg_id])) { $arFields = array("UF_EPG_ID" => $epg_id, "UF_TITLE" => $title, "UF_ISO" => $iso, "UF_ACTIVE" => 0, "UF_EXIST" => 1); $result = CountryTable::add($arFields); if ($result->isSuccess()) { $id = $result->getId(); $arFields["ID"] = $id; $arList[$epg_id] = $arFields; } else { $errors = $result->getErrorMessages(); } } } return $arCategories; }