1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-23 18:01:35 +02:00
invoiceninja/app/handlers/InvoiceEventHandler.php
2013-12-25 16:34:42 -05:00

46 lines
816 B
PHP
Executable File

<?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)
{
}
public function onPaid($invoice)
{
}
private function sendNotifications($invoice, $type)
{
foreach ($invoice->account->users as $user)
{
if ($user->{'notify_' . $type})
{
$this->mailer->sendNotification($user, $invoice, $type);
}
}
}
}