sparqapi/api/application/controllers/Test.php
2022-03-23 11:47:40 +05:30

147 lines
5.2 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once APPPATH . '/libraries/REST_Controller.php';
class Test extends REST_Controller {
/**
* load list modal, library and helpers
*/
function __Construct(){
parent::__Construct();
$this->load->helper(array('form', 'url'));
//$this->load->model('test_model');
$this->load->library('asynclibrary');
$this->load->library('AWS_REKONITION');
$this->load->helper('MYUTIL');
}
/**
* @desc : Function to perform multiple task in background
* @param :void
* @return : void
*/
public function ind_get(){
//echo base_url();
print_r(getallheaders());
$url = base_url()."test/sendmail";
$urls = base_url()."test/insert";
$param = array('email' => "jagroop@gmail.com" );
$param1 = array('name' => "Jagroop Singh",
'email' => "jagroop@gmail.com" );
// $async1 = $this->asynclibrary->do_in_background($url, $param);
// $async2 = $this->asynclibrary->do_in_background($urls, $param1);
// print_r($async1);
// print_r($async2);
}
/**
* @desc : Function to send mail
* @param :void
* @return : void
*/
public function sendmail_post(){
// $this->load->library('email');
$user_email = $_POST['email'];
// $message = "Testing";
// $this->email->from('wolfy@gmail.com', 'Wolfy Singh');
// $this->email->to($user_email);
// $this->email->subject("test");
// $this->email->message($message);
// $this->email->send();
$id = $this->db->insert('t_city_master',array('city_name'=> $user_email));
// echo $user_email;
// print_r($id);
}
/**
* @desc : Function to call insert() method
* of test_model to insert data in database
* @param :void
* @return : void
*/
public function insert_post(){
$user_email = $_POST['name'];
$this->db->insert('t_city_master',array('city_name'=>$user_email));
// $email = $this->input->post('email');
// $name = $this->input->post('name');
// $this->test_model->insert($email, $name);
//echo "insert";
}
public function compareFaces_post()
{
$pdid = $this->post('pdid');
$src = $this->post('src');
$dest = $this->post('dest');
$src_url_type = $this->post('src_url_type');
$dest_url_type = $this->post('dest_url_type');
$res_data = array('nxt_action' => null);
// echo $src;die();
if($src_url_type == 'base64')//make local img
{
$src_local_file = APPPATH.'docs/'.MYUTIL::getRandomString(10).'-'.date('Y-m-d-H-i-s').'.png';
$ifp = fopen( $src_local_file, 'wb' );
//$data = explode( ',', $src );
fwrite( $ifp, base64_decode( $src ) );
fclose( $ifp );
$src = $src_local_file;
}
if($dest_url_type == 'base64')//make local img
{
$dest_local_file = APPPATH.'docs/'.MYUTIL::getRandomString(10).'-'.date('Y-m-d-H-i-s').'.png';
$ifp = fopen( $dest_local_file, 'wb' );
//$data = explode( ',', $src );
fwrite( $ifp, base64_decode( $dest ) );
fclose( $ifp );
$dest = $dest_local_file;
}
//check no of faces in src img
$no_of_faces_in_src_img = $this->aws_rekonition->detectFaces($src);
if(is_object($no_of_faces_in_src_img) && isset($no_of_faces_in_src_img['FaceDetails']) && count($no_of_faces_in_src_img['FaceDetails']) > 1)
{
foreach($no_of_faces_in_src_img as $k => $v)
{
$res_data[$k] = $v;
// echo '***********************';
}
$res_data['nxt_action'] = 'pick_src_img';
//if no faces more than two then return all face details to
//front end and let user pick the src img
$this->response($res_data,REST_Controller::HTTP_OK);
}
$compare_analysis_data = $this->aws_rekonition->comparePhotos($src,$dest);
if(is_object($compare_analysis_data))
{
foreach($compare_analysis_data as $k => $v)
{
$res_data[$k] = $v;
// echo '***********************';
}
}
//delete local files if created
if($dest_url_type == 'base64')
{
unlink($dest);
}
if($src_url_type == 'base64')
{
unlink($src);
}
$this->response($res_data,REST_Controller::HTTP_OK);
}
}