2013-12-25 22:34:42 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use ninja\mailers\UserMailer as Mailer;
|
|
|
|
|
|
|
|
class InvoiceEventHandler
|
|
|
|
{
|
|
|
|
protected $mailer;
|
|
|
|
|
|
|
|
public function __construct(Mailer $mailer)
|
|
|
|
{
|
|
|
|
$this->mailer = $mailer;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function subscribe($events)
|
|
|
|
{
|
|
|
|
$events->listen('invoice.sent', 'InvoiceEventHandler@onSent');
|
|
|
|
$events->listen('invoice.viewed', 'InvoiceEventHandler@onViewed');
|
|
|
|
$events->listen('invoice.paid', 'InvoiceEventHandler@onPaid');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function onSent($invoice)
|
|
|
|
{
|
|
|
|
$this->sendNotifications($invoice, 'sent');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function onViewed($invoice)
|
|
|
|
{
|
2013-12-26 01:36:34 +01:00
|
|
|
$this->sendNotifications($invoice, 'viewed');
|
2013-12-25 22:34:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function onPaid($invoice)
|
|
|
|
{
|
2013-12-26 01:36:34 +01:00
|
|
|
$this->sendNotifications($invoice, 'paid');
|
2013-12-25 22:34:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function sendNotifications($invoice, $type)
|
|
|
|
{
|
|
|
|
foreach ($invoice->account->users as $user)
|
|
|
|
{
|
|
|
|
if ($user->{'notify_' . $type})
|
|
|
|
{
|
|
|
|
$this->mailer->sendNotification($user, $invoice, $type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|