/** * Set country & default city by country's iso * * @return array */ public static function setCountryByIso($iso) { global $currentGeo; $arSelect = array("ID", "UF_TITLE", "UF_TIMEZONE", "UF_COUNTRY_ID", "COUNTRY_ISO" => "UF_COUNTRY.UF_ISO"); $result = CityTable::getList(array('filter' => array("=UF_COUNTRY.UF_ISO" => $iso, "=UF_ACTIVE" => 1, "=UF_DEFAULT" => 1), 'select' => $arSelect, 'limit' => 1)); $currentGeo = $_SESSION["USER_GEO"] = $result->fetch(); return $_SESSION["USER_GEO"]; }
public static function exportChannelCity() { $arRows = array(); $fp = fopen($_SERVER["DOCUMENT_ROOT"] . "/upload/channel_city.csv", 'w'); $firstStr = array("Субъект федерации" . "\t", "Город/Канал" . "\t"); $arChannelCity = array(); $arSelect = array("ID", "UF_CHANNEL_ID", "UF_CITY_ID", "UF_BASE_ID" => "UF_CHANNEL.UF_BASE_ID", "UF_EPG_ID" => "UF_CHANNEL.UF_EPG_ID"); $result = ChannelCityTable::getList(array('filter' => array(), 'select' => $arSelect)); while ($arItem = $result->fetch()) { $arChannelCity[$arItem["UF_CITY_ID"]][$arItem["UF_BASE_ID"]] = $arItem["UF_EPG_ID"]; } $arCities = array(); $arFilter = array("UF_COUNTRY.UF_TITLE" => "Россия", "UF_ACTIVE" => 1); $arSelect = array("ID", "UF_TITLE", "UF_REGION"); $result = CityTable::getList(array('filter' => $arFilter, 'select' => $arSelect, 'order' => array("UF_TITLE" => "ASC"))); while ($arCity = $result->fetch()) { $arCities[$arCity["ID"]] = $arCity; } $arChannels = array(); $arFilter = array("UF_ACTIVE" => 1); $arSelect = array("ID", "UF_TITLE"); $result = ChannelBaseTable::getList(array('filter' => $arFilter, 'select' => $arSelect)); while ($arChannel = $result->fetch()) { $arChannels[$arChannel["ID"]] = $arChannel["UF_TITLE"]; $firstStr[] = $arChannel["UF_TITLE"] . "\t"; } $arRows[] = $firstStr; fputcsv($fp, $firstStr, ";"); foreach ($arCities as $city_id => $arCity) { $arStr = array($arCity["UF_REGION"], $arCity["UF_TITLE"]); foreach ($arChannels as $channel_id => $channel_title) { $arStr[] = (string) $arChannelCity[$city_id][$channel_id] . "\t"; } $arRows[] = $arStr; fputcsv($fp, $arStr); } fclose($fp); $fileName = 'channel_city.csv'; header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header('Content-Description: File Transfer'); header("Content-type: text/csv"); header("Content-Disposition: attachment; filename={$fileName}"); header("Expires: 0"); header("Pragma: public"); $fh = @fopen('php://output', 'w'); foreach ($arRows as $data) { fputcsv($fh, $data, ";"); } fclose($fh); exit; }
/** * import channel & city info connection */ public static function import() { $arChannelCity = array(); $arFilter = array(); $arSelect = array("ID", "UF_CHANNEL_ID", "UF_CITY_ID"); $result = ChannelCityTable::getList(array('filter' => $arFilter, 'select' => $arSelect)); while ($arItem = $result->fetch()) { $arChannelCity[$arItem["UF_CHANNEL_ID"] . "-" . $arItem["UF_CITY_ID"]] = $arItem["ID"]; } $arCities = array(); $arFilter = array("UF_COUNTRY.UF_TITLE" => "Россия", "UF_ACTIVE" => 1); $arSelect = array("ID", "UF_TITLE"); $result = CityTable::getList(array('filter' => $arFilter, 'select' => $arSelect)); while ($arCity = $result->fetch()) { $arCities[$arCity["UF_TITLE"]] = $arCity["ID"]; } $arChannels = array(); $arFilter = array(); $arSelect = array("ID", "UF_EPG_ID"); $result = ChannelTable::getList(array('filter' => $arFilter, 'select' => $arSelect)); while ($arChannel = $result->fetch()) { $arChannels[$arChannel["UF_EPG_ID"]] = $arChannel["ID"]; } $file = $_SERVER["DOCUMENT_ROOT"] . "/local/modules/hawkart.megatv/data/channel_city.csv"; $lines = file($file); foreach ($lines as $line_num => $line) { $arItem = explode(";", $line); $city = trim($arItem[0]); foreach ($arItem as $value) { if (strpos($value, "channel_id=") !== false) { $channel_epg_id = str_replace("channel_id=", "", $value); $channel_epg_id = trim($channel_epg_id); $city_id = $arCities[$city]; $channel_id = $arChannels[$channel_epg_id]; if (intval($arChannelCity[$channel_id . "-" . $city_id]) == 0 && intval($city_id) > 0 && intval($channel_id) > 0) { //echo $city." ".$channel_epg_id."<br />"; $arFields = array("UF_CITY_ID" => $city_id, "UF_CHANNEL_ID" => $channel_id); //\CDev::pre($arFields); $result = ChannelCityTable::add($arFields); if ($result->isSuccess()) { $id = $result->getId(); $arChannelCity[$channel_id . "-" . $city_id] = $id; } } } } } }
<?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_COUNTRY_ID" => $arResult["GEO"]["UF_COUNTRY_ID"], "=UF_ACTIVE" => 1); $arSelect = array("ID", "UF_TITLE"); $obCache = new \CPHPCache(); if ($obCache->InitCache(86400, serialize($arFilter) . serialize($arSelect), "/cityList/")) { $arResult["ITEMS"] = $obCache->GetVars(); } elseif ($obCache->StartDataCache()) { $result = \Hawkart\Megatv\CityTable::getList(array('filter' => $arFilter, 'select' => $arSelect, 'order' => array("UF_TITLE" => "ASC"))); while ($arCity = $result->fetch()) { $arResult["ITEMS"][] = $arCity; } $obCache->EndDataCache($arResult["ITEMS"]); } foreach ($arResult["ITEMS"] as $arCity) { if ($arResult["GEO"]["ID"] == $arCity["ID"]) { $arResult["CUR_CITY"] = $arCity; } } $this->IncludeComponentTemplate();
public static function getByFilterSelect($arFilter) { $arSelect = array("ID", "UF_TITLE", "UF_TIMEZONE", "UF_COUNTRY_ID", "COUNTRY_ISO" => "UF_COUNTRY.UF_ISO"); $result = CityTable::getList(array('filter' => $arFilter, 'select' => $arSelect, 'limit' => 1)); return $result->fetch(); }