1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Services/EmailService.php
2017-01-30 21:40:43 +02:00

74 lines
1.4 KiB
PHP

<?php
namespace App\Services;
use App\Models\Invitation;
use App\Ninja\Mailers\UserMailer;
use Carbon;
/**
* Class EmailService.
*/
class EmailService
{
/**
* @var UserMailer
*/
protected $userMailer;
/**
* EmailService constructor.
*
* @param UserMailer $userMailer
*/
public function __construct(UserMailer $userMailer)
{
$this->userMailer = $userMailer;
}
/**
* @param $messageId
*
* @return bool
*/
public function markOpened($messageId)
{
/** @var \App\Models\Invitation $invitation */
$invitation = Invitation::whereMessageId($messageId)->first();
if (! $invitation) {
return false;
}
$invitation->opened_date = Carbon::now()->toDateTimeString();
$invitation->save();
return true;
}
/**
* @param $messageId
* @param $error
*
* @return bool
*/
public function markBounced($messageId, $error)
{
/** @var \App\Models\Invitation $invitation */
$invitation = Invitation::with('user', 'invoice', 'contact')
->whereMessageId($messageId)
->first();
if (! $invitation) {
return false;
}
$invitation->email_error = $error;
$invitation->save();
$this->userMailer->sendEmailBounced($invitation);
return true;
}
}