Commit f4172166 by Tobin

Merge branch 'jansa' into 'master'

chat apis See merge request !91
parents 6fe9a1a7 863d77d9
...@@ -484,5 +484,89 @@ class Webservice extends CI_Controller { ...@@ -484,5 +484,89 @@ class Webservice extends CI_Controller {
$this->db->update('country',array('conversion_rate'=>$rate),array('currency'=>$currency)); $this->db->update('country',array('conversion_rate'=>$rate),array('currency'=>$currency));
} }
} }
public function sync_contacts(){
$data = (array) json_decode(file_get_contents('php://input'));
$data['auth_token'] = $this->auth_token;
$res = $this->Webservice_model->sync_contacts($data);
if($res['status']!=0){
$this->response($res['data']);
}
else{
$this->errorResponse($res['code'],$res['message']);
}
}
public function update_friend_request(){
$data = (array) json_decode(file_get_contents('php://input'));
$data['auth_token'] = $this->auth_token;
$res = $this->Webservice_model->update_friend_request($data);
if($res!=0){
$this->successResponse($res);
}
else{
$this->errorResponse($res['code'],$res['message']);
}
}
public function send_friend_request(){
$data = (array) json_decode(file_get_contents('php://input'));
$data['auth_token'] = $this->auth_token;
$res = $this->Webservice_model->send_friend_request($data);
if($res['status']!=0){
$this->successResponse($res);
}
else{
$this->errorResponse($res['code'],$res['message']);
}
}
public function get_friend_requests(){
$data = (array) json_decode(file_get_contents('php://input'));
$data['auth_token'] = $this->auth_token;
$res = $this->Webservice_model->get_friend_requests($data);
if($res['status']!=0){
$this->response($res['data']);
}
else{
$this->errorResponse($res['code'],$res['message']);
}
}
public function recent_chats(){
$data['auth_token'] = $this->auth_token;
$res = $this->Webservice_model->recent_chats($data);
if($res['status']!=0){
$this->response($res['data']);
}
else{
$this->errorResponse($res['code'],$res['message']);
}
}
public function upload_audio_message(){
if(!empty($_FILES))
{
if (!file_exists('assets/audios/'.date('Y-m-d'))){
mkdir('assets/audios/'.date('Y-m-d'), 0777, true);
}
$fileName =date('d').'_'.$_FILES['audio_message']['name'];
$config = set_upload_service('assets/audios/'.date('Y-m-d'));
$config['file_name'] = $fileName;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('audio_message'))
{
$error = array('error' => $this->upload->display_errors('', ''));
$this->errorResponse('ER10',$error);
}
else
{
$imagedata = $this->upload->data();
$fullfilepath='assets/audios/'.date('Y-m-d').'/'.$imagedata['file_name'];
$respArr['data'] = $fullfilepath;
$this->response($respArr);
}
}
}
} }
?> ?>
...@@ -113,7 +113,79 @@ class Validation_app_model extends CI_Model { ...@@ -113,7 +113,79 @@ class Validation_app_model extends CI_Model {
'forgot_password'=> array('new_password'=>array('required'=>array('code'=>'ER35', 'message'=>'New password is null or empty')), 'forgot_password'=> array('new_password'=>array('required'=>array('code'=>'ER35', 'message'=>'New password is null or empty')),
'phone'=>array('required'=>array('code'=>'ER07', 'message'=>'Phone is null or empty')),), 'phone'=>array('required'=>array('code'=>'ER07', 'message'=>'Phone is null or empty')),),
'convertCurrency'=> array() 'convertCurrency'=> array(),
'sync_contacts' => array(
'auth_token' => array(
'required' => array(
'code' => 'ER02',
'message' => 'User id is null or empty'
)
) ,
'contacts' => array(
'required' => array(
'code' => 'ER04',
'message' => 'Contacts is null or empty'
) ,
)
),
'update_friend_request' => array(
'auth_token' => array(
'required' => array(
'code' => 'ER02',
'message' => 'User id is null or empty'
)
) ,
'user_id' => array(
'required' => array(
'code' => 'ER04',
'message' => 'User Id is null or empty'
) ,
),
'add_as_friend' => array(
'required' => array(
'code' => 'ER04',
'message' => 'Accept/Reject value is null or empty'
) ,
)
),
'send_friend_request' => array(
'auth_token' => array(
'required' => array(
'code' => 'ER02',
'message' => 'User id is null or empty'
)
) ,
'user_id' => array(
'required' => array(
'code' => 'ER04',
'message' => 'User Id is null or empty'
) ,
)
),
'get_friend_requests' => array(
'auth_token' => array(
'required' => array(
'code' => 'ER02',
'message' => 'User id is null or empty'
)
)
),
'recent_chats' => array(
'auth_token' => array(
'required' => array(
'code' => 'ER02',
'message' => 'User id is null or empty'
)
)
),
'upload_audio_message' => array(
'auth_token' => array(
'required' => array(
'code' => 'ER02',
'message' => 'User id is null or empty'
)
)
),
); );
public function validation_check($method_name, $parms) { public function validation_check($method_name, $parms) {
......
...@@ -1756,6 +1756,90 @@ class Webservice_model extends CI_Model { ...@@ -1756,6 +1756,90 @@ class Webservice_model extends CI_Model {
} }
return $event_layouts; return $event_layouts;
} }
public function sync_contacts($data){
$user_id = $this->auth_token_get($data['auth_token']);
$respArr = array('status'=>0,'code'=>'918','message'=>'Something Went Wrong..Try Again');
if(empty($data)){
return $respArr;
}
$phNumbers = '';
foreach($data['contacts'] AS $key => $number) {
$eCond = ($key != count($data['contacts'])-1)?' OR ':'';
if(strlen($number) > 10){
$phNumbers .= " phone LIKE '%".substr($number, strlen($number)-10)."' ".$eCond;
} else {
$phNumbers .= " phone LIKE '%".$number."' ".$eCond;
}
}
$result = $this->db->query("SELECT name,phone,profile_image FROM customer WHERE (".$phNumbers.") AND customer_id NOT IN (SELECT from_user FROM chats WHERE (from_user=$user_id AND type='2') OR (to_user =$user_id AND type='2')) AND customer_id NOT IN (SELECT to_user FROM chats WHERE (from_user=$user_id AND type='2') OR (to_user =$user_id AND type='2'))");
if(!empty($result) && !empty($result = $result->result_array())){
$respArr['status'] = 1;
$respArr['data'] = $result;
}
return $respArr;
}
public function update_friend_request($data){
$user_id = $this->auth_token_get($data['auth_token']);
$status = $this->db->query("UPDATE chats SET type = ".$data['add_as_friend']." WHERE from_user = $user_id AND to_user = ".$data['user_id']);
return ($status)?1:0;
}
public function send_friend_request($data){
$respArr = array('status'=>0,'code'=>'918','message'=>'Something Went Wrong..Try Again');
$user_id = $this->auth_token_get($data['auth_token']);
$result=$this->db->get_where('chats',array('from_user'=>$user_id,'to_user'=>$data['user_id']))->row_array();
if(empty($result)){
$result = $this->db->get_where('chats',array('to_user'=>$user_id,'from_user'=>$data['user_id']))->row_array();
if(empty($result)){
$this->db->insert('chats',array('from_user'=>$user_id,'to_user'=>$data['user_id'],'type'=>'0'));
} else if (!empty($result) && $result['type'] == '0'){
$this->db->update('chats',array('type'=>'1'),array('chat_id'=>$result['chat_id']));
}
$respArr['status'] = 1;
}else{
$respArr['status'] = 1;
}
return $respArr;
}
public function get_friend_requests($data){
$respArr = array('status'=>0,'code'=>'918','message'=>'No Request for you');
$user_id = $this->auth_token_get($data['auth_token']);
$this->db->select("name,phone,profile_image");
$this->db->join('customer','customer.customer_id = chats.to_user');
$result=$this->db->get_where('chats',array('to_user'=>$user_id,'type'=>'0'))->result_array();
if(!empty($result)){
$respArr['status'] = 1;
$respArr['data'] = $result;
}
return $respArr;
}
public function recent_chats($data){
$respArr = array('status'=>0,'code'=>'918','message'=>'No Request for you');
$user_id = $this->auth_token_get($data['auth_token']);
$result = $this->db->query("SELECT from_user,to_user,type FROM chats WHERE (from_user=$user_id OR to_user=$user_id) AND type IN('0','1')")->result_array();
if(!empty($result)){
foreach ($result as $key => $value) {
if($value['to_user'] == $user_id && $value['type'] == 0){
continue;
}
$this->db->select("name,phone,profile_image");
$cust = $this->db->get_where('customer',array('customer_id'=>$value['to_user']));
if(!empty($cust) && !empty($cust = $cust->row_array())){
$custData[] = $cust;
}
}
$respArr['status'] = 1;
$respArr['data'] = $custData;
}
return $respArr;
}
} }
?> ?>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment