Merge branch 'master' of bitbucket.org:venbaittech/sparqapi

This commit is contained in:
VE10-Sanjeev 2022-05-24 18:59:46 +05:30
commit cb529ab4ad
8 changed files with 371 additions and 121 deletions

View File

@ -25,13 +25,11 @@
"guzzlehttp/guzzle": "^6.3",
"twilio/sdk": "^6.10",
"phpoffice/phpspreadsheet": "^1.15",
"johnathanmiller/secure-env-php": "^2.0"
"johnathanmiller/secure-env-php": "^2.0",
"google/apiclient": "^2.0"
},
"suggest": {
"paragonie/random_compat": "Provides better randomness in PHP 5.x"
},
"require-dev": {
}
}

View File

@ -354,6 +354,7 @@ $route['awsrek/(:any)'] = 'Test/testAwsrek';
$route['optimizeImages/(:num)'] = 'PD_Controller/optimizeImages';
$route['downloadSMCExcelFile/(:num)'] = 'PD_Controller/downloadSMCExcelFile';
$route['compareFaces'] = 'Test/compareFaces';
$route['updateGoogleVideoStatus'] = 'Test/updateGoogleVideoStatus';
$route['googleSheet'] = 'Data_Dump_Controller/googleSheet';
@ -362,8 +363,13 @@ $route['sendNotificationToOfficers'] = 'PD_Controller/sendNotificationToOfficers
$route['getMasterForDataDump'] = 'Request_DataDump_Controller/getMasterForDataDump';
$route['getRequestForDataDump'] = 'Request_DataDump_Controller/getRequestForDataDump';
$route['addgoogleCalenderEvent'] = 'GC_Event_Controller/addGoogleCalenterEvent';//dummy checking purpose
$route['getEventList'] = 'GC_Event_Controller/getGoogleCalenderEventList';//dummy checking purpose
$route['getEvent'] = 'GC_Event_Controller/getEventFromGoogleCalender';//dummy checking purpose
$route['createGmeetLink'] = 'PD_Controller/createGmeetLink'; //only developer testing, not for APP use
$route['deleteCalenderEvent'] = 'PD_Controller/deleteCalenderEvent'; //only developer testing, not for APP use
$route['GC_addEvent'] = 'GC_Event_Controller/addEvent';
$route['GC_eventList'] = 'GC_Event_Controller/eventList';
$route['getSalesPDReportforCETApp'] = 'Sales_PD_Controller/getSalesPDReportforCETApp';
$route['getCreditPDReportforCETApp'] = 'SMC_Credit_PD_Controller/getCreditPDReportforCETApp';
$route['getCreditPDReportforCETApp'] = 'SMC_Credit_PD_Controller/getCreditPDReportforCETApp';

View File

