| Line 18... |
Line 18... |
| 18 |
$regIds = array($gcmUser['GcmUser']['gcm_regid']);
|
18 |
$regIds = array($gcmUser['GcmUser']['gcm_regid']);
|
| 19 |
$message = $user['NotificationCampaign'];
|
19 |
$message = $user['NotificationCampaign'];
|
| 20 |
if($user['NotificationCampaign']['type'] == 'url' && !empty($user['NotificationCampaign']['url'])) {
|
20 |
if($user['NotificationCampaign']['type'] == 'url' && !empty($user['NotificationCampaign']['url'])) {
|
| 21 |
$message['url'] = $this->generateAffiliateUrl($user['NotificationCampaign']['url'],$user['Pushnotification']['user_id'],$store);
|
21 |
$message['url'] = $this->generateAffiliateUrl($user['NotificationCampaign']['url'],$user['Pushnotification']['user_id'],$store);
|
| 22 |
}
|
22 |
}
|
| 23 |
$result = $this->send_push_notification($regIds,$message,$user['Pushnotification']['user_id']);
|
23 |
$result = $this->send_push_notification($regIds,$message,$user['Pushnotification']['user_id'],$user['Pushnotification']['id']);
|
| 24 |
$data = array('id'=>$user['Pushnotification']['id'],'type'=>'sent','status'=>$result);
|
- |
|
| 25 |
$this->Pushnotification->save($data);
|
- |
|
| 26 |
}
|
24 |
}
|
| 27 |
}
|
25 |
}
|
| 28 |
}
|
26 |
}
|
| 29 |
|
27 |
|
| 30 |
private function send_push_notification($registatoin_ids, $message, $user_id) {
|
28 |
private function send_push_notification($registatoin_ids, $message, $user_id,$cid) {
|
| 31 |
Configure::load('live');
|
29 |
Configure::load('live');
|
| 32 |
$msg = array(
|
30 |
$msg = array(
|
| 33 |
'message' => $message['message'],
|
31 |
'message' => $message['message'],
|
| 34 |
'cid' => $message['id'],
|
32 |
'cid' => $message['id'],
|
| 35 |
'title' => $message['title'],
|
33 |
'title' => $message['title'],
|
| Line 76... |
Line 74... |
| 76 |
// $this->Pushnotification->create();
|
74 |
// $this->Pushnotification->create();
|
| 77 |
// $this->Pushnotification->save($data);
|
75 |
// $this->Pushnotification->save($data);
|
| 78 |
// Close connection
|
76 |
// Close connection
|
| 79 |
curl_close($ch);
|
77 |
curl_close($ch);
|
| 80 |
$this->log("For $user_id ".$registatoin_ids[0]." ".print_r($result,1),'pushnotifications');
|
78 |
$this->log("For $user_id ".$registatoin_ids[0]." ".print_r($result,1),'pushnotifications');
|
| - |
|
79 |
if($res['success']==1){
|
| - |
|
80 |
$data = array('id'=>$cid,'type'=>'sent','status'=>$res['success'],'message'=>'success');
|
| - |
|
81 |
$this->Pushnotification->save($data);
|
| - |
|
82 |
}else if($res['success']==0){
|
| - |
|
83 |
$this->loadModel(GcmUser);
|
| - |
|
84 |
$message=$res['results'][0]['error'];
|
| - |
|
85 |
$data = array('id'=>$cid,'type'=>'sent','status'=>$res['success'],'message'=>$message);
|
| - |
|
86 |
|
| - |
|
87 |
$sqlQuery="update gcm_users set failurecount=failurecount+1 where gcm_regid='".$registatoin_ids[0]."'";
|
| - |
|
88 |
$resultData=$this->GcmUser->query($sqlQuery);
|
| - |
|
89 |
$this->Pushnotification->save($data);
|
| - |
|
90 |
}
|
| 81 |
return $res['success'];
|
91 |
return $res['success'];
|
| 82 |
}
|
92 |
}
|
| 83 |
|
93 |
|
| 84 |
private function generateAffiliateUrl($url,$user_id,$store){
|
94 |
private function generateAffiliateUrl($url,$user_id,$store){
|
| 85 |
//Get StoreProduct Info
|
95 |
//Get StoreProduct Info
|