Commit f5233eea by Jansa Jose

view page comit

parent b8b13356
...@@ -522,7 +522,6 @@ class Webservice extends CI_Controller { ...@@ -522,7 +522,6 @@ class Webservice extends CI_Controller {
} }
public function get_friend_requests(){ public function get_friend_requests(){
$data = (array) json_decode(file_get_contents('php://input'));
$data['auth_token'] = $this->auth_token; $data['auth_token'] = $this->auth_token;
$res = $this->Webservice_model->get_friend_requests($data); $res = $this->Webservice_model->get_friend_requests($data);
if($res['status']!=0){ if($res['status']!=0){
......
...@@ -1774,7 +1774,11 @@ class Webservice_model extends CI_Model { ...@@ -1774,7 +1774,11 @@ class Webservice_model extends CI_Model {
$phNumbers .= " phone LIKE '%".$number."' ".$eCond; $phNumbers .= " phone LIKE '%".$number."' ".$eCond;
} }
} }
$result = $this->db->query("SELECT customer_id,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'))"); $result = $this->db->query("SELECT CUST.customer_id,CUST.name,CUST.phone,CUST.profile_image,
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=1)
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'))");
$respArr['status'] = 1; $respArr['status'] = 1;
if(!empty($result) && !empty($result = $result->result_array())){ if(!empty($result) && !empty($result = $result->result_array())){
...@@ -1787,7 +1791,8 @@ class Webservice_model extends CI_Model { ...@@ -1787,7 +1791,8 @@ class Webservice_model extends CI_Model {
public function update_friend_request($data){ public function update_friend_request($data){
$user_id = $this->auth_token_get($data['auth_token']); $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']); $status = $this->db->query("UPDATE chats SET type='".$data['add_as_friend']."'
WHERE from_user='".$data['user_id']."' AND to_user='".$user_id."'");
return ($status)?1:0; return ($status)?1:0;
} }
...@@ -1812,10 +1817,12 @@ class Webservice_model extends CI_Model { ...@@ -1812,10 +1817,12 @@ class Webservice_model extends CI_Model {
public function get_friend_requests($data){ public function get_friend_requests($data){
$respArr = array('status'=>0,'code'=>'918','message'=>'No Request for you'); $respArr = array('status'=>0,'code'=>'918','message'=>'No Request for you');
$user_id = $this->auth_token_get($data['auth_token']); $user_id = $this->auth_token_get($data['auth_token']);
$this->db->select("name,phone,profile_image,customer_id");
$this->db->join('customer','customer.customer_id = chats.to_user'); $result = $this->db->query("SELECT CUST.name,CUST.phone,CUST.profile_image,CUST.customer_id
$result=$this->db->get_where('chats',array('to_user'=>$user_id,'type'=>'0'))->result_array(); FROM customer AS CUST
if(!empty($result)){ INNER JOIN chats AS CHT ON (CUST.customer_id = CHT.from_user)
WHERE type='0' AND to_user='".$user_id."'");
if(!empty($result) && !empty($result = $result->result())){
$respArr['status'] = 1; $respArr['status'] = 1;
$respArr['data'] = $result; $respArr['data'] = $result;
} }
...@@ -1828,11 +1835,20 @@ class Webservice_model extends CI_Model { ...@@ -1828,11 +1835,20 @@ class Webservice_model extends CI_Model {
$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('0','1')")->result_array();
if(!empty($result)){ if(!empty($result)){
foreach ($result as $key => $value) { foreach ($result as $key => $value) {
if($value['to_user'] == $user_id && $value['type'] == 0){ if($value['type'] == 0){
continue; continue;
} }
$fromUsrId = '';
if($value['to_user']==$user_id){
$fromUsrId = $value['from_user'];
} else if ($value['from_user'] == $user_id){
$fromUsrId = $value['to_user'];
} else {
continue;
}
$this->db->select("name,phone,profile_image,customer_id"); $this->db->select("name,phone,profile_image,customer_id");
$cust = $this->db->get_where('customer',array('customer_id'=>$value['to_user'])); $cust = $this->db->get_where('customer',array('customer_id'=>$fromUsrId));
if(!empty($cust) && !empty($cust = $cust->row_array())){ if(!empty($cust) && !empty($cust = $cust->row_array())){
$custData[] = $cust; $custData[] = $cust;
} }
......
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