2020-02-24 11:15:30 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Services\Notification;
|
|
|
|
|
|
|
|
use App\Models\Company;
|
|
|
|
use App\Services\AbstractService;
|
|
|
|
use Illuminate\Notifications\Notification as Notifiable;
|
|
|
|
use Illuminate\Support\Facades\Notification;
|
|
|
|
|
|
|
|
class NotificationService extends AbstractService
|
|
|
|
{
|
|
|
|
|
|
|
|
public $company;
|
|
|
|
|
|
|
|
public $notification;
|
|
|
|
|
|
|
|
public function __construct(Company $company, Notifiable $notification)
|
|
|
|
{
|
|
|
|
|
|
|
|
$this->company = $company;
|
|
|
|
|
|
|
|
$this->notification = $notification;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-03-03 10:44:26 +01:00
|
|
|
public function run($is_system = false)
|
2020-02-24 11:15:30 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
$this->company->owner()->notify($this->notification);
|
|
|
|
|
2020-03-03 10:44:26 +01:00
|
|
|
if($is_system)
|
|
|
|
{
|
|
|
|
$this->notification->is_system = true;
|
|
|
|
|
|
|
|
Notification::route('slack', $this->company->slack_webhook_url)
|
|
|
|
->notify($this->notification);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hosted notifications
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function ninja()
|
|
|
|
{
|
|
|
|
|
|
|
|
Notification::route('slack', config('ninja.notification.slack'))
|
|
|
|
->route('mail', config('ninja.notification.mail'))
|
|
|
|
->notify($this->notification);
|
|
|
|
|
2020-02-24 11:15:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|