From 78f19dfc5e17efaf09c7638ebb2a4602e83a9b41 Mon Sep 17 00:00:00 2001 From: VE10-Sanjeev Date: Fri, 4 Nov 2022 21:43:09 +0530 Subject: [PATCH] Video Shorts : ps --- api/application/config/routes.php | 4 +- api/application/controllers/PD_Controller.php | 237 ++++++++---------- 2 files changed, 109 insertions(+), 132 deletions(-) diff --git a/api/application/config/routes.php b/api/application/config/routes.php index 43e88e11..dc0af2cd 100755 --- a/api/application/config/routes.php +++ b/api/application/config/routes.php @@ -413,4 +413,6 @@ $route['previewDigiLockerDocs']='Flyhi_Controller/previewDigiLockerDocs'; $route['purge_pddata']='Data_Dump_Controller/renamingExistingPDinfo'; $route['checkjsonPD']='Data_Dump_Controller/checkjsonPD'; -$route['deleteS3Image']='Data_Dump_Controller/deleteS3Images'; \ No newline at end of file +$route['deleteS3Image']='Data_Dump_Controller/deleteS3Images'; + +$route['saveShortsVideo'] = 'PD_Controller/saveShortsVideo'; \ No newline at end of file diff --git a/api/application/controllers/PD_Controller.php b/api/application/controllers/PD_Controller.php index 93624a0d..79224bf8 100644 --- a/api/application/controllers/PD_Controller.php +++ b/api/application/controllers/PD_Controller.php @@ -22,7 +22,7 @@ class PD_Controller extends REST_Controller //class level variable declaration //protected $external_path; - private $photo_names = array('selfie_with_person_met' => array('Person met', '18', 0, 0), 'person_met_id' => array('Person met ID Proof', '18', 0, 0), 'address_proof_visited' => array('Address Proof', '5', 0, 0), 'name_board_seen' => array('Name Board Seen', '13', 0, 0), 'machinery_image' => array('Machinery Image', '22', 0, 0), 'gst_Regn_cert_pic' => array('GST Regn Cert', '13', 0, 0), 'pf_regn_pic' => array('PF Regn', '13', 0, 0), 'esic_regn_pic' => array('ESIC Regn', '13', 0, 0), 'export_import_cert_pic' => array('Export Import Cert', '13', 0, 0), 'factory_cert_pic' => array('Factory Cert', '13', 0, 0), 'shop_eat_act_cert_pic' => array('Shop Est Act Cert', '13', 0, 0), 'eb_bill_pic' => array('EB Bill', '13', 0, 0), 'practice_cert_pic' => array('Cert of Practice', '13', 0, 0), 'fire_noc_pic' => array('Fire NOC', '13', 0, 0), 'stock_image' => array('Stock image', '11', 1, 1), 'client_image' => array('Client Bills', '2', 1, 1), 'supplier_image' => array('Supplier Bills', '1', 1, 1), 'office_setup' => array('Office/Business Setup', '13', 1, 1), 'additional_photos' => array('Additional Photographs', '13', 1, 1),'Video'=>array('Video','18',0,0)); + private $photo_names = array('selfie_with_person_met' => array('Person met', '18', 0, 0), 'person_met_id' => array('Person met ID Proof', '18', 0, 0), 'address_proof_visited' => array('Address Proof', '5', 0, 0), 'name_board_seen' => array('Name Board Seen', '13', 0, 0), 'machinery_image' => array('Machinery Image', '22', 0, 0), 'gst_Regn_cert_pic' => array('GST Regn Cert', '13', 0, 0), 'pf_regn_pic' => array('PF Regn', '13', 0, 0), 'esic_regn_pic' => array('ESIC Regn', '13', 0, 0), 'export_import_cert_pic' => array('Export Import Cert', '13', 0, 0), 'factory_cert_pic' => array('Factory Cert', '13', 0, 0), 'shop_eat_act_cert_pic' => array('Shop Est Act Cert', '13', 0, 0), 'eb_bill_pic' => array('EB Bill', '13', 0, 0), 'practice_cert_pic' => array('Cert of Practice', '13', 0, 0), 'fire_noc_pic' => array('Fire NOC', '13', 0, 0), 'stock_image' => array('Stock image', '11', 1, 1), 'client_image' => array('Client Bills', '2', 1, 1), 'supplier_image' => array('Supplier Bills', '1', 1, 1), 'office_setup' => array('Office/Business Setup', '13', 1, 1), 'additional_photos' => array('Additional Photographs', '13', 1, 1),'video'=>array('Video','34',0,0)); private $existing_imges = array(); function __construct() @@ -810,7 +810,7 @@ class PD_Controller extends REST_Controller if (count($docs_to_be_collected)) { foreach ($docs_to_be_collected as $pd_doc_key => $pd_doc_requirement) { - if ($pd_doc_requirement['pd_doc_to_be_collect_id'] != null || $pd_doc_requirement['pd_doc_to_be_collect_id'] != "" && ($docs_to_be_collect['doc_name'] != null)) { + if ($pd_doc_requirement['pd_doc_to_be_collect_id'] != null || $pd_doc_requirement['pd_doc_to_be_collect_id'] != "" && ($pd_doc_requirement['doc_name'] != null)) { $where_condition_array = array('pd_doc_to_be_collect_id' => $pd_doc_requirement['pd_doc_to_be_collect_id']); $pk_id = $this->PD_Model->updateRecords($pd_doc_requirement, PDDOCSTOBECOLLECTED, $where_condition_array); if ($pk_id != "" || $pk_id != null) { @@ -8495,41 +8495,6 @@ class PD_Controller extends REST_Controller // for business related images $company_id = null; - if(isset($records['content_type']) && $records['content_type'] == 2){ - // echo "VT".$records['content_type']; - log_message('ERROR', '### PD VIDEO called ; type = ' . $records['content_type']); - $img_array['pd_image_alias_name'] = isset($records['pd_image_alias_name']) ? $records['pd_image_alias_name'] : null; - $img_array['image_key'] = $records['image_key']; - $img_array['link'] = isset($records['link']) ? $records['link'] : null; - $img_array['image'] = $records['image']; - $img_array['Name'] = isset($records['name']) ? $records['name'] : $records['image_key']; - $img_array['content_type'] = isset($records['content_type']) ? $records['content_type'] : null; - if($records['image']){ - $where_condition_array = array('fk_pd_id' => $records['fk_pd_id'], 'fk_form_id' => $records['fk_form_id'], 'image_key' => $records['image_key']); - if (isset($records['pd_document_id']) && isset($records['retake_flag']) && $records['retake_flag']) { - $where_condition_array = array('pd_document_id' => $records['pd_document_id']); - unset($records['pd_document_id']); - unset($records['retake_flag']); - $to_update = array('isactive' => 0, 'retake_flag' => 0); - } else if (isset($records['pd_document_id']) && $records['pd_document_id'] != null && $records['pd_document_id'] != "" && $records['image'] == "") { - $where_condition_array = array('pd_document_id' => $records['pd_document_id']); - $to_update = array("pd_image_alias_name" => $records['pd_image_alias_name']); - } else { - $to_update = array('isactive' => 0, 'retake_flag' => 0); - } - // print_r($to_update); - // print_r($where_condition_array); - $update = $this->PD_Model->updateRecords($to_update, PDDOCUMENTS, $where_condition_array); - log_message('ERROR', '### PD VIDEO exist-update ' . $update); - // $res = 1; - $res = $this->saveBase64Video($records['fk_pd_id'], ($records['fk_form_id'] ? $records['fk_form_id'] : null), array($img_array)); - }else{ - log_message('ERROR', '### PD VIDEO Not Saved. Due to Base64 Format Missing'); - $res['status'] = true; - $res['msg'] = "Video Not Saved. Due to Base64 Format Missing."; - } - }//Video Type End Here content type = 2 - else{ if ($records['image_key'] == 'selfie_with_person_met' || $records['image_key'] == 'person_met_id') { //get main applicant name $main_applicant_name = $this->PD_Model->selectCustomRecords(array('fk_pd_id', 'applicant_name', 'pd_co_applicant_id','facemark_image_generated'), array('fk_pd_id' => $records['fk_pd_id'], 'applicant_type' => 1), PDAPPLICANTSDETAILS); @@ -8625,7 +8590,6 @@ class PD_Controller extends REST_Controller if ($records['image'] != "") { $res = $this->saveBase64Images($records['fk_pd_id'], ($records['fk_form_id'] ? $records['fk_form_id'] : null), $company_id, $rental_count_id = null, array($img_array)); } - }//Image Type End Here content type = 1 if ($res) { $data['dataStatus'] = true; @@ -8874,6 +8838,13 @@ class PD_Controller extends REST_Controller // unset($this->photo_names['selfie_with_person_met']); // return $arr; } + else if ($current_img_key == 'video' && strpos($value['pd_document_title'], 'Video') !== false) { + $arr = array('img_key' => 'Video', 'img_name' => $this->photo_names['video'][0], 'img_url' => $value['doc_url'], 'fk_form_id' => $this->photo_names['video'][1], 'is_multiple' => 0, 'pd_document_id' => $value['pd_document_id'], 'pd_image_alias_name' => $value['pd_image_alias_name'], 'is_name_editable' => $this->photo_names['video'][3]); + unset($this->existing_imges[$key]); + return $arr; + // unset($this->photo_names['selfie_with_person_met']); + // return $arr; + } // else // { // //unset($this->existing_imges[$key]); @@ -9025,6 +8996,103 @@ class PD_Controller extends REST_Controller } } + public function saveShortsVideo_post() + { + log_message('ERROR', "saveShortsVideo FNS called"); + $records = json_decode($this->post('records'), true); + $file_folder = "pd_reports"; + if (!empty($_FILES['video_file'])) { + $form_id = $records['form_id']; + $pd_id = $records['pd_id']; + $pd_master_details = $this->PD_Model->getPDMasterDetails($pd_id); + if(isset($records['filename']) && $records['filename'] !=""){ + $temp_file_name = $records['filename']; + }else{ + //Generate Random File Name + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < 5; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + $temp_file_name = $randomString . date('Y-m-d-H-i-s') . '.mp4'; + + } + log_message('ERROR', "filename = ".$temp_file_name); + $lender_id = $pd_master_details[0]['fk_lender_id']; + $bucketname = LENDER_BUCKET_NAME_PREFIX . $lender_id; + $key = 'pd' . $records['pd_id'] . '/video/' . $temp_file_name; + log_message('ERROR', "bucket key = ".$bucketname); + $file_name_wo_extension = explode('.', ($temp_file_name))[0]; + log_message('ERROR', "file_name_extension = ".$file_name_wo_extension); + $file_type = explode('/', ($_FILES['video_file']['type']))[1]; + log_message('ERROR', "file_type ".$file_type); + $folder_to_check = XLPATH . '/' . $file_folder . '/' . $records['pd_id'] . '/videos'; + // echo $folder_to_check;//die(); + if (!file_exists($folder_to_check)) { + mkdir(XLPATH . '/' . $file_folder . '/' . $records['pd_id'], 0777); + mkdir($folder_to_check, 0777); + } + + $config = array('upload_path' => $folder_to_check, 'overwrite' => TRUE, 'allowed_types' => '*', 'file_name' => $file_name_wo_extension . '.' . $file_type); + $this->load->library('upload', $config); + if ($this->upload->do_upload('video_file')) { + $upload_data = $this->upload->data(); + $command_to_execute = FFMPEG_PATH . ' -i ' . $folder_to_check . '/' . $file_name_wo_extension . '.' . $file_type . ' ' . $folder_to_check . '/' . $file_name_wo_extension . '.mp4' . ' 2>&1'; + + exec($command_to_execute, $o, $v); + if ($o) { + $sourcefile = $folder_to_check . '/' . $file_name_wo_extension . '.mp4'; + + $bucket_data = array('bucket_name' => $bucketname, 'key' => $key, 'sourcefile' => $sourcefile); + $s3result = $this->aws_s3->uploadFileToS3Bucket($bucket_data); + // print_r($s3result); + if (is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) { + $uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname, $key, $time = '+1 week'); + log_message('ERROR', '###PD SHORTS VIDEO stored in S3 uri = ' . $uri); + unlink($folder_to_check . '/' . $file_name_wo_extension . '.webm'); + unlink($folder_to_check . '/' . $file_name_wo_extension . '.mp4'); + $record_data = array('fk_pd_id' => $pd_id, 'pd_document_title' => 'Video', 'pd_document_name' => $temp_file_name, 'fk_form_id' => $form_id, 'is_show_report' => 1, 'rental_count_id' => null, 'location' => null, 'co_applicant_id' => null, 'img_type' => null, 'image_key' => "video", "pd_image_alias_name" => null,"content_type"=>2); + $record_data['company_id'] = null; + $id = $this->PD_Model->saveRecords($record_data, PDDOCUMENTS); + if ($id != null || $id != "") { + $pks['id'] = $id; + $pks['uri'] = $uri; + } + } + + + if ($id != null || $id != "") { + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['msg'] = 'Video Saved Successfully'; + $data['records'] = $pks; + $this->response($data, REST_Controller::HTTP_OK); + } else { + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NOT_FOUND; + $data['msg'] = 'Something Wrong. Try Later!'; + $this->response($data, REST_Controller::HTTP_OK); + } + } else { + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NOT_FOUND; + $data['msg'] = 'Something Wrong. Try Later!'; + $this->response($data, REST_Controller::HTTP_OK); + } + } else { + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NOT_FOUND; + $data['msg'] = 'Something Wrong. Try Later!'; + $this->response($data, REST_Controller::HTTP_OK); + } + } else { + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NOT_FOUND; + $data['msg'] = 'No Video found to upload'; + $this->response($data, REST_Controller::HTTP_OK); + } + } //merge all splitted videos public function getVideoURL_post() @@ -10782,98 +10850,5 @@ class PD_Controller extends REST_Controller } } - public function saveBase64Video($pd_id, $form_id = null, $data) - { - log_message('ERROR', '### PD 30`s Video function called' . $pd_id . ' - ' . $form_id); - $count = 0; - $result = array(); - $pks = array(); - $uri = null; - $pd_details = $this->PD_Model->getPDMasterDetails($pd_id); - //print_r($data);die(); - EXTERNAL_DIR_CHECK::checkExternalDirectory($pd_id); - foreach ($data as $iter => $doc) { - //make location for water mark helper function - // $this->location_for_watermark = $doc['link']; - - - $temp_base64_string = $doc['image']; - $title = $doc['Name']; - $is_show_report = isset($doc['is_show_report']) ? $doc['is_show_report'] : null; - - //echo $title.'-'.$is_show_report;die(); - $img_type = isset($doc['img_type']) ? $doc['img_type'] : null; - $output_file = $this->external_path . "/pd_reports/" . $pd_id . "/temp_base64_video.mp4"; - // $this->temp_path_for_watermark = $output_file; - - //Generate Random File Name - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $charactersLength = strlen($characters); - $randomString = ''; - for ($i = 0; $i < 5; $i++) { - $randomString .= $characters[rand(0, $charactersLength - 1)]; - } - $temp_file_name = $randomString . date('Y-m-d-H-i-s') . '.mp4'; - - log_message('ERROR', '### PD VDO writing started' . $pd_id . ' - ' . $form_id); - $ifp = fopen($output_file, 'wb'); - $temp_data = explode(',', $temp_base64_string); - fwrite($ifp, base64_decode($temp_data[1])); - fclose($ifp); - log_message('ERROR', '### PD VDO writing done' . $pd_id . ' - ' . $form_id); - - - // //###########end of image water marking with logo - log_message('ERROR', '### PD VDO uploading to S3' . $pd_id . ' - ' . $form_id); - $tempdoc = $output_file; - $tempdocname = $temp_file_name; - $bucketname = LENDER_BUCKET_NAME_PREFIX . $pd_details[0]['fk_lender_id']; - $key = 'pd' . $pd_id . '/' . $tempdocname; - // if($form_id != null) - // { - // $key = 'pd'.$pd_id.'/'.'form'.$form_id.'/'.$tempdocname; - // } - $sourcefile = $tempdoc; - - $bucket_data = array('bucket_name' => $bucketname, 'key' => $key, 'sourcefile' => $sourcefile); - - //this line make this bucket data values in obj level so can access in helpers and hook files - // $this->bucket_data_for_watermark = $bucket_data; - $s3result = $this->aws_s3->uploadFileToS3Bucket($bucket_data); - - if (is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) { - log_message('ERROR', '### PD VDO stored in S3' . $pd_id . ' - ' . $form_id); - // $record_data = array('fk_pd_id' => $pd_id,'pd_document_title'=>$title,'pd_document_name'=>$tempdocname,'fk_form_id'=>$form_id,'is_show_report' =>$is_show_report,'rental_count_id' => $rental_count_id,'location' => isset($doc['link']) ? $doc['link'] : null,'co_applicant_id' => $co_applicant_id,'img_type' => $img_type,'image_key' => (isset($doc['image_key']) ? $doc['image_key'] : null)); - $record_data = array('fk_pd_id' => $pd_id, 'pd_document_title' => $title, 'pd_document_name' => $tempdocname, 'fk_form_id' => $form_id, 'is_show_report' => $is_show_report, 'rental_count_id' => null, 'location' => isset($doc['link']) ? $doc['link'] : null, 'co_applicant_id' => null, 'img_type' => $img_type, 'image_key' => (isset($doc['image_key']) ? $doc['image_key'] : null), "pd_image_alias_name" => (isset($doc['pd_image_alias_name']) ? $doc['pd_image_alias_name'] : null),"content_type"=>(isset($doc['content_type']) ? $doc['content_type'] : null)); - $record_data['company_id'] = null; - $id = $this->PD_Model->saveRecords($record_data, PDDOCUMENTS); - if ($id != null || $id != "") { - $count++; - $pks[] = $id; - } - $uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname, $key, $time = '+1 week'); - - // $this->img_url_for_watermark = $uri; - //print_r($uri); - } - } - - if ($count == count($data)) { - //$logger->info('All Images Saved Sucessfully',array($pd_id,$form_id,$company_id)); - $result['status'] = true; - $result['count'] = $count; - $result['pks'] = $pks; - $result['records'] = $uri; - $result['msg'] = "Video Saved Successfully"; - } else { - //$logger->info('Some Images Not Saved',array($pd_id,$form_id,$company_id)); - $result['status'] = true; - $result['count'] = $count; - $result['pks'] = $pks; - $result['msg'] = "Video Not Saved!"; - } - return $result; - } - }