1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00
invoiceninja/app/Services/EmailService.php
Holger Lösken 0fbda85a59 Code Refactoring
- Removed unused uses
- Type hinting for method parameters
- Removed commented code
- Introduced comments for classes and methods
- Short array syntax
2016-07-03 16:19:22 +00:00

69 lines
1.4 KiB
PHP

<?php namespace App\Services;
use Carbon;
use App\Models\Invitation;
use App\Ninja\Mailers\UserMailer;
/**
* 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;
}
}