@ -7,93 +7,51 @@
defined('BASEPATH') OR exit('No direct script access allowed');
require_once APPPATH . '/libraries/REST_Controller.php';
require APPPATH . 'vendor/autoload.php';
//require APPPATH . 'vendor/autoload.php';
class GC_Event_Controller extends REST_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('GC_Event_Model');
$this->load->library('Googleapi');
}
public function addEvent_post()
public function addGoogleCalenterEvent_post()
{
log_message('ERROR','#/# G-Calender-Event Fns Entered');
// log_message('ERROR','#/# G-Calender-Event Fns Entered');
$post = $this->post();
$data = array();
$valErr = "";
if(!empty($post)){
if(empty($post['title'])){
$valErr .= 'event title is Empty.<br/>';
}
if(empty($post['date'])){
$valErr .= 'event date is Empty.<br/>';
}
$event = array(
// 'title' =>$title,
'title' => !empty($post['title'])?trim($post['title']):'Con Call - 1',
'location' => !empty($post['location'])?trim($post['location']):'Perambalur',
'summary' => !empty($post['summary'])?trim($post['summary']):'Google meet link',
'start' => !empty($post['time_from'])?trim($post['time_from']):'10:30',
'end' => !empty($post['time_to'])?trim($post['time_to']):'17:00',
'description' => !empty($post['description'])?trim($post['description']):'Generated By Sanjeev',
'date' => !empty($post['date'])?date_format($date,"Y-m-d"):date('Y-m-d')
'start' => !empty($post['start'])?trim($post['start']):'10:30',
'end' => !empty($post['end'])?trim($post['end']):'17:00',
'pdid' => !empty($post['pdid'])?trim($post['pdid']):'17:00'
);
log_message('ERROR',"GC-Event data : ".json_encode($event));
if(empty($valErr)){
$event = $this->GC_Event_Model->addEvent($event);
if(!empty($event['id'])){
log_message('ERROR','GC-Event Created - ID :'.$event);
$statusMsg = 'Events created';
}else{
log_message('ERROR','GC-Event Not Created issues on Insert');
$statusMsg = 'Something went wrong, please try again after some time.';
}
}else{
log_message('ERROR','GC-Event Not Created because of mandatory fields - '.trim($valErr, '<br/>'));
$statusMsg = '<p>Please fill all the mandatory fields:</p>'.trim($valErr, '<br/>');
}
}else{
log_message('ERROR','GC-Event Data Not Available');
$statusMsg = 'Data Not Available.';
}
$data = $this->googleapi->addGoogleCalenterEvent($event);
$this->response($data,REST_Controller::HTTP_OK);
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$data['msg'] = $statusMsg;
$this->response($data,REST_Controller::HTTP_OK);
}
public function eventList_get()
public function getGoogleCalenderEventList_get()
{
log_message('ERROR','#/# G-Calender-Event List');
$get = $this->get();
if($get){
$data = ($this->googleapi->getEventListFromGoogleCalender());
$this->response($data,REST_Controller::HTTP_OK);
$start = $get['start'].' 00:00:00';
}
$end = $get['end'].' 23:59:59';
$data['msg'] = 'Events of between '.$get['start']." and ".$get['end'];
} else {
$start = false;
$end = false;
$data['msg'] = 'Events of today';
}
$data['events'] = $this->GC_Event_Model->getEvents('primary', $start, $end, 40);
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
$this->response($data,REST_Controller::HTTP_OK);
public function getEventFromGoogleCalender_get()
{
$eventId = $this->get('eventid');// = '112e17c49k57uni51qp8l7gf18'
$data = ($this->googleapi->getGoogleCalenderEvent($eventId));
$this->response($data,REST_Controller::HTTP_OK);
}

View File

@ -792,6 +792,11 @@ class PD_Controller extends REST_Controller {
/****************END OF ADDTIONAL REQUIREMENTS SECTION*******************************************/
//create gmeet link
if($pd_id != null && $pd_id != '' && ($pd_details['fk_pd_type'] == 2 || $pd_details['fk_pd_type'] == 3))
{
$this->createGmeetLink($pdid);
}
if($pd_id != null || $pd_id != '' && $count != 0)
{
@ -1046,6 +1051,10 @@ class PD_Controller extends REST_Controller {
if((isset($pd_details['pd_status']) && $pd_details['pd_status'] == QC_COMPLETED))
{
$pd_details['is_cus_link_disabled'] = 1;
//call delete google calender event
$this->deleteCalenderEvent($exist_pd_details[0]['gmeet_id']);
}
if(isset($pd_details['pd_status']) && ($pd_details['pd_status'] == TRIGGERED || $pd_details['pd_status'] == INITIATED || $pd_details['pd_status'] == INPROGRESS))
@ -10247,7 +10256,7 @@ public function getCompaniesListsFromGeneralFormRawJSONV2_post()
foreach ($video_info as $key => $value)
{
if($value['composition_id'])
if($value['composition_id'] && $value['vps'] != 'google')
{
$res = $this->twlio->getCompositionStatus($value['composition_id']);
//echo $res['status'];
@ -11872,7 +11881,53 @@ public function getCompaniesListsFromGeneralFormRawJSONV2_post()
}
}
$this->response($data,REST_Controller::HTTP_OK);
}
}
/****
create gmeet link for smart and tele pd and update it in pd trigger table
*/
// function createGmeetLink_get()
function createGmeetLink($pdid)
{
// $pdid = $this->get('pdid');
$this->load->library('Googleapi');
$pd_details = $this->PD_Model->getPDMasterDetails($pdid);
$event = array(
'summary' => 'PD for case -'.$pd_details[0]['pd_sno'].' & Applicant ID - '.$pd_details[0]['lender_applicant_id'],
'start' => Date('Y-m-d'),
'end' => Date('Y-m-d'),
'pdid' => $pdid,
);
$event_data = $this->googleapi->addGoogleCalenterEvent($event);
if(is_object($event_data))
{
$meet_code = isset($event_data['conferenceData']['conferenceId']) ? $event_data['conferenceData']['conferenceId'] : null;
$meet_id = isset($event_data['id']) ? $event_data['id'] : null;
$where_condition_array = array('pd_id' => $pdid);
$this->PD_Model->updateRecords(['gmeet_code' => $meet_code,'gmeet_id' => $meet_id],PDTRIGGER,$where_condition_array);
}
}
/****
delete Calender Event from google calender
*/
// function deleteCalenderEvent_get()
function deleteCalenderEvent($eventID)
{
// $eventID = $this->get('eventID');
$this->load->library('Googleapi');
$event_data = $this->googleapi->deleteGoogleCalenderEvent($eventID);
}
// public function facemark_get(){
public function toMakeFaceBoundingBox($master_details){
// $pdid = $this->get('pd');//pdid 3184 comment this
@ -11939,4 +11994,5 @@ public function getCompaniesListsFromGeneralFormRawJSONV2_post()
}
}

