Commit d695fdaf by Tobin

t : push notification changes

parent f8c87676
......@@ -123,8 +123,9 @@ class Notification extends CI_Controller {
foreach($users AS $user){
$userData = array('id'=>$event_data->event_id,
'title'=>$event_data->event_name_EN,
'param'=>'event_id',
'message'=>$message);
$this->push_sent_cancel('1',$user['fcm_token'],$userData);
push_sent_cancel($user['fcm_token'],$userData);
}
$flashMsg['class'] = 'success';
......@@ -152,39 +153,11 @@ class Notification extends CI_Controller {
foreach($bookData AS $bData){
$userData = array('id'=>$bData['bookId'],
'param'=>'booking_id',
'title'=>$bData['event_name_en'],
'message'=>'Booking Remainder');
$this->push_sent_cancel('2',$bData['fcm_token'],$userData);
push_sent_cancel($bData['fcm_token'],$userData);
}
}
function push_sent_cancel($type='1', $fcm_token='', $fcm_data=array()) {
$settings = getSettings();
$key = $settings['app_id'];
if(empty($key) || empty($fcm_token) || empty($fcm_data)){
return;
}
switch ($type) {
case '1':
$data = "{ \"notification\": { \"title\": \"".$fcm_data['title']."\", \"text\": \"".$fcm_data['message']."\", \"sound\": \"default\" }, \"time_to_live\": 60, \"data\" : {\"response\" : {\"status\" : \"success\", \"data\" : {\"event_id\" : \"".$fcm_data['id']."\", \"trip_status\" : 0}}}, \"collapse_key\" : \"trip\", \"priority\":\"high\", \"to\" : \"".$fcm_token."\"}";
break;
case '2':
$data = "{ \"notification\": { \"title\": \"".$fcm_data['title']."\", \"text\": \"".$fcm_data['message']."\", \"sound\": \"default\" }, \"time_to_live\": 60, \"data\" : {\"response\" : {\"status\" : \"success\", \"data\" : {\"booking_id\" : \"".$fcm_data['id']."\", \"trip_status\" : 0}}}, \"collapse_key\" : \"trip\", \"priority\":\"high\", \"to\" : \"".$fcm_token."\"}";
break;
}
$ch = curl_init("https://fcm.googleapis.com/fcm/send");
$header = array('Content-Type: application/json', 'Authorization: key='.$key);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$out = curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close($ch);
}
}
?>
\ No newline at end of file
......@@ -396,4 +396,22 @@
}
return $langArr;
}
function push_sent_cancel($fcm_token='', $fcm_data=array()) {
$settings = getSettings();
$key = $settings['org_app_id'];
if(empty($key) || empty($fcm_token) || empty($fcm_data)){
return;
}
$data = "{ \"notification\": { \"title\": \"".$fcm_data['title']."\", \"text\": \"".$fcm_data['message']."\", \"sound\": \"default\" }, \"time_to_live\": 60, \"data\" : {\"response\" : {\"status\" : \"success\", \"data\" : {\"".$fcm_data['param']."\" : \"".$fcm_data['id']."\", \"user_type\" : 2}}}, \"collapse_key\" : \"trip\", \"priority\":\"high\", \"to\" : \"".$fcm_token."\"}";
$ch = curl_init("https://fcm.googleapis.com/fcm/send");
$header = array('Content-Type: application/json', 'Authorization: key='.$key);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close($ch);
}
?>
\ No newline at end of file
......@@ -703,8 +703,9 @@ class Api_model extends CI_Model {
if($post_data['status'] == 6){
$userData = array('id'=>$post_data['bookId'],
'title'=>'New Booking',
'param'=>'booking_id',
'message'=>'New Booking is There For Approval');
$this->push_sent_cancel($bkData['fcm_token'],$userData);
push_sent_cancel($bkData['fcm_token'],$userData);
}
}
} else {
......@@ -723,24 +724,6 @@ class Api_model extends CI_Model {
return 'https://www.barcodefaq.com/wp-content/uploads/2018/08/gs1-qrcode-fnc1.png';
}
public function push_sent_cancel($fcm_token='', $fcm_data=array()) {
$settings = getSettings();
$key = $settings['org_app_id'];
if(empty($key) || empty($fcm_token) || empty($fcm_data)){
return;
}
$data = "{ \"notification\": { \"title\": \"".$fcm_data['title']."\", \"text\": \"".$fcm_data['message']."\", \"sound\": \"default\" }, \"time_to_live\": 60, \"data\" : {\"response\" : {\"status\" : \"success\", \"data\" : {\"booking_id\" : \"".$fcm_data['id']."\", \"user_type\" : 2}}}, \"collapse_key\" : \"trip\", \"priority\":\"high\", \"to\" : \"".$fcm_token."\"}";
$ch = curl_init("https://fcm.googleapis.com/fcm/send");
$header = array('Content-Type: application/json', 'Authorization: key='.$key);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close($ch);
}
function recommend($data) {
try {
$locCond = '';
......@@ -1438,8 +1421,9 @@ class Api_model extends CI_Model {
if($bokStatus == '6'){
$userData = array('id'=>$book_id,
'title'=>'New Booking',
'param'=>'booking_id',
'message'=>'New Booking is There For Approval');
$this->push_sent_cancel($bkData['fcm_token'],$userData);
push_sent_cancel($bkData['fcm_token'],$userData);
}
}
$this->db->update('booking',array('status'=>$bokStatus),array('bookId'=>$book_id));
......
......@@ -1097,32 +1097,15 @@ class Organizer_model extends CI_Model {
$bData = $this->db->query($sql)->row_array();
$this->db->update('booking',array('status'=>'1'),array('bookId'=>$data['booking_id']));
$userData = array('id'=>$data['booking_id'],
'param'=>'booking_id',
'title'=>'Booking Approved',
'message'=>'Your Booking is Approved by the Event Provider');
$this->push_sent_cancel($bData['fcm_token'],$userData);
push_sent_cancel($bData['fcm_token'],$userData);
$res = array('status'=>1,'message'=>'Booking Accepted Successfully');
}catch(Exception $e){
$res = array('status'=>0,'message'=>'Ohh No!! Something Went South','code'=>'ER06');
}
return $res;
}
public function push_sent_cancel($fcm_token='', $fcm_data=array()) {
$settings = getSettings();
$key = $settings['app_id'];
if(empty($key) || empty($fcm_token) || empty($fcm_data)){
return;
}
$data = "{ \"notification\": { \"title\": \"".$fcm_data['title']."\", \"text\": \"".$fcm_data['message']."\", \"sound\": \"default\" }, \"time_to_live\": 60, \"data\" : {\"response\" : {\"status\" : \"success\", \"data\" : {\"booking_id\" : \"".$fcm_data['id']."\", \"trip_status\" : 0}}}, \"collapse_key\" : \"trip\", \"priority\":\"high\", \"to\" : \"".$fcm_token."\"}";
$ch = curl_init("https://fcm.googleapis.com/fcm/send");
$header = array('Content-Type: application/json', 'Authorization: key='.$key);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$out = curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close($ch);
}
}
?>
......@@ -1212,9 +1212,10 @@ class Webservice_model extends CI_Model {
}
if($post_data['status'] == 6){
$userData = array('id'=>$post_data['bookId'],
'title'=>'New Booking',
'message'=>'New Booking is There For Approval');
$this->push_sent_cancel($bkData['fcm_token'],$userData);
'param'=>'booking_id',
'title'=>'New Booking',
'message'=>'New Booking is There For Approval');
push_sent_cancel($bkData['fcm_token'],$userData);
}
}
} else {
......@@ -1233,24 +1234,6 @@ class Webservice_model extends CI_Model {
return 'https://www.barcodefaq.com/wp-content/uploads/2018/08/gs1-qrcode-fnc1.png';
}
public function push_sent_cancel($fcm_token='', $fcm_data=array()) {
$settings = getSettings();
$key = $settings['org_app_id'];
if(empty($key) || empty($fcm_token) || empty($fcm_data)){
return;
}
$data = "{ \"notification\": { \"title\": \"".$fcm_data['title']."\", \"text\": \"".$fcm_data['message']."\", \"sound\": \"default\" }, \"time_to_live\": 60, \"data\" : {\"response\" : {\"status\" : \"success\", \"data\" : {\"booking_id\" : \"".$fcm_data['id']."\", \"user_type\" : 2}}}, \"collapse_key\" : \"trip\", \"priority\":\"high\", \"to\" : \"".$fcm_token."\"}";
$ch = curl_init("https://fcm.googleapis.com/fcm/send");
$header = array('Content-Type: application/json', 'Authorization: key='.$key);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close($ch);
}
function cancel($data) {
try {
$user_id = $this->auth_token_get($data['auth_token']);
......@@ -1920,20 +1903,42 @@ class Webservice_model extends CI_Model {
}
public function update_friend_request($data){
$fromUser = $data['user_id'];
$user_id = $this->auth_token_get($data['auth_token']);
$status = $this->db->query("UPDATE chats SET type='".$data['add_as_friend']."'
WHERE from_user='".$data['user_id']."' AND to_user='".$user_id."'");
WHERE from_user='".$fromUser."' AND to_user='".$user_id."'");
if($data['add_as_friend'] == 1){
$toCustData = $this->db->get_where('customer',array('customer_id'=>$fromUser))->row_array();
$frmCustData = $this->db->get_where('customer',array('customer_id'=>$user_id))->row_array();
$fcmData = array('id'=>$toUser,'param'=>'user_id',
'title'=>'Accepted Chat Request',
'message'=>$frmCustData['name'].' has Accepted Your Chat Request');
push_sent_cancel($toCustData['fcm_token'],$fcmData);
}
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();
$toUser = (is_numeric($data['user_id']))?$data['user_id']:decode_param($data['user_id']);
if(empty($toUser)){
return array('status'=>0,'code'=>'919','message'=>'Something Went Wrong.. Try Again..');
}
$result = $this->db->get_where('chats',array('from_user'=>$user_id,'to_user'=>$toUser))->row_array();
if(empty($result)){
$result = $this->db->get_where('chats',array('to_user'=>$user_id,'from_user'=>$data['user_id']))->row_array();
$result=$this->db->get_where('chats',array('to_user'=>$user_id,'from_user'=>$toUser))->row_array();
if(empty($result)){
$this->db->insert('chats',array('from_user'=>$user_id,'to_user'=>$data['user_id'],'type'=>'0'));
$this->db->insert('chats',array('from_user'=>$user_id,'to_user'=>$toUser,'type'=>'0'));
$toCustData = $this->db->get_where('customer',array('customer_id'=>$toUser))->row_array();
$frmCustData = $this->db->get_where('customer',array('customer_id'=>$user_id))->row_array();
$fcmData = array('id'=>$toUser,'param'=>'user_id',
'title'=>'New Friend Request',
'message'=>'You got a New Friend Request from '.$toCustData['name']);
push_sent_cancel($frmCustData['fcm_token'],$fcmData);
} else if (!empty($result) && $result['type'] == '0'){
$this->db->update('chats',array('type'=>'1'),array('chat_id'=>$result['chat_id']));
}
......
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