mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-08-07 10:01:47 -04:00
Push Notifications
This commit is contained in:
parent
f6be1041b7
commit
57a4a24294
@ -9,6 +9,17 @@ use Illuminate\Http\Request;
|
||||
* @package App\Ninja\Notifications
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* $account->devices Definition
|
||||
*
|
||||
* @param string token
|
||||
* @param bool notify_sent
|
||||
* @param bool notify_paid
|
||||
* @param bool notify_approved
|
||||
* @param bool notify_viewed
|
||||
*/
|
||||
|
||||
class PushService
|
||||
{
|
||||
protected $pushFactory;
|
||||
@ -20,7 +31,7 @@ class PushService
|
||||
|
||||
/**
|
||||
* @param $invoice - Invoice object
|
||||
* @param $type - Type of notification, ie. Quote APPROVED, Invoice PAID, Invoice SENT, Invoice VIEWED
|
||||
* @param $type - Type of notification, ie. Quote APPROVED, Invoice PAID, Invoice/Quote SENT, Invoice/Quote VIEWED
|
||||
*/
|
||||
|
||||
public function sendNotification($invoice, $type)
|
||||
@ -30,15 +41,92 @@ class PushService
|
||||
return;
|
||||
|
||||
//Harvest an array of devices that are registered for this notification type
|
||||
$devices = json_decode($invoice->account->devices, TRUE);
|
||||
|
||||
foreach($devices as $device)
|
||||
{
|
||||
if($device["notify_{$type}"] == TRUE)
|
||||
$this->pushMessage($invoice, $device['token'], $device["notify_{$type}"]);
|
||||
}
|
||||
|
||||
//loop and send
|
||||
|
||||
}
|
||||
|
||||
|
||||
private function pushMessage($invoice, $token, $type)
|
||||
{
|
||||
$this->pushFactory->message($token, $this->messageType($invoice, $type));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* checkDeviceExists function
|
||||
*
|
||||
* Returns a boolean if this account has devices registered for PUSH notifications
|
||||
*
|
||||
* @param $account
|
||||
* @return bool
|
||||
*/
|
||||
private function checkDeviceExists($account)
|
||||
{
|
||||
$devices = json_decode($account->devices);
|
||||
$devices = json_decode($account->devices, TRUE);
|
||||
|
||||
|
||||
if(count($devices) >= 1)
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
private function messageType($invoice, $type)
|
||||
{
|
||||
switch($type)
|
||||
{
|
||||
case 'notify_sent':
|
||||
return $this->entitySentMessage($invoice);
|
||||
break;
|
||||
|
||||
case 'notify_paid':
|
||||
return $this->invoicePaidMessage($invoice);
|
||||
break;
|
||||
|
||||
case 'notify_approved':
|
||||
return $this->quoteApprovedMessage($invoice);
|
||||
break;
|
||||
|
||||
case 'notify_viewed':
|
||||
return $this->entityViewedMessage($invoice);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private function entitySentMessage($invoice)
|
||||
{
|
||||
if($invoice->is_quote)
|
||||
return 'Quote #{$invoice->invoice_number} sent!';
|
||||
else
|
||||
return 'Invoice #{$invoice->invoice_number} sent!';
|
||||
|
||||
}
|
||||
|
||||
private function invoicePaidMessage($invoice)
|
||||
{
|
||||
return 'Invoice #{$invoice->invoice_number} paid!';
|
||||
}
|
||||
|
||||
private function quoteApprovedMessage($invoice)
|
||||
{
|
||||
return 'Quote #{$invoice->invoice_number} approved!';
|
||||
}
|
||||
|
||||
private function entityViewedMessage($invoice)
|
||||
{
|
||||
if($invoice->is_quote)
|
||||
return 'Quote #{$invoice->invoice_number} viewed!';
|
||||
else
|
||||
return 'Invoice #{$invoice->invoice_number} viewed!';
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user