View File

@ -8,8 +8,9 @@ class Test extends REST_Controller {
*/
function __Construct(){
parent::__Construct();
$this->external_path = $this->config->item('external_data_path');
$this->load->helper(array('form', 'url'));
//$this->load->model('test_model');
$this->load->model('PD_Model');
$this->load->library('asynclibrary');
$this->load->library('AWS_REKONITION');
$this->load->helper('MYUTIL');
@ -133,6 +134,9 @@ class Test extends REST_Controller {
// echo '***********************';
}
}
//update face api result in main table
$where_condition_array = array('pd_id' => $pd_id);
$this->PD_Model->updateRecords(['faceapi_result' => json_encode($res_data)],PDTRIGGER,$where_condition_array);
//delete local files if created
if($dest_url_type == 'base64')
@ -145,4 +149,63 @@ class Test extends REST_Controller {
}
$this->response($res_data,REST_Controller::HTTP_OK);
}
function handleGoolgeVideoFile($file,$pd_details)
{
$file_content = $this->googleapi->downloadDriveFile($file['id']);
if($file_content)
{
//store locally
$is_downloaded = file_put_contents($this->external_path.'/pd_reports/'.$pd_details[0]['pd_id'].'/'.$file['id'].'.mp4',$file_content);
$bucketname = LENDER_BUCKET_NAME_PREFIX.$pd_details[0]['fk_lender_id'];
// $bucketname = LENDER_BUCKET_NAME_PREFIX.'1';
$key = 'pd'.$pd_details[0]['pd_id'].'/video/'.$file['id'].'.mp4';
$bucket_data = array('bucket_name'=>$bucketname,'key'=>$key,'sourcefile'=>($this->external_path.'/pd_reports/'.$pd_details[0]['pd_id'].'/'.$file['id'].'.mp4'));
$s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data);
if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200)
{
$record_data = array('fk_pd_id' => $pd_details[0]['pd_id'],'composition_id' => $file['id'].'.mp4','is_call_ended' => 1,'twilo_status'=>'completed','s3_copied' => 1,'vsp' => 'google');
$this->PD_Model->saveRecords($record_data,VIDEO_ROOM_INFO);
//echo 'done';
unlink($this->external_path.'/pd_reports/'.$pd_details[0]['pd_id'].'/'.$file['id'].'.mp4');
$file_content = $this->googleapi->deleteDriveFile($file['id']);
}
}
}
function updateGoogleVideoStatus_get()
{
$this->load->library('Googleapi');
$pdid = $this->get('pdid');
$pd_details = $this->PD_Model->getPDMasterDetails($pdid);
if(($pd_details[0]['fk_pd_type'] == 2 || $pd_details[0]['fk_pd_type'] == 3) && $pd_details[0]['gmeet_code'] != "")
{
$driveFilesList = $this->googleapi->getDriveFilesList($pd_details[0]['gmeet_code']);
if(count($driveFilesList))
{
foreach ($driveFilesList as $key => $file)
{
$this->handleGoolgeVideoFile($file,$pd_details);
}
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
// $data['msg'] = 'Officers Records Not Found!';
$this->response($data,REST_Controller::HTTP_OK);
}
else
{
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
// $data['msg'] = 'Officers Records Not Found!';
$this->response($data,REST_Controller::HTTP_OK);
}
}
}
}

