예제 #1
0
파일: DB.php 프로젝트: kshamiev/testXml
 /**
  * Инициализация соединения с БД.
  *
  */
 public static function Init()
 {
     //  Initcializatciia ob``ekta mysqli
     /* create a connection object which is not connected */
     try {
         self::$DB = mysqli_connect(DB_HOST, DB_LOGIN, DB_PASSWORD, DB_NAME);
     } catch (Exception $e) {
         throw new Exception(mysqli_connect_error(), 500);
     }
     /* check connection */
     if (mysqli_connect_errno()) {
         die("mysqli - Unable to connect to the server or choose a database.<br>\n Cause: " . mysqli_connect_error());
     }
     self::$DB->set_charset('utf8');
     //  self::$DB = mysqli_init();
     /* set connection options */
     //  self::$DB->options(MYSQLI_INIT_COMMAND, "SET AUTOCOMMIT=1");
     //  self::$DB->options(MYSQLI_INIT_COMMAND, "SET CacheDataACTER SET UTF8");
     //  self::$DB->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5);
     /* connect to server */
     //  self::$DB->real_connect(DB_HOST, DB_LOGIN, DB_PASSW, DB_NAME);
     //  self::$DB->select_db(DB_NAME);
     //  Initcializatciia interfesa dlia raboty` s khranimy`mi protcedurami
     //    self::$Procedure = new DB_Procedure();
     //  mysql_query('SET CacheDataACTER SET UTF8');
     //  mysql_query('SET CacheDataACTER SET cp1251_koi8');
     //  mysql_query('set names cp1251');
     //  mysql_query("SET CacheDataACTER SET DEFAULT", self::$DB_Link);
 }
