WIP Workorder AH download
This commit is contained in:
@@ -247,7 +247,111 @@ class Rimoapi {
|
||||
return false;
|
||||
}
|
||||
|
||||
$items = self::getFilenames($rimo_id);
|
||||
|
||||
if(!is_object($items)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!is_array($items->item) || !count($items->item)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach($items->item as $item) {
|
||||
if(!$item->name) continue;
|
||||
|
||||
if(!preg_match('/_AHA.pdf$/i', $item->name)) continue;
|
||||
|
||||
$filename = $item->name;
|
||||
}
|
||||
|
||||
if(!$filename) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// fetch file
|
||||
|
||||
$params = [];
|
||||
$params['apiKey'] = RIMO_API_JSON_APIKEY;
|
||||
$params['objectId'] = $rimo_id;
|
||||
$params['fileNames'] = $filename;
|
||||
|
||||
$ctx_opts = [
|
||||
'http' => [
|
||||
'method' => 'GET',
|
||||
]
|
||||
];
|
||||
|
||||
$qs = http_build_query($params);
|
||||
|
||||
$getFileEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_GET_FILES;
|
||||
|
||||
$get_url = $getFileEp."?".$qs;
|
||||
$ctx = stream_context_create($ctx_opts);
|
||||
$log->debug(__METHOD__.": Retrieving file from Rimo: $get_url");
|
||||
$response = file_get_contents($get_url, false, $ctx);
|
||||
|
||||
if(!$response) return false;
|
||||
|
||||
/* remove boundary from rimo response
|
||||
|
||||
header:
|
||||
|
||||
--uuid:b0b72203-db4d-4a85-9d26-b01cd08338c1
|
||||
Content-Type: application/octet-stream
|
||||
Content-Transfer-Encoding: binary
|
||||
Content-ID: <101DCY_AHA.pdf>
|
||||
|
||||
footer:
|
||||
|
||||
--uuid:b0b72203-db4d-4a85-9d26-b01cd08338c1--
|
||||
*/
|
||||
|
||||
|
||||
$finfo = new Finfo(FILEINFO_MIME);
|
||||
$mimetype = $finfo->buffer($response);
|
||||
|
||||
var_dump($mimetype);exit;
|
||||
|
||||
if(!stripos($mimetype, "pdf")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public static function getFilenames($rimo_id) {
|
||||
if(!$rimo_id) return false;
|
||||
|
||||
$log = mfLoghandler::singleton();
|
||||
|
||||
$params = [];
|
||||
$params['apiKey'] = RIMO_API_JSON_APIKEY;
|
||||
$params['objectId'] = $rimo_id;
|
||||
|
||||
$ctx_opts = [
|
||||
'http' => [
|
||||
'method' => 'GET',
|
||||
'header' => 'accept: application/json'
|
||||
]
|
||||
];
|
||||
|
||||
$qs = http_build_query($params);
|
||||
|
||||
$getFileEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_GET_FILENAMES;
|
||||
|
||||
$get_url = $getFileEp."?".$qs;
|
||||
$ctx = stream_context_create($ctx_opts);
|
||||
$log->debug(__METHOD__.": Getting Filenames from Rimo: $get_url");
|
||||
$response = file_get_contents($get_url, false, $ctx);
|
||||
|
||||
if($response === false) {
|
||||
$log->error("Error retrieving filenames from RIMO for $rimo_id");
|
||||
return false;
|
||||
}
|
||||
|
||||
$resp_data = json_decode($response);
|
||||
return $resp_data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user