From 479e3942e0812e32b78813fa59dbb077bc2e80cf Mon Sep 17 00:00:00 2001 From: Velz2020 Date: Thu, 11 Feb 2021 00:41:03 +0530 Subject: [PATCH] REPORT URL SHORTNER --- api/application/config/constants.php | 3 + api/application/config/routes.php | 2 +- api/application/controllers/PD_Controller.php | 2 +- api/application/controllers/Welcome.php | 119 ++++++++++++++---- .../helpers/photo_pdf_converter_helper.php | 1 + .../helpers/report_attachments_helper.php | 34 ++--- .../helpers/url_shortener_helper.php | 51 ++++++++ 7 files changed, 168 insertions(+), 44 deletions(-) create mode 100644 api/application/helpers/url_shortener_helper.php diff --git a/api/application/config/constants.php b/api/application/config/constants.php index 9bf49636..0684791c 100644 --- a/api/application/config/constants.php +++ b/api/application/config/constants.php @@ -115,6 +115,7 @@ defined('OFFICER_TRACKING_URL') OR define('OFFICER_TRACKING_URL','https://demo.p defined('CUSTOMER_IMG_URL') OR define('CUSTOMER_IMG_URL','https://demo.pdgenie.com/customer/#/pd-images/'); defined('SALESPD_CUSTOMER_IMG_URL') OR define('SALESPD_CUSTOMER_IMG_URL','https://demo.pdgenie.com/customer/#/salespd_images/'); defined('CUSTOMER_IMG_URL') OR define('CUSTOMER_IMG_URL','https://demo.pdgenie.com/customer/#/pd-images/'); +defined('PDF_ATTACHEMENT_URL') OR define('PDF_ATTACHEMENT_URL','https://apitest.pdgenie.com/sparqdev/api/short?dat='); } else if(ENVIRONMENT == 'testing') { @@ -128,6 +129,7 @@ else if(ENVIRONMENT == 'testing') defined('OFFICER_TRACKING_URL') OR define('OFFICER_TRACKING_URL','https://demo.pdgenie.com/otnew/#/'); defined('SALESPD_CUSTOMER_IMG_URL') OR define('SALESPD_CUSTOMER_IMG_URL','https://demo.pdgenie.com/customer/#/salespd_images/'); defined('CUSTOMER_IMG_URL') OR define('CUSTOMER_IMG_URL','https://demo.pdgenie.com/customer/#/pd-images/'); + defined('PDF_ATTACHEMENT_URL') OR define('PDF_ATTACHEMENT_URL','https://apitest.pdgenie.com/sparqtest/api/short?dat='); } else if(ENVIRONMENT == 'production') { @@ -141,6 +143,7 @@ else if(ENVIRONMENT == 'production') defined('OFFICER_TRACKING_URL') OR define('OFFICER_TRACKING_URL','https://pdgenie.com/track/#/'); defined('SALESPD_CUSTOMER_IMG_URL') OR define('SALESPD_CUSTOMER_IMG_URL','https://pdgenie.com/customer/#/salespd_images/'); defined('CUSTOMER_IMG_URL') OR define('CUSTOMER_IMG_URL','https://pdgenie.com/customer/#/pd-images/'); + defined('PDF_ATTACHEMENT_URL') OR define('PDF_ATTACHEMENT_URL','https://api.pdgenie.com/sparqprod/api/short?dat='); } /*********************END of AWS resources Constants*************************************************/ diff --git a/api/application/config/routes.php b/api/application/config/routes.php index c68c9708..270c473f 100644 --- a/api/application/config/routes.php +++ b/api/application/config/routes.php @@ -50,7 +50,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); | my-controller/my-method -> my_controller/my_method */ $route['default_controller'] = 'welcome'; -$route['vdo'] = 'welcome/short'; +$route['short'] = 'welcome/receiveShortenURL'; $route['autenticadors'] = 'autenticador/index'; $route['404_override'] = ''; $route['translate_uri_dashes'] = FALSE; diff --git a/api/application/controllers/PD_Controller.php b/api/application/controllers/PD_Controller.php index 8de16f33..c8c525cc 100644 --- a/api/application/controllers/PD_Controller.php +++ b/api/application/controllers/PD_Controller.php @@ -4866,7 +4866,7 @@ public function getPDFormDetailsJSON_post() //Get attachment links and embed here... //get img pdf - $report_attachments = (new report_attachments)->getReportAttchments($pd_master_details[0]['pd_id'],$pd_master_details[0]['random_string']); + $report_attachments = (new report_attachments)->getReportAttchments($pd_master_details[0]['pd_id'],$pd_master_details[0]['random_string'],$pd_master_details); $temp = substr_replace($temp,$report_attachments,strpos($temp,''),0); //End Get attachment links diff --git a/api/application/controllers/Welcome.php b/api/application/controllers/Welcome.php index 65e52a8c..3e57a0eb 100644 --- a/api/application/controllers/Welcome.php +++ b/api/application/controllers/Welcome.php @@ -18,17 +18,35 @@ class Welcome extends CI_Controller { * map to /index.php/welcome/ * @see https://codeigniter.com/user_guide/general/urls.html */ + + + protected $redirect_url = 'https://demo.pdgenie.com/error/404.html'; + + + function __construct() + { + // Construct the parent class + parent::__construct(); + $this->external_path = $this->config->item('external_data_path'); + } + + public function index() { $this->load->view('welcome_message'); } - public function short() + public function checktest() + { + $this->load->helper('url_shortener'); + // echo $_SERVER['REQUEST_URI'];die(); + print('
'.print_r(url_shortener::url_shorten(2148,'nmi9iJ2tDKrc7GRo')).'
'); + } + + + public function receiveShortenURL() { $data = $this->input->get('dat'); - //echo $data; - - $redirect_url = 'https://demo.pdgenie.com/error/404.html'; if($data) { @@ -36,36 +54,85 @@ class Welcome extends CI_Controller { $uri = custom_encryption::decode($data); // echo $uri; $uri = explode('/',$uri); - $video_name = $uri[0]; - $date = $uri[1]; - $is_expired = MYUTIL::isDateExpired($date,7); - if(!$is_expired) + // print_r($uri);die(); + $pd_id = $uri[2]; + $random_string = $uri[3];//in case type is video then randon string will be video name(composition id) + $type = $uri[0]; + $date_created = $uri[1]; + $is_expired = MYUTIL::isDateExpired($date_created,15); + if(!$is_expired) { - - $this->load->model('PD_Model'); - $this->load->library('AWS_S3'); - $room_info = $this->PD_Model->selectCustomRecords(array('*'),array('composition_id' => $video_name),VIDEO_ROOM_INFO); - //print_r($room_info);die(); - if(count($room_info)) - { - $pd_master_details = $this->PD_Model->getPDMasterDetails($room_info[0]['fk_pd_id']); - $bucket_name = LENDER_BUCKET_NAME_PREFIX.$pd_master_details[0]['fk_lender_id']; - $final_key = 'pd'.$pd_master_details[0]['pd_id'].'/video/'.$video_name.'.mp4'; - $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$final_key,'+2 hour'); - $redirect_url = $singed_uri; - } + if($type == 'vdo') + { + $this->redirect_url = $this->vdo($pd_id,$random_string); + } + else if($type == 'ppdf') + { + $this->redirect_url = $this->ppdf($pd_id,$random_string); + }else if($type == 'zip') + { + $this->redirect_url = $this->zip($pd_id,$random_string); + } } else { - $redirect_url = 'https://demo.pdgenie.com/error/exp.html'; + $this->redirect_url = 'https://demo.pdgenie.com/error/exp.html'; } + } + + // echo $this->redirect_url;die(); + header("Location: $this->redirect_url"); + + } - //echo $redirect_url; - header("Location: $redirect_url"); - } + public function vdo($pdid,$video_name) + { + $this->load->model('PD_Model'); + $this->load->library('AWS_S3'); + $room_info = $this->PD_Model->selectCustomRecords(array('*'),array('composition_id' => $video_name),VIDEO_ROOM_INFO); + // print_r($room_info);die(); + if(count($room_info)) + { + // echo 'vdo working'; + $pd_master_details = $this->PD_Model->getPDMasterDetails($room_info[0]['fk_pd_id']); + $bucket_name = LENDER_BUCKET_NAME_PREFIX.$pd_master_details[0]['fk_lender_id']; + + if(!$room_info[0]['is_uploaded']){ $video_name = $video_name.'.mp4'; } + + $final_key = 'pd'.$pd_master_details[0]['pd_id'].'/video/'.$video_name; + // echo $final_key;die(); + $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$final_key,'+2 hour'); + return + //echo + $singed_uri;//die(); + // $viewdata['uri'] = $singed_uri; + // $this->load->view('vdoplayer.php',$viewdata); + + } + + } + + function ppdf($pd_id,$random_string) + { + $this->load->helper('photo_pdf_converter'); + return $res_data = (new photo_pdf_converter)->covertImgs2PDF($pd_id,$random_string,array()); + } + + function zip($pd_id,$random_string) + { + $this->load->helper('photo_zip_creator'); + return $res_data = (new photo_zip_creator)->covertImgs2ZIP($pd_id,$random_string,array()); + } + + public function checkAfterResponse() + { + // $data['dataStatus'] = false; + // $data['status'] = REST_Controller::HTTP_NOT_FOUND; + // $data['msg'] = 'No Data File Found!'; + // $this->response($data,REST_Controller::HTTP_OK,true); + echo 'Hi'; } - } diff --git a/api/application/helpers/photo_pdf_converter_helper.php b/api/application/helpers/photo_pdf_converter_helper.php index ebf5cd9f..5b3a21d2 100644 --- a/api/application/helpers/photo_pdf_converter_helper.php +++ b/api/application/helpers/photo_pdf_converter_helper.php @@ -13,6 +13,7 @@ class photo_pdf_converter //echo 'this is from daiu'; $CI =&get_instance(); $CI->load->model('PD_Model'); + $CI->load->library('pdfgenerator'); if(!count($pd_master_details)) { diff --git a/api/application/helpers/report_attachments_helper.php b/api/application/helpers/report_attachments_helper.php index 08d7bf20..f8894673 100644 --- a/api/application/helpers/report_attachments_helper.php +++ b/api/application/helpers/report_attachments_helper.php @@ -10,34 +10,36 @@ class report_attachments public function getReportAttchments($pdid,$random_string,$pd_master_details = array()) { - //echo 'this is from daiu'; + // print_r($pd_master_details);die(); $CI =&get_instance(); $CI->load->model('PD_Model'); - $CI->load->helper('photo_pdf_converter'); - $CI->load->helper('photo_zip_creator'); - $CI->load->helper('video_grabber_helper'); + // $CI->load->helper('photo_pdf_converter'); + // $CI->load->helper('photo_zip_creator'); + // $CI->load->helper('video_grabber_helper'); - if(!count($pd_master_details)) - { - $pd_master_details = $CI->PD_Model->getPDMasterDetails($pdid,$random_string); - } - $img_pdf_aws_uri = (new photo_pdf_converter)->covertImgs2PDF($pd_master_details[0]['pd_id'],$pd_master_details[0]['random_string'],$pd_master_details); + $CI->load->helper('url_shortener'); + $uri = url_shortener::url_shorten($pdid,$random_string); + // if(!count($pd_master_details)) + // { + // $pd_master_details = $CI->PD_Model->getPDMasterDetails($pdid,$random_string); + // } + // $img_pdf_aws_uri = (new photo_pdf_converter)->covertImgs2PDF($pd_master_details[0]['pd_id'],$pd_master_details[0]['random_string'],$pd_master_details); - $img_zip_aws_uri = (new photo_zip_creator)->covertImgs2ZIP($pd_master_details[0]['pd_id'],$pd_master_details[0]['random_string'],$pd_master_details); + // $img_zip_aws_uri = (new photo_zip_creator)->covertImgs2ZIP($pd_master_details[0]['pd_id'],$pd_master_details[0]['random_string'],$pd_master_details); - $video_uri = (new video_grabber_helper)->grabAllVideo($pd_master_details[0]['pd_id'],$pd_master_details[0]['random_string'],$pd_master_details); + // $video_uri = (new video_grabber_helper)->grabAllVideo($pd_master_details[0]['pd_id'],$pd_master_details[0]['random_string'],$pd_master_details); // print_r($video_uri) ;die(); - $attachment = '

Data Links

Click here for Image PDF Link

Click here for Image ZIP Link

'; - if($pd_master_details[0]['fk_pd_type'] == 2 && count($video_uri))// if smart pd + $attachment = '

Data Links

Click here for Image PDF Link

Click here for Image ZIP Link

'; + if($pd_master_details[0]['fk_pd_type'] == 2 && count($uri['vdo']))// if smart pd { $attachment .='

videos

'; - foreach ($video_uri as $key => $value) + foreach ($uri['vdo'] as $key => $value) { - $attachment .= '

'.$value['video_name'].'

'; + $attachment .= '

'.$value['video_name'].'

'; } } - $attachment.= '


(Note all links will expire in 7 days from the date of report generation.)

'; + $attachment.= '


(Note all links will expire in 15 days from the date of report generation.)

'; return $attachment; } diff --git a/api/application/helpers/url_shortener_helper.php b/api/application/helpers/url_shortener_helper.php new file mode 100644 index 00000000..0ac10d06 --- /dev/null +++ b/api/application/helpers/url_shortener_helper.php @@ -0,0 +1,51 @@ +load->model('PD_Model'); + + $date_of_creation = date('Ymd'); + $uri = array(); + if($type) + { + $uri[ $type ] = $type.'/'.$date_of_creation.'/'.$pdid.'/'.$random_string; + } + else + { + // echo 'else'; + $query = "SELECT * FROM ".VIDEO_ROOM_INFO." where fk_pd_id = $pdid and isactive = 1"; + $video_info = $CI->db->query($query); + if($video_info && ($video_info->num_rows())) + { + foreach ($video_info->result_array() as $key => $value) + { + $video_name = $value['composition_id']; + $uri['vdo'][$key] = ['url' => custom_encryption::encode( 'vdo/'.$date_of_creation.'/'.$pdid.'/'.$video_name),'video_name' => $video_name]; + + } + } + + $uri[ 'ppdf' ] = custom_encryption::encode ( 'ppdf/'.$date_of_creation.'/'.$pdid.'/'.$random_string); + $uri[ 'zip' ] = custom_encryption::encode ( 'zip/'.$date_of_creation.'/'.$pdid.'/'.$random_string ); + } + // print_r($uri);die(); + return $uri; + + + + } +} + + + +?> \ No newline at end of file