1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00
invoiceninja/app/Services/EmailService.php

74 lines
1.4 KiB
PHP
Raw Normal View History

2017-01-30 20:40:43 +01:00
<?php
namespace App\Services;
2015-10-11 16:41:09 +02:00
use App\Models\Invitation;
use App\Ninja\Mailers\UserMailer;
2017-01-30 20:40:43 +01:00
use Carbon;
2015-10-11 16:41:09 +02:00
/**
2017-01-30 20:40:43 +01:00
* Class EmailService.
*/
class EmailService
{
/**
* @var UserMailer
*/
2015-10-11 16:41:09 +02:00
protected $userMailer;
/**
* EmailService constructor.
*
* @param UserMailer $userMailer
*/
2015-10-11 16:41:09 +02:00
public function __construct(UserMailer $userMailer)
{
$this->userMailer = $userMailer;
}
/**
* @param $messageId
2017-01-30 20:40:43 +01:00
*
* @return bool
*/
2015-10-11 16:41:09 +02:00
public function markOpened($messageId)
{
/** @var \App\Models\Invitation $invitation */
$invitation = Invitation::whereMessageId($messageId)->first();
2015-10-11 16:41:09 +02:00
2017-01-30 20:40:43 +01:00
if (! $invitation) {
2015-10-11 16:41:09 +02:00
return false;
}
$invitation->opened_date = Carbon::now()->toDateTimeString();
$invitation->save();
return true;
}
/**
* @param $messageId
* @param $error
2017-01-30 20:40:43 +01:00
*
* @return bool
*/
2015-10-11 16:41:09 +02:00
public function markBounced($messageId, $error)
{
/** @var \App\Models\Invitation $invitation */
2015-10-11 16:41:09 +02:00
$invitation = Invitation::with('user', 'invoice', 'contact')
->whereMessageId($messageId)
->first();
2017-01-30 20:40:43 +01:00
if (! $invitation) {
2015-10-11 16:41:09 +02:00
return false;
}
$invitation->email_error = $error;
$invitation->save();
$this->userMailer->sendEmailBounced($invitation);
return true;
}
2017-01-30 17:05:31 +01:00
}