Commit 168bd787 by Tobin

t : chant changes

parent 1dcabb80
......@@ -1863,6 +1863,7 @@ class Webservice_model extends CI_Model {
if(empty($data)){
return array('status'=>0,'code'=>'918','message'=>'Data Missing');
}
$phNumbers = '';
foreach($data['contacts'] AS $key => $number) {
$number = preg_replace('/\D/', '', $number);
......@@ -1875,37 +1876,48 @@ class Webservice_model extends CI_Model {
$phNumbers .= " (CUST.phone LIKE '%".$number."' ".$eCond;
}
}
if(empty($phNumbers)){
return array('status'=>0,'code'=>'919','message'=>'Invalid Data');
}
if(empty($phNumbers)){ return array('status'=>0,'code'=>'919','message'=>'Invalid Data'); }
$sql = "SELECT CUST.customer_id FROM customer AS CUST
INNER JOIN users AS USR ON (USR.id=CUST.customer_id)
WHERE $phNumbers AND CUST.customer_id!=$user_id";
WHERE CUST.enable_chat='1' AND CUST.customer_id!=$user_id AND $phNumbers";
$custIds = $this->db->query($sql)->result_array();
if(empty($custIds)){
return array('status'=>0,'code'=>'919','message'=>'No Data Found');
}
$user_ids = '';
foreach ($custIds AS $id) {
$user_ids = $id['customer_id'].',';
$user_ids[] = $id['customer_id'];
}
$sql = "SELECT from_user FROM chats
WHERE (from_user=$user_id AND type='2') OR (to_user=$user_id AND type='2')";
$blocked = $this->db->query($sql)->result_array();
if(!empty($blocked)){
foreach ($blocked AS $id) {
$user_ids = array_diff($user_ids,$id);
}
}
$sql = "SELECT to_user FROM chats
WHERE (from_user=$user_id AND type='2') OR (to_user=$user_id AND type='2')";
$blocked = $this->db->query($sql)->result_array();
if(!empty($blocked)){
foreach ($blocked AS $id) {
$user_ids = array_diff($user_ids,$id);
}
}
if(empty($user_ids) || empty($user_ids = implode(',',$user_ids))){
return array('status'=>0,'code'=>'920','message'=>'No User Found');
}
$user_ids = trim($user_ids,',');
$result = $this->db->query("SELECT CUST.customer_id,CUST.name,CUST.phone,CUST.profile_image,
CUST.profile_image_qr,CHT.type AS friend_status
FROM customer AS CUST
LEFT JOIN chats AS CHT ON ((CUST.customer_id=CHT.from_user OR CUST.customer_id=CHT.to_user) AND CHT.type IN (0,1))
WHERE CUST.customer_id IN ($user_ids) 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'))
WHERE CUST.customer_id IN ($user_ids)
GROUP BY CUST.customer_id");
$respArr['status'] = 1;
$respArr['data'] = (!empty($result) && !empty($result=$result->result_array()))?$result:[];
......@@ -1978,13 +1990,10 @@ class Webservice_model extends CI_Model {
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();
$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 ('1')")->result_array();
$custData = array();
if(!empty($result)){
foreach ($result as $key => $value) {
if($value['type'] == 0){
continue;
}
$fromUsrId = '';
if($value['to_user'] == $user_id) {
$fromUsrId = $value['from_user'];
......
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