first commit
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class MessageParser {
|
||||
|
||||
public function parse($id,$db) {
|
||||
global $savvyext;
|
||||
$data = array(
|
||||
'source_vendor' => 'Error',
|
||||
'date_value' => 'N/A',
|
||||
'date_score' => 'N/A',
|
||||
'date_end_value' => 'N/A',
|
||||
'date_end_score' => 'N/A',
|
||||
'location_start_value' => 'N/A',
|
||||
'location_start_score' => 'N/A',
|
||||
'location_end_value' => 'N/A',
|
||||
'location_end_score' => 'N/A',
|
||||
'distance_value' => 'N/A',
|
||||
'distance_score' => 'N/A',
|
||||
'duration_value' => 'N/A',
|
||||
'duration_score' => 'N/A',
|
||||
'cost_value' => 'N/A',
|
||||
'cost_score' => 'N/A',
|
||||
);
|
||||
// check the cache
|
||||
$q = "SELECT a.*, b.address AS location_start, b.latitude AS location_start_lat, b.longitude AS location_start_lng, b.timezone AS location_start_tz, b.geocoding_date AS location_geocoding_date, c.address AS location_end, c.latitude AS location_end_lat, c.longitude AS location_end_lng
|
||||
FROM parsedemail_item a
|
||||
LEFT JOIN address b ON b.id=a.location_start_id
|
||||
LEFT JOIN address c ON c.id=a.location_end_id
|
||||
WHERE a.trackedemail_item_id='${id}'";
|
||||
$r = $db->query($q);
|
||||
$f = $r->row_array();
|
||||
if ($f!=NULL) {
|
||||
$data['source_vendor'] = $f["transport_provider_id"];
|
||||
$data['date_value'] = $f["travel_date"];
|
||||
$data['date_end_value'] = $f["travel_date_end"];
|
||||
$data['location_start_value'] = $f["location_start"];
|
||||
$data['location_end_value'] = $f["location_end"];
|
||||
$data['distance_value'] = $f["distance"]==0?'N/A':$f["distance"];
|
||||
$data['duration_value'] = $f["duration"]==0?'N/A':$f["duration"];
|
||||
$data['cost_value'] = $f["cost"];
|
||||
return $data;
|
||||
}
|
||||
$url = $savvyext->cfgReadChar('system.oauth2_url')."parse/${id}";
|
||||
error_log($url);
|
||||
// hit the service
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Server-Token '.$savvyext->cfgReadChar('system.oauth2_token')));
|
||||
if( ! $result = curl_exec($ch)) {
|
||||
// Error
|
||||
} else {
|
||||
$raw_data = json_decode($result,true);
|
||||
if (is_array($raw_data) && !isset($raw_data['error']) && isset($raw_data['code']) &&
|
||||
$raw_data['code']=='0' && is_array($raw_data['data'])) {
|
||||
$data = $raw_data['data'];
|
||||
}
|
||||
}
|
||||
curl_close($ch);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
vi:ts=2
|
||||
*/
|
||||
Reference in New Issue
Block a user