Example #1
0
 /**
  * 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;
 }