1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/app/Handlers/InvoiceEventHandler.php
Jeramy Simpson 6ae6a29117 Fix Ninja Namespace
Also includes other minor clean ups and L5 syntax changes
2015-03-24 18:21:12 +10:00

51 lines
1.2 KiB
PHP

<?php namespace App\Handlers;
use App\Ninja\Mailers\UserMailer;
use App\Ninja\Mailers\ContactMailer;
class InvoiceEventHandler
{
protected $userMailer;
protected $contactMailer;
public function __construct(UserMailer $userMailer, ContactMailer $contactMailer)
{
$this->userMailer = $userMailer;
$this->contactMailer = $contactMailer;
}
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)
{
$this->sendNotifications($invoice, 'viewed');
}
public function onPaid($payment)
{
$this->contactMailer->sendPaymentConfirmation($payment);
$this->sendNotifications($payment->invoice, 'paid', $payment);
}
private function sendNotifications($invoice, $type, $payment = null)
{
foreach ($invoice->account->users as $user)
{
if ($user->{'notify_' . $type})
{
$this->userMailer->sendNotification($user, $invoice, $type, $payment);
}
}
}
}