View File

@ -2,66 +2,234 @@
/**
* @package Google API : Google Client API
*
* @author TechArise Team
* @author Velz
*
* @email info@techarise.com
*
* Description of Contact Controller
*/
if (!defined('BASEPATH'))
exit('No direct script access allowed');
include_once APPPATH.'/vendor/autoload.php';
// use Google\Service\Calendar\Event;
// use Google\Service\Calendar\EventDateTime;
class Googleapi
{
/**
* Googleapi constructor.
*/
public function __construct() {
// load google client api
require_once BASH_PATH.'vendor/autoload.php';
private $client;
private $calender;
private $drive;
function __construct()
{
$this->client = new Google_Client();
$this->client->setApplicationName('Learning Gmeet Event in Php');
$this->ci =& get_instance();
$this->ci->config->load('calendar');
$this->client->setClientId($this->ci->config->item('client_id'));
$this->client->setClientSecret($this->ci->config->item('client_secret'));
// $this->client->setRedirectUri($this->ci->config->base_url().'gc/auth/oauth');
$this->client->addScope(Google_Service_Calendar::CALENDAR);
$this->client->addScope('profile');
$this->client->setApplicationName('GmeetPOC App');
$this->client->setScopes(Google_Service_Calendar::CALENDAR_EVENTS);
$this->client->setAuthConfig($_SERVER['DOCUMENT_ROOT'].'/env/pdgenie_credentials.json');
// $this->client->setDeveloperKey('AIzaSyBFuekMZZFvQFdA4I1GLTMgYUg1vMqRR0Q');
$this->client->setAccessType('offline');
// $this->client->setPrompt('select_account consent');
// Load previously authorized token from a file, if it exists.
// The file token.json stores the user's access and refresh tokens, and is
// created automatically when the authorization flow completes for the first
// time.
$tokenPath = $_SERVER['DOCUMENT_ROOT'].'/env/pdgenie_token.json';
if (file_exists($tokenPath)) {
$accessToken = json_decode(file_get_contents($tokenPath), true);
$this->client->setAccessToken($accessToken);
}
// If there is no previous token or it's expired.
if ($this->client->isAccessTokenExpired()) {
// Refresh the token if possible, else fetch a new one.
if ($this->client->getRefreshToken()) {
$this->client->fetchAccessTokenWithRefreshToken($this->client->getRefreshToken());
} else {
// Request authorization from the user.
$authUrl = $this->client->createAuthUrl();
echo "Open the following link in your browser:\n%s\n", $authUrl;
print 'Enter verification code: ';
$authCode = trim(fgets(STDIN));
// Exchange authorization code for an access token.
$accessToken = $this->client->fetchAccessTokenWithAuthCode($authCode);
$this->client->setAccessToken($accessToken);
// Check to see if there was an error.
if (array_key_exists('error', $accessToken)) {
throw new Exception(join(', ', $accessToken));
}
}
// Save the token to a file.
if (!file_exists(dirname($tokenPath))) {
mkdir(dirname($tokenPath), 0700, true);
}
file_put_contents($tokenPath, json_encode($this->client->getAccessToken()));
}
// return //$this->client;
//create new calender service
$this->calender = new Google_Service_Calendar($this->client);
$this->drive = new Google_Service_Drive($this->client);
}
public function loginUrl() {
return $this->client->createAuthUrl();
public function getEventListFromGoogleCalender()
{
$optParams = array(
'maxResults' => 25,
'orderBy' => 'startTime',
'singleEvents' => true,
// 'timeMin' => $timeMin,
// 'timeMax' => $timeMax,
//'timeZone' => 'Asia/Kolkata',
);
$events_list = $this->calender->events->listEvents('primary', $optParams);
$result = [];
if(count($events_list))
{
foreach ($events_list as $key => $event) {
$result[($key+1)]['id'] = $event->getId();
$result[($key+1)]['summary'] = $event->getSummary();
$result[($key+1)]['description'] = $event->getDescription();
// $result[($key+1)]['creator'] = $event->getCreator();
// $result[($key+1)]['start'] = $event->getStart()->dateTime;
// $result[($key+1)]['end'] = $event->getEnd()->dateTime;
$result[($key+1)]['gmeetlink'] = $event->getHangoutLink();
// $result[($key+1)]['link'] = $event->getHtmlLink();
}
return $result;
}
else
{
return $result;
}
}
public function getAuthenticate() {
return $this->client->authenticate();
public function getGoogleCalenderEvent($eventId)
{
try
{
$event = $events_list = $this->calender->events->get('primary', $eventId);
return $event;
}
catch(Exception $e) {
//echo 'Message: ' .$e->getMessage();
return [];
}
}
public function getAccessToken() {
return $this->client->getAccessToken();
public function addGoogleCalenterEvent($eventdata)
{
// $eventObj = new Event();//cast('A',$b);
// $eventTimeObj = new EventDateTime();//cast('A',$b);
// $eventTimeObj->setDateTime('2022-05-21T00:00:00');
// $eventTimeObj->setTimeZone('Asia/Kolkata');
// $eventObj->setSummary($eventdata['summary']);
// $eventObj->setStart($eventTimeObj);
// $eventObj->setEnd($eventTimeObj);
$event = new Google_Service_Calendar_Event(array(
'summary' => $eventdata['summary'],
'location' => 'Online',
'description' => '',
'start' => array(
'dateTime' => $eventdata['start'].'T00:00:00',
'timeZone' => 'Asia/Kolkata',
),
'end' => array(
'dateTime' => $eventdata['end'].'T00:00:00',
'timeZone' => 'Asia/Kolkata',
),"conferenceData" => [
"createRequest"=> [
"requestId" => $eventdata['pdid'].'_'.$eventdata['start'].'-'.rand()]]
));
try
{
$event = $this->calender->events->insert('primary',$event,['conferenceDataVersion' => 1]);
return $event;
}
catch(Exception $e) {
echo 'Message: ' .$e->getMessage();
return [];
}
}
public function setAccessToken() {
return $this->client->setAccessToken();
public function deleteGoogleCalenderEvent($eventId)
{
try
{
$event = $events_list = $this->calender->events->delete('primary', $eventId);
return $event;
}
catch(Exception $e) {
//echo 'Message: ' .$e->getMessage();
return [];
}
}
public function revokeToken() {
return $this->client->revokeToken();
public function getDriveFilesList($gmeet_code)
{
$filter = ['q' => "mimeType='video/mp4' and name contains '".$gmeet_code."'"];
try
{
$files = $this->drive->files->listFiles($filter);
if(count($files->getFiles()))
{
// echo count($files->getFiles());
$res = [];
foreach($files->getFiles() as $key => $file)
{
$res[($key+1)]['id'] = $file->getId();
$res[($key+1)]['name'] = $file->getName();
$res[($key+1)]['type'] = $file->getMimeType();
}
return $res;
}
return [];
}
catch(Exception $e) {
//echo 'Message: ' .$e->getMessage();
return [];
}
}
public function client() {
return $this->client;
public function downloadDriveFile($fileID)
{
$files = $this->drive->files->get($fileID,['alt' => 'media']);
if($files->getStatusCode() == 200)
{
return $files->getBody();
}
return false;
// echo $files->getStatusCode();
// echo $files->getContentType();
// $files = file_put_contents(__DIR__.'/temp',$files->getBody());
}
public function getUser() {
$google_ouath = new Google_Service_Oauth2($this->client);
return (object)$google_ouath->userinfo->get();
}
public function isAccessTokenExpired() {
return $this->client->isAccessTokenExpired();
public function deleteDriveFile($fileID)
{
$files = $this->drive->files->delete($fileID);
return true;
// echo $files->getStatusCode();
// echo $files->getContentType();
// $files = file_put_contents(__DIR__.'/temp',$files->getBody());
}
}
?>

View File

@ -44,14 +44,14 @@ class GC_Event_Model extends SPARQ_Model {
'maxResults' => $maxResults,
'orderBy' => 'startTime',
'singleEvents' => true,
'timeMin' => $timeMin,
'timeMax' => $timeMax,
// 'timeMin' => $timeMin,
// 'timeMax' => $timeMax,
'timeZone' => 'Asia/Kolkata',
);
$results = $this->googlecalendar->calendar->events->listEvents($calendarId, $optParams);
$results = $this->Googleapi->calendar->events->listEvents('primary', $optParams);
print_r($results);die();
$data = array();

File diff suppressed because one or more lines are too long