sparqapi/api/application/helpers/video_grabber_helper.php
2023-04-05 16:01:14 +05:30

91 lines
3.3 KiB
PHP

<?php
class video_grabber_helper
{
protected $CI = '';
function __construct()
{
//$CI =&get_instance();
}
public function grabAllVideo($pdid,$random_string,$pd_master_details = array(),$pd_category)
{
$CI =&get_instance();
// $CI->load->helper('url_shortener');
if(!count($pd_master_details))
{
if($pd_category == '2'){
$pd_master_details = $CI->PD_Model->selectCustomRecords(array('sales_pd_id as pd_id', 'lender_id as fk_lender_id', 'product_id', 'sales_pd_type','isactive', 'rand_string as random_string', 'pd_branch_id'),array('sales_pd_id' => $pd_id,'rand_string'=>$random_string),SALES_PD_DATA);}
if($pd_category == '1'){
$pd_master_details = $CI->PD_Model->getPDMasterDetails($pd_id,$random_string);}
}
// $bucket_name = LENDER_BUCKET_NAME_PREFIX.$pd_master_details[0]['fk_lender_id'];
$bucket_name = TWILIO_CONTENT_BUCKET_NAME;
$result_data = array();
$query = "SELECT * FROM ".VIDEO_ROOM_INFO." where fk_pd_id = $pdid and isactive = 1 and pd_category = $pd_category";
$video_info = $CI->db->query($query);
// print_r($video_info->result_array());die();
if($video_info->num_rows())
{
$video_info = $video_info->result_array();
$date_of_creation = date('Ymd');
// $uri = url_shortener::url_shorten($pdid,$random_string);
//print_r($video_info);die();
foreach ($video_info as $key => $value)
{
$video_name = $value['composition_id'].'.mp4';
if($value['is_uploaded'] || $value['vsp'] == 'google'){$video_name = $value['composition_id'];}
$file_name = $video_name;
if($value['s3_copied'])
{
// $final_key = 'pd'.$pd_master_details[0]['pd_id'].'/video/'.$file_name;
$final_key = $file_name;
$singed_uri = $CI->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$final_key,'+7 days');
$shortURL = VIDEO_SHORT_URL . substr($video_name,0,6);
if($value['short_link_created_date'] == NULL)//make short url entry in links file
{
$localEncryptedURL = PDF_ATTACHEMENT_URL . custom_encryption::encode( 'vdo/'.$date_of_creation.'/'.$pdid.'/'.$value['composition_id']);
$file = "/data/web/shortlink/links.txt";
$concatinated_url = substr($video_name,0,6)." ". $localEncryptedURL;
$myfile = file_put_contents($file, $concatinated_url.PHP_EOL , FILE_APPEND | LOCK_EX);
//update short_link_created_date in DB
$CI->db->where('video_room_info_id =',$value['video_room_info_id']);
$CI->db->update(VIDEO_ROOM_INFO, array('short_link_created_date' => date('Y-m-d H:i:s')));
}
$result_data[] = array('video_name' => $video_name,'s3_url' => $singed_uri,'url'=>$singed_uri,'status' => $value['twilo_status'],'room_id' => $value['room_id'],'id' => $value['video_room_info_id'],'shorturl' => $shortURL);
}
else
{
$result_data[] = array('video_name' => $video_name, 's3_url' => '','url'=>'','status' =>'processing','room_id' => $value['room_id'],'id' => $value['video_room_info_id']);
}
}
}
return $result_data;
}
public function deleteVideo($id)
{
$CI =&get_instance();
$updateRows = array('isactive' => 0);
$CI->db->where('video_room_info_id =',$id);
$CI->db->update(VIDEO_ROOM_INFO, $updateRows);
$affectedRows = $CI->db->affected_rows();
return (($affectedRows > 0 ) ? "Deleted successfully" : "Fail to Delete");
}
}
?>