示例#1
0
文件: cepg.php 项目: Hawkart/megatv
 /**
  * Import People from xml EPG
  *
  * @return array
  */
 public static function importPeople($arRoles = false)
 {
     $file = "http://xmldata.epgservice.ru/EPGService/hs/xmldata/saturn/people_list";
     $xml = simplexml_load_file($file);
     $arList = array();
     $result = PeopleTable::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;
     }
     if (!$arRoles) {
         $arRoles = self::importRole();
     }
     foreach ($xml->element as $arElement) {
         $el_attr = $arElement->attributes();
         $epg_id = (string) $el_attr["id"];
         $title = (string) $arElement->name;
         $role_attr = $arElement->role->attributes();
         $role_epg_id = (string) $role_attr["id"];
         $role_id = $arRoles[$role_epg_id]["ID"];
         if (!is_array($arList[$epg_id])) {
             $arFields = array("UF_EPG_ID" => $epg_id, "UF_TITLE" => $title, "UF_ROLE_ID" => $role_id);
             $result = PeopleTable::add($arFields);
             if ($result->isSuccess()) {
                 $id = $result->getId();
                 $arFields["ID"] = $id;
                 $arList[$epg_id] = $arFields;
             } else {
                 $errors = $result->getErrorMessages();
                 //\CDev::pre($arFields);\CDev::pre($errors);
             }
         }
     }
     unset($arRoles);
     return $arList;
 }