SATELLITE IMG HELPER
This commit is contained in:
parent
0f5eac6cbc
commit
727fdd98b1
94
api/application/helpers/satellite_image_helper.php
Normal file
94
api/application/helpers/satellite_image_helper.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
class satellite_image
|
||||
{
|
||||
|
||||
public static function getSatelliteImage($pd_id,$pd_type = 1)//1 - credit PD,2 - sales pd
|
||||
{
|
||||
$pdid = $pd_id;
|
||||
$CI =&get_instance();
|
||||
$path_to_check = $pd_type == 1 ? $CI->external_path.'/pd_reports/'.$pdid : $CI->external_path.'/sales_pd/'.$pdid;
|
||||
$geo_location = null;
|
||||
$pdmas = array();
|
||||
$logger = $pd_type == 1 ? MYLOG::logFunction(null,$pdid) : MYLOG::logSalesPD($pdid);
|
||||
$model_to_load = $pd_type == 1 ? 'PD_Model' : 'Sales_PD_Model';
|
||||
//print_r($logger);die();
|
||||
if(!file_exists($path_to_check))
|
||||
{
|
||||
mkdir($path_to_check,0777);
|
||||
}
|
||||
|
||||
if($pd_type == 1)
|
||||
{
|
||||
$pdmas = $CI->PD_Model->getPDMasterDetails($pdid);
|
||||
$geo_location = $pdmas[0]['start_location'];
|
||||
}
|
||||
else if($pd_type == 2)
|
||||
{
|
||||
$pdmas = $CI->Sales_PD_Model->selectCustomRecords(array('geo_location'),array('sales_pd_id' => $pdid),SALES_PD_DATA);
|
||||
$geo_location = $pdmas[0]['geo_location'];
|
||||
}
|
||||
|
||||
|
||||
|
||||
$satellite_script_from_db = $CI->$model_to_load->selectCustomRecords(array('*'),array('script_name' => SATELLITE_IMAGE_LOCATION),SCRIPTS);
|
||||
$satellite_script = $satellite_script_from_db[0]['script_content'];
|
||||
|
||||
$google_map_static_api_key = GOOGLE_STATIC_MAP_API_KEY;
|
||||
|
||||
|
||||
//Replacing Place holders
|
||||
|
||||
|
||||
$satellite_script = str_replace('{{APPPATH}}',$path_to_check,$satellite_script);
|
||||
$satellite_script = str_replace('{{ADDRESS}}',$geo_location,$satellite_script);
|
||||
$satellite_script = str_replace('{{GEOLOCATION}}',$geo_location,$satellite_script);
|
||||
$satellite_script = str_replace('{{API_KEY}}',$google_map_static_api_key,$satellite_script);
|
||||
//echo $satellite_script;die();
|
||||
|
||||
file_put_contents(APPPATH.'/views/js/phantomsatellite.js',$satellite_script);
|
||||
|
||||
//call& execute phantom script
|
||||
$str = 'phantomjs '.APPPATH.'/views/js/phantomsatellite.js';
|
||||
exec($str,$ou);
|
||||
exec('phantom.exit();');
|
||||
|
||||
|
||||
// //convert as base 64 image.
|
||||
$satellite_image_png_path = $path_to_check.'/satellite.png';
|
||||
//echo 'all done';
|
||||
//die();
|
||||
if($pd_type == 1 )
|
||||
{
|
||||
|
||||
$bucketname = LENDER_BUCKET_NAME_PREFIX.$pdmas[0]['fk_lender_id'];
|
||||
$key = 'pd'.$pdid.'/'.'satellite.png';
|
||||
$bucket_data = array('bucket_name'=>$bucketname,'key'=>$key,'sourcefile'=>$CI->external_path.'/pd_reports/'.$pdid.'/satellite.png');
|
||||
|
||||
$s3result= $CI->aws_s3->uploadFileToS3Bucket($bucket_data);
|
||||
|
||||
if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200)
|
||||
{
|
||||
|
||||
$CI->PD_Model->updateRecords(array('isactive' => 0),PDDOCUMENTS,array('pd_document_title' => 'satellite','fk_pd_id' => $pd_id));
|
||||
$record_data = array('fk_pd_id' => $pdid,'pd_document_title'=>'satellite','pd_document_name'=>'satellite.png','fk_form_id'=>null,'rental_count_id' => null,'location' => null);
|
||||
$id = $CI->PD_Model->saveRecords($record_data,PDDOCUMENTS);
|
||||
|
||||
$custom_log_info = '###CUSTOM DEBUG SATELLITE IMAGE STORED IN S3 DONE - '. $id;
|
||||
log_message('ERROR',$custom_log_info);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
else if($pd_type == 2) //save satellite img as base64 in sale pd doc table
|
||||
{
|
||||
$satellite_base64 = base64_encode(file_get_contents($satellite_image_png_path));
|
||||
$CI->Sales_PD_Model->saveRecords(array('img' => $satellite_base64,'img_name' => 'satellite','fk_sales_pd_id' => $pdid),SALEPD_DOCS);
|
||||
}
|
||||
//generate log
|
||||
$logger->info("Generate Satellite Called in (".ENVIRONMENT.")",array('script' => $satellite_script,'script_output' => $ou));
|
||||
//return $base64_pdscore_chart_url;
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
||||
Loading…
Reference in New Issue
Block a user