Пример #1
0
 /**
  * Function executes parcel point request and prepares the $points array.
  * @access private
  * @return Void
  */
 private function doSimpleRequest($type)
 {
     $source = parent::doRequest();
     /* We make sure there is an XML answer and try to parse it */
     if ($source !== false) {
         parent::parseResponse($source);
         if (count($this->resp_errors_list) == 0) {
             $point = $this->xpath->query('/' . $type)->item(0);
             $point_detail = array('code' => $this->xpath->query('./code', $point)->item(0)->nodeValue, 'name' => $this->xpath->query('./name', $point)->item(0)->nodeValue, 'address' => $this->xpath->query('./address', $point)->item(0)->nodeValue, 'city' => $this->xpath->query('./city', $point)->item(0)->nodeValue, 'zipcode' => $this->xpath->query('./zipcode', $point)->item(0)->nodeValue, 'country' => $this->xpath->query('./country', $point)->item(0)->nodeValue, 'latitude' => $this->xpath->query('./latitude', $point)->item(0)->nodeValue, 'longitude' => $this->xpath->query('./longitude', $point)->item(0)->nodeValue, 'phone' => $this->xpath->query('./phone', $point)->item(0)->nodeValue, 'description' => $this->xpath->query('./description', $point)->item(0)->nodeValue);
             /* We get open and close informations  */
             $schedule = array();
             foreach ($this->xpath->query('./schedule/day', $point) as $d => $day_node) {
                 $childs = $this->xpath->query('*', $day_node);
                 foreach ($childs as $child_node) {
                     if ($child_node->nodeName != '#text') {
                         $schedule[$d][$child_node->nodeName] = $child_node->nodeValue;
                     }
                 }
             }
             $point_detail['schedule'] = $schedule;
             /* We store the data in the right array (defined by $type) */
             if (!isset($this->points[$type])) {
                 $this->points[$type] = array();
             }
             $this->points[$type][] = $point_detail;
         }
     }
 }
Пример #2
0
 /**
  * Function executes countries request and prepares the $countries array.
  * @access private
  * @return Void
  */
 private function doCtrRequest()
 {
     $source = parent::doRequest();
     /* We make sure there is an XML answer and try to parse it */
     if ($source !== false) {
         parent::parseResponse($source);
         if (count($this->resp_errors_list) == 0) {
             # Add here new country xml properties to handle.
             $__prop = ['code', 'label', 'is_ue', 'states'];
             $this->countries = array();
             foreach ($this->xpath->query('/countries/country') as $k => $country) {
                 $c = (object) [];
                 # Process the random country xml properties.
                 foreach ($__prop as $_k => $_v) {
                     $c->{$_v} = $this->xpath->query('./' . $_v, $country)->item(0)->nodeValue;
                 }
                 # Process some more specific properties.
                 $c->states = [];
                 foreach ($this->xpath->query('./states/state', $country) as $state) {
                     $c->states[] = (object) ['code' => $this->xpath->query('./code', $state)->item(0)->nodeValue, 'label' => $this->xpath->query('./label', $state)->item(0)->nodeValue];
                 }
                 # Add the country object to the collection.
                 $this->countries[$c->code] = $c;
             }
         }
     }
 }
Пример #3
0
 /**
  * Function which gets news list details.
  * @access private
  * @return false if server response isn't correct; true if it is
  */
 private function doSimpleRequest()
 {
     $source = parent::doRequest();
     /* Uncomment if ou want to display the XML content */
     /* We make sure there is an XML answer and try to parse it */
     if ($source !== false) {
         parent::parseResponse($source);
         return count($this->resp_errors_list) == 0;
     }
     return false;
 }
Пример #4
0
 /**
  * Function executes carrier request and prepares the $list_points array.
  * @access private
  * @return Void
  */
 private function doCarrierRequest()
 {
     $source = $this->doRequest();
     /* We make sure there is an XML answer and try to parse it */
     if ($source !== false) {
         parent::parseResponse($source);
         if (count($this->resp_errors_list) == 0) {
             /* The XML file is loaded, we now gather the datas */
             $carriers = $this->xpath->query('/operators/operator');
             foreach ($carriers as $carrier) {
                 $result = $this->parseCarrierNode($carrier);
                 /* We use the 'code' data as index (maybe using the $c index is better) */
                 //$code = $this->xpath->query('./code', $carrier)->item(0)->nodeValue;
                 $this->carriers[$result['code']] = $result;
             }
         }
     }
 }
Пример #5
0
 /**
  * Function executes order request and prepares the $order_info array.
  * @access private
  * @return Void
  */
 private function doStatusRequest()
 {
     $source = parent::doRequest();
     /* We make sure there is an XML answer and try to parse it */
     if ($source !== false) {
         parent::parseResponse($source);
         if (count($this->resp_errors_list) == 0) {
             /* The XML file is loaded, we now gather the datas */
             $labels = array();
             $order_labels = $this->xpath->evaluate('/order/labels/*');
             foreach ($order_labels as $label_index => $label) {
                 $labels[$label_index] = $label->nodeValue;
             }
             $documents = array();
             $order_documents = $this->xpath->evaluate('/order/documents/*');
             foreach ($order_documents as $docs) {
                 $documents[$docs->nodeName] = $docs->nodeValue;
             }
             $this->order_info = array('emcRef' => $this->xpath->evaluate('/order/emc_reference')->item(0)->nodeValue, 'state' => $this->xpath->evaluate('/order/state')->item(0)->nodeValue, 'opeRef' => $this->xpath->evaluate('/order/carrier_reference')->item(0)->nodeValue, 'labelAvailable' => (bool) $this->xpath->evaluate('/order/label_available')->item(0)->nodeValue, 'labelUrl' => $this->xpath->evaluate('/order/label_url')->item(0)->nodeValue, 'labels' => $labels, 'documents' => $documents);
         }
     }
 }
Пример #6
0
 /**
  * Post request on api/v1/user_keys to generate API keys
  * @access public
  * @param Array $params Params
  * @return String
  */
 public function postUserKeys($params)
 {
     $this->setOptions(array('action' => 'api/v1/user_keys'));
     $this->param = array_merge($this->param, $params);
     $this->setPost();
     $source = parent::doRequest();
     if ($source !== false) {
         parent::parseResponse($source);
         // The request is ok, we return trimed response
         $nodes = $this->xpath->query('/user/response');
         if (isset($nodes->item(0)->nodeValue)) {
             return trim($nodes->item(0)->nodeValue);
         } else {
             return trim($nodes->item);
         }
     } else {
         return $this->resp_error;
     }
 }
Пример #7
0
 /**
  * Function executes content request and prepares the $contents array.
  * @access private
  * @return Void
  */
 private function doConRequest()
 {
     $source = parent::doRequest();
     /* We make sure there is an XML answer and try to parse it */
     if ($source !== false) {
         parent::parseResponse($source);
         if (count($this->resp_errors_list) == 0) {
             /* The XML file is loaded, we now gather the datas */
             $contents = $this->xpath->query('/contents/content');
             foreach ($contents as $content) {
                 $category_id = $this->xpath->query('./category', $content)->item(0)->nodeValue;
                 if (!isset($this->contents[$category_id])) {
                     $this->contents[$category_id] = array();
                 }
                 array_push($this->contents[$category_id], array('code' => $this->xpath->query('./code', $content)->item(0)->nodeValue, 'label' => $this->xpath->query('./label', $content)->item(0)->nodeValue, 'category' => $category_id));
             }
         }
     }
 }
Пример #8
0
 /**
  * Function executes points request and prepares the $list_points array.
  * @access private
  * @return Void
  */
 private function doListRequest()
 {
     $source = parent::doRequest();
     /* Uncomment if you want to display the XML content */
     // echo '<textarea>'.$source.'</textarea>';
     /* We make sure there is an XML answer and try to parse it */
     if ($source !== false) {
         parent::parseResponse($source);
         if (count($this->resp_errors_list) == 0) {
             /* The XML file is loaded, we now gather the datas */
             $carriers = $this->xpath->query('/carriers/carrier');
             foreach ($carriers as $carrier_index => $carrier) {
                 $this->list_points[$carrier_index]['operator'] = $this->xpath->query('./operator', $carrier)->item(0)->nodeValue;
                 $this->list_points[$carrier_index]['service'] = $this->xpath->query('./service', $carrier)->item(0)->nodeValue;
                 $points = $this->xpath->query('./points/point', $carrier);
                 foreach ($points as $point_index => $point) {
                     $point_info = array('code' => $this->xpath->query('./code', $point)->item(0)->nodeValue, 'name' => $this->xpath->query('./name', $point)->item(0)->nodeValue, 'address' => $this->xpath->query('./address', $point)->item(0)->nodeValue, 'city' => $this->xpath->query('./city', $point)->item(0)->nodeValue, 'zipcode' => $this->xpath->query('./zipcode', $point)->item(0)->nodeValue, 'country' => $this->xpath->query('./country', $point)->item(0)->nodeValue, 'latitude' => $this->xpath->query('./latitude', $point)->item(0)->nodeValue, 'longitude' => $this->xpath->query('./longitude', $point)->item(0)->nodeValue, 'phone' => $this->xpath->query('./phone', $point)->item(0)->nodeValue, 'description' => $this->xpath->query('./description', $point)->item(0)->nodeValue, 'schedule' => array());
                     $days = $this->xpath->query('./schedule/day', $point);
                     foreach ($days as $day_index => $day) {
                         $point_info['schedule'][$day_index] = array('weekday' => $this->xpath->query('./weekday', $day)->item(0)->nodeValue, 'open_am' => $this->xpath->query('./open_am', $day)->item(0)->nodeValue, 'close_am' => $this->xpath->query('./close_am', $day)->item(0)->nodeValue, 'open_pm' => $this->xpath->query('./open_pm', $day)->item(0)->nodeValue, 'close_pm' => $this->xpath->query('./close_pm', $day)->item(0)->nodeValue);
                     }
                     $this->list_points[$carrier_index]['points'][$point_index] = $point_info;
                 }
             }
         }
     }
 }