File: /var/www/vhost/disk-apps/agile-selling-wpb/app/Http/Controllers/PushNotificationController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use \OneSignal;
use Berkayk\OneSignal\OneSignalClient;
class PushNotificationController extends Controller
{
private $onesignalDelivery;
private function getOneSignalDelivery(){
if($this->onesignalDelivery){
return $this->onesignalDelivery;
}
$this->onesignalDelivery = new OneSignalClient(env("ONESIGNAL_APP_ID_DELIVERY"), env("ONESIGNAL_REST_API_KEY_DELIVERY"),null);
return $this->onesignalDelivery;
}
/**
* * Envio de notificacion con destino absolutamente todos los usuarios registrados en el app de OneSignal
* @param $message - Mensaje a ser enviado
* @param $url - URL que redirecciona la notificacion
* @param $data - Datos en segundo plano enviados junto a la notificacion
* @param $buttons - Botones incluidos en la notificacion aplica con ciertas restricciones según version iOS y Android
* @param $schedule - Fecha y hora de programación de la notificacion formatos posibles:
* "Thu Sep 24 2015 14:00:00 GMT-0700 (PDT)"
* "September 24th 2015, 2:00:00 pm UTC-07:00"
* "2015-09-24 14:00:00 GMT-0700"
* "Sept 24 2015 14:00:00 GMT-0700"
* "Thu Sep 24 2015 14:00:00 GMT-0700 (Pacific Daylight Time)"
* @param $typeTarget - U : USER D : DELIVERY
*/
public function sendToAll($message, $url, $data, $buttons, $schedule, $typeTarget){
if($typeTarget == "D"){
$onesignalDelivery = $this->getOneSignalDelivery();
$onesignalDelivery->sendNotificationToAll($message, $url, $data, $buttons, $schedule);
}else{
OneSignal::sendNotificationToAll($message, $url, $data, $buttons, $schedule);
}
}
/**
* * Envio de notificacion con destino a un usuario según su Player ID.
* @param $message - Mensaje a ser enviado
* @param $idOneSignal - Player ID asignado por la palataforma de OneSignal.
* @param $url - URL que redirecciona la notificacion
* @param $data - Datos en segundo plano enviados junto a la notificacion
* @param $buttons - Botones incluidos en la notificacion aplica con ciertas restricciones según version iOS y Android
* @param $schedule - Fecha y hora de programación de la notificacion formatos posibles:
*
* "Thu Sep 24 2015 14:00:00 GMT-0700 (PDT)"
* "September 24th 2015, 2:00:00 pm UTC-07:00"
* "2015-09-24 14:00:00 GMT-0700"
* "Sept 24 2015 14:00:00 GMT-0700"
* "Thu Sep 24 2015 14:00:00 GMT-0700 (Pacific Daylight Time)"
* @param $typeTarget - U : USER D : DELIVERY
*/
public function sendToUser($message, $idOneSignal, $url, $data, $buttons, $schedule, $typeTarget){
if($typeTarget == "D"){
$onesignalDelivery = $this->getOneSignalDelivery();
$onesignalDelivery->sendNotificationToUser($message, $idOneSignal, $url, $data, $buttons, $schedule);
}else{
OneSignal::sendNotificationToUser($message, $idOneSignal, $url, $data, $buttons, $schedule);
}
}
/**
* * Envio de notificacion con destino un segmento, el cual debe existir en la plataforma de OneSignal.
* @param $message - Mensaje a ser enviado
* @param $segment - Segmento, el cual debe estar creado en la plataforma de OneSignal.
* @param $url - URL que redirecciona la notificacion
* @param $data - Datos en segundo plano enviados junto a la notificacion
* @param $buttons - Botones incluidos en la notificacion aplica con ciertas restricciones según version iOS y Android
* @param $schedule - Fecha y hora de programación de la notificacion formatos posibles:
*
* "Thu Sep 24 2015 14:00:00 GMT-0700 (PDT)"
* "September 24th 2015, 2:00:00 pm UTC-07:00"
* "2015-09-24 14:00:00 GMT-0700"
* "Sept 24 2015 14:00:00 GMT-0700"
* "Thu Sep 24 2015 14:00:00 GMT-0700 (Pacific Daylight Time)"
* @param $typeTarget - U : USER D : DELIVERY
*/
public function sendToSegments($message, $segment, $url, $data, $buttons, $schedule, $typeTarget){
if($typeTarget == "D"){
$onesignalDelivery = $this->getOneSignalDelivery();
$onesignalDelivery->sendNotificationToSegment($message, $segment, $url, $data, $buttons, $schedule);
}else{
OneSignal::sendNotificationToSegment($message, $segment, $url, $data, $buttons, $schedule);
}
}
/**
* * Envio de notificacion con destino a las tags indicadas, las cuales deben existir en la plataforma de OneSignal.
* @param $message - Mensaje a ser enviado
* @param $tags - TAGS, etiquetas que deben estar marcadas en el usuario.
* @param $url - URL que redirecciona la notificacion
* @param $data - Datos en segundo plano enviados junto a la notificacion
* @param $buttons - Botones incluidos en la notificacion aplica con ciertas restricciones según version iOS y Android
* @param $schedule - Fecha y hora de programación de la notificacion formatos posibles:
*
* "Thu Sep 24 2015 14:00:00 GMT-0700 (PDT)"
* "September 24th 2015, 2:00:00 pm UTC-07:00"
* "2015-09-24 14:00:00 GMT-0700"
* "Sept 24 2015 14:00:00 GMT-0700"
* "Thu Sep 24 2015 14:00:00 GMT-0700 (Pacific Daylight Time)"
* @param $typeTarget - U : USER D : DELIVERY
*/
public function sendToSegment($message, $tags, $url, $data, $buttons, $schedule, $typeTarget){
if($typeTarget == "D"){
$onesignalDelivery = $this->getOneSignalDelivery();
$onesignalDelivery->sendNotificationUsingTags($message, $tags, $url, $data, $buttons, $schedule);
}else{
OneSignal::sendNotificationUsingTags($message, $tags, $url, $data, $buttons, $schedule);
}
}
}