Subversion Repositories SmartDukaan

Rev

Rev 14770 | Rev 14781 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 14770 Rev 14776
Line 360... Line 360...
360
			if(empty($this->request->data['userIds'])){
360
			if(empty($this->request->data['userIds'])){
361
				$this->Session->setFlash(__('Please choose a few users'));
361
				$this->Session->setFlash(__('Please choose a few users'));
362
				$this->redirect(array('action' => 'admin_pushnotifications'));
362
				$this->redirect(array('action' => 'admin_pushnotifications'));
363
			}else{
363
			}else{
364
				$message = $this->request->data['User'];
364
				$message = $this->request->data['User'];
-
 
365
				$this->loadModel('NotificationCampaign');
-
 
366
				$this->NotificationCampaign->create();
-
 
367
				$data = array('name'=>$message['name'],'title'=>$message['title'],'type'=>$message['type'],'message'=>$message['message'],'url'=>$message['url']);
-
 
368
				if($this->NotificationCampaign->save($data)){
-
 
369
					$message['cid'] = $this->NotificationCampaign->getLastInsertId();
-
 
370
				} else{
-
 
371
					debug($this->NotificationCampaign->validationErrors);
-
 
372
					$message['cid'] = $message['name'];
-
 
373
				}
365
				if($message['type'] == 'url' && !empty($message['url'])) {
374
				if($message['type'] == 'url' && !empty($message['url'])) {
366
					$url = $message['url'];
375
					$url = $message['url'];
367
					$this->loadModel('Store');
376
					$this->loadModel('Store');
368
					$store = $this->Store->getByUrl($url);					
377
					$store = $this->Store->getByUrl($url);					
369
				}				
378
				}				
Line 383... Line 392...
383
	}
392
	}
384
 
393
 
385
	private function send_push_notification($registatoin_ids, $message, $user_id) {
394
	private function send_push_notification($registatoin_ids, $message, $user_id) {
386
		$msg = array(
395
		$msg = array(
387
		    'message'       => $message['message'],
396
		    'message'       => $message['message'],
-
 
397
		    'cid'       	=> $message['cid'],
388
		    'title'         => $message['title'],
398
		    'title'         => $message['title'],
389
		    'type'      	=> $message['type'],
399
		    'type'      	=> $message['type'],
390
		    'url'		    => $message['url'],
400
		    'url'		    => $message['url'],
391
		    'vibrate'       => 1,
401
		    'vibrate'       => 1,
392
		    'sound'         => 1,
402
		    'sound'         => 1,
Line 422... Line 432...
422
		// Execute post
432
		// Execute post
423
		$result = curl_exec($ch);
433
		$result = curl_exec($ch);
424
		if ($result === FALSE) {
434
		if ($result === FALSE) {
425
		    die('Curl failed: ' . curl_error($ch));
435
		    die('Curl failed: ' . curl_error($ch));
426
		}
436
		}
427
 
-
 
-
 
437
		$res = json_decode($result,1);
-
 
438
		$this->loadModel('Pushnotification');
-
 
439
		$data = array('notification_campaign_id'=>$message['cid'],'user_id'=>$user_id,'status'=>$res['success']);
-
 
440
		$this->Pushnotification->create();
-
 
441
		$this->Pushnotification->save($data);
428
		// Close connection
442
		// Close connection
429
		curl_close($ch);
443
		curl_close($ch);
430
		$this->log("For $user_id ".$registatoin_ids[0]." ".print_r($result,1),'notifiactions');
444
		$this->log("For $user_id ".$registatoin_ids[0]." ".print_r($result,1),'notifiactions');
431
	}
445
	}
432
 
446