예제 #2
0
파일: Test.php 프로젝트: kshamiev/testXml
 /**
  * Обработчик ноды одноименной методу (без учета регистра)
  *
  * @param Xml_Object $xml
  * @return bool
  */
 public function offer(Xml_Object $xml)
 {
     // Main
     $params = [];
     $attributes = $xml->Get_Attributes();
     if (!isset($attributes['internal-id'])) {
         return Zero_Logs::Error('error attribute internal-id');
     }
     $params[] = $attributes['internal-id'];
     if (is_null($node = $xml->Get_Node('type')) || !$node->Get_Data()) {
         return Zero_Logs::Error('error tag type');
     }
     $params[] = $node->Get_Data();
     if (is_null($node = $xml->Get_Node('property-type')) || !$node->Get_Data()) {
         return Zero_Logs::Error('error tag property-type');
     }
     $params[] = $node->Get_Data();
     if (is_null($node = $xml->Get_Node('category')) || !$node->Get_Data()) {
         return Zero_Logs::Error('error tag category');
     }
     $params[] = $node->Get_Data();
     if (is_null($node = $xml->Get_Node('url')) || !$node->Get_Data()) {
         return Zero_Logs::Error('error tag url');
     }
     $params[] = $node->Get_Data();
     if (is_null($node = $xml->Get_Node('creation-date')) || !$node->Get_Data() || null == ($date = $this->CheckDate($xml->Get_Data()))) {
         return Zero_Logs::Error('error tag creation-date');
     }
     $params[] = $date->format('Y-m-d H:i:s');
     if (!is_null($node = $xml->Get_Node('last-update-date')) && '' != $node->Get_Data()) {
         if (is_null($date = $this->CheckDate($xml->Get_Data()))) {
             return Zero_Logs::Error('error tag last-update-date');
         }
         $params[] = $date->format('Y-m-d H:i:s');
     } else {
         $params[] = '';
     }
     if (!is_null($node = $xml->Get_Node('expire-date')) && '' != $node->Get_Data()) {
         if (is_null($date = $this->CheckDate($xml->Get_Data()))) {
             return Zero_Logs::Error('error tag expire-date');
         }
         $params[] = $date->format('Y-m-d H:i:s');
     } else {
         $params[] = '';
     }
     if (is_null($node = $xml->Get_Node('payed-adv')) || !$node->Get_Data() || !isset($this->FlagBool[$node->Get_Data()])) {
         return Zero_Logs::Error('error tag payed-adv');
     }
     $params[] = $this->FlagBool[$node->Get_Data()];
     if (is_null($node = $xml->Get_Node('manually-added')) || !$node->Get_Data() || !isset($this->FlagBool[$node->Get_Data()])) {
         return Zero_Logs::Error('error tag manually-added');
     }
     $params[] = $this->FlagBool[$node->Get_Data()];
     // Location
     if (is_null($nodeLocation = $xml->Get_Node('location'))) {
         return Zero_Logs::Error('error tag location');
     }
     if (is_null($node = $nodeLocation->Get_Node('country')) || !$node->Get_Data()) {
         return Zero_Logs::Error('error tag location country');
     }
     $params[] = $node->Get_Data();
     if (is_null($node = $nodeLocation->Get_Node('region'))) {
         $params[] = '';
     } else {
         $params[] = $node->Get_Data();
     }
     if (is_null($node = $nodeLocation->Get_Node('district'))) {
         $params[] = '';
     } else {
         $params[] = $node->Get_Data();
     }
     if (is_null($node = $nodeLocation->Get_Node('locality-name'))) {
         $params[] = '';
     } else {
         $params[] = $node->Get_Data();
     }
     if (is_null($node = $nodeLocation->Get_Node('sub-locality-name'))) {
         $params[] = '';
     } else {
         $params[] = $node->Get_Data();
     }
     if (is_null($node = $nodeLocation->Get_Node('address'))) {
         $params[] = '';
     } else {
         $params[] = $node->Get_Data();
     }
     if (is_null($node = $nodeLocation->Get_Node('direction'))) {
         $params[] = '';
     } else {
         $params[] = $node->Get_Data();
     }
     if (is_null($node = $nodeLocation->Get_Node('distance'))) {
         $params[] = '';
     } else {
         $params[] = $node->Get_Data();
     }
     if (is_null($node = $nodeLocation->Get_Node('latitude'))) {
         $params[] = '';
     } else {
         $params[] = $node->Get_Data();
     }
     if (is_null($node = $nodeLocation->Get_Node('longitude'))) {
         $params[] = '';
     } else {
         $params[] = $node->Get_Data();
     }
     // Metro
     if (is_null($nodeMetro = $nodeLocation->Get_Node('metro'))) {
         $params[] = '';
         $params[] = '';
         $params[] = '';
     } else {
         if (is_null($node = $nodeMetro->Get_Node('name'))) {
             $params[] = '';
         } else {
             $params[] = $node->Get_Data();
         }
         if (is_null($node = $nodeMetro->Get_Node('time-on-transport'))) {
             $params[] = '';
         } else {
             $params[] = $node->Get_Data();
         }
         if (is_null($node = $nodeMetro->Get_Node('time-on-foot'))) {
             $params[] = '';
         } else {
             $params[] = $node->Get_Data();
         }
     }
     if (is_null($node = $nodeLocation->Get_Node('railway-station'))) {
         $params[] = '';
     } else {
         $params[] = $node->Get_Data();
     }
     // Price
     if (is_null($nodePrice = $xml->Get_Node('price'))) {
         return Zero_Logs::Error('error tag price');
     }
     if (is_null($node = $nodePrice->Get_Node('value')) || !$node->Get_Data()) {
         return Zero_Logs::Error('error tag price value');
     }
     $params[] = $node->Get_Data();
     if (is_null($node = $nodePrice->Get_Node('currency')) || !$node->Get_Data()) {
         return Zero_Logs::Error('error tag price currency');
     }
     $params[] = $node->Get_Data();
     if (is_null($node = $nodePrice->Get_Node('period'))) {
         $params[] = '';
     } else {
         $params[] = $node->Get_Data();
     }
     if (is_null($node = $nodePrice->Get_Node('unit'))) {
         $params[] = '';
     } else {
         $params[] = $node->Get_Data();
     }
     // SalesAgent
     $params_sales = [];
     if (is_null($nodeSales = $xml->Get_Node('sales-agent'))) {
         return Zero_Logs::Error('error tag sales-agent');
     }
     if (is_null($node = $nodeSales->Get_Node('name'))) {
         $params_sales[] = '';
     } else {
         $params_sales[] = $node->Get_Data();
     }
     if (is_null($node = $nodeSales->Get_Node('phone')) || !$node->Get_Data()) {
         return Zero_Logs::Error('error tag phone');
     }
     $params_sales[] = $node->Get_Data();
     if (is_null($node = $nodeSales->Get_Node('category'))) {
         $params_sales[] = '';
     } else {
         $params_sales[] = $node->Get_Data();
     }
     if (is_null($node = $nodeSales->Get_Node('organization'))) {
         $params_sales[] = '';
     } else {
         $params_sales[] = $node->Get_Data();
     }
     if (is_null($node = $nodeSales->Get_Node('agency-id'))) {
         $params_sales[] = '';
     } else {
         $params_sales[] = $node->Get_Data();
     }
     if (is_null($node = $nodeSales->Get_Node('url'))) {
         $params_sales[] = '';
     } else {
         $params_sales[] = $node->Get_Data();
     }
     if (is_null($node = $nodeSales->Get_Node('email'))) {
         $params_sales[] = '';
     } else {
         $params_sales[] = $node->Get_Data();
     }
     if (is_null($node = $nodeSales->Get_Node('partner'))) {
         $params_sales[] = '';
     } else {
         $params_sales[] = $node->Get_Data();
     }
     // Sql
     $sql = "INSERT Offers SET\n            internal_id = %d,\n            type = %s,\n            property_type = %s,\n            category = %s,\n            url = %s,\n            creation_date = %s,\n            last_update_date = %s,\n            expire_date = %s,\n            payed_adv = %d,\n            manually_added = %d,\n            country = %s,\n            region = %s,\n            district = %s,\n            locality_name = %s,\n            sub_locality_name = %s,\n            address = %s,\n            direction = %s,\n            distance = %d,\n            latitude = %d,\n            longitude = %d,\n            metroName = %s,\n            time_on_transport = %d,\n            time_on_foot = %d,\n            railway_station = %s,\n            price = %f,\n            currency = %s,\n            period = %s,\n            unit = %s\n        ";
     $sql = Zero_DB::Escape_Format($sql, $params);
     if (!($offer_id = Zero_DB::Ins($sql))) {
         return Zero_Logs::Error('error offer save: ' . $attributes['internal-id']);
     }
     $sql = "INSERT OffersSalesAgent SET\n            name = %s,\n            phone = %s,\n            category = %s,\n            organization = %s,\n            agency_id = %d,\n            url = %s,\n            email = %s,\n            partner = %s,\n            Offers_Id = %d\n        ";
     $params_sales[] = $offer_id;
     $sql = Zero_DB::Escape_Format($sql, $params_sales);
     Zero_DB::Ins($sql);
     // Images
     if (!is_null($nodeImages = $xml->Get_Nodes('image'))) {
         $sqlImages = [];
         $sql = "INSERT INTO `OffersImages`(`Offers_Id`, `image`) VALUES ";
         foreach ($nodeImages as $node) {
             /* @var $node Xml_Object */
             if ('' != ($img = $node->Get_Data())) {
                 $sqlImages[] = '(' . $offer_id . ', ' . Zero_DB::Escape_T($img) . ')';
             }
         }
         if (0 < count($sqlImages)) {
             $sql .= implode(', ', $sqlImages);
         }
         Zero_DB::Ins($sql);
     }
     return Zero_Logs::Info('обработка предложения id: ' . $attributes['internal-id']);
 }
예제 #3
0
파일: index.php 프로젝트: kshamiev/testXml
<?php

/**
 * The entry point to the application.
 * Initialize and run.
 */
// Including the class App
require 'config.php';
Zero_Logs::Init('app.log');
Zero_DB::Init();
$xml = new Xml_Parser();
$xml->Parser(PATH_EXCHANGE . '/test.xml', 'Xml_Handler_Test');
die('Done');