mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-15 10:04:13 -08:00
151 lines
5 KiB
PHP
151 lines
5 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Mail;
|
||
|
|
||
|
use App\Helpers\Helper;
|
||
|
use App\Models\Asset;
|
||
|
use App\Models\Setting;
|
||
|
use App\Models\User;
|
||
|
use Illuminate\Bus\Queueable;
|
||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||
|
use Illuminate\Mail\Mailable;
|
||
|
use Illuminate\Mail\Mailables\Address;
|
||
|
use Illuminate\Mail\Mailables\Attachment;
|
||
|
use Illuminate\Mail\Mailables\Content;
|
||
|
use Illuminate\Mail\Mailables\Envelope;
|
||
|
use Illuminate\Notifications\Messages\MailMessage;
|
||
|
use Illuminate\Queue\SerializesModels;
|
||
|
|
||
|
class CheckoutAssetMail extends Mailable
|
||
|
{
|
||
|
use Queueable, SerializesModels;
|
||
|
|
||
|
/**
|
||
|
* Create a new message instance.
|
||
|
*/
|
||
|
public function __construct(Asset $asset, $checkedOutTo, User $checkedOutBy, $note, $acceptance)
|
||
|
{
|
||
|
$this->item = $asset;
|
||
|
$this->admin = $checkedOutBy;
|
||
|
$this->note = $note;
|
||
|
$this->target = $checkedOutTo;
|
||
|
$this->acceptance = $acceptance;
|
||
|
|
||
|
$this->settings = Setting::getSettings();
|
||
|
|
||
|
$this->last_checkout = '';
|
||
|
$this->expected_checkin = '';
|
||
|
|
||
|
if ($this->item->last_checkout) {
|
||
|
$this->last_checkout = Helper::getFormattedDateObject($this->item->last_checkout, 'date',
|
||
|
false);
|
||
|
}
|
||
|
|
||
|
if ($this->item->expected_checkin) {
|
||
|
$this->expected_checkin = Helper::getFormattedDateObject($this->item->expected_checkin, 'date',
|
||
|
false);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Get the message envelope.
|
||
|
*/
|
||
|
public function envelope(): Envelope
|
||
|
{
|
||
|
$from = null;
|
||
|
$cc = [];
|
||
|
|
||
|
if (!empty(Setting::getSettings()->alert_email)) {
|
||
|
$from = new Address(Setting::getSettings()->alert_email);
|
||
|
}
|
||
|
if (!empty(Setting::getSettings()->admin_cc_email)) {
|
||
|
$cc[] = new Address(Setting::getSettings()->admin_cc_email);
|
||
|
}
|
||
|
|
||
|
return new Envelope(
|
||
|
from: $from ?? new Address('default@example.com', 'Default Sender'),
|
||
|
cc: $cc,
|
||
|
subject: trans('mail.Asset_Checkout_Notification'),
|
||
|
);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Get the mail representation of the notification.
|
||
|
*
|
||
|
* @param mixed $notifiable
|
||
|
* @return Content
|
||
|
*/
|
||
|
public function content(): Content
|
||
|
{
|
||
|
$this->item->load('assetstatus');
|
||
|
$eula = method_exists($this->item, 'getEula') ? $this->item->getEula() : '';
|
||
|
$req_accept = method_exists($this->item, 'requireAcceptance') ? $this->item->requireAcceptance() : 0;
|
||
|
$fields = [];
|
||
|
|
||
|
// Check if the item has custom fields associated with it
|
||
|
if (($this->item->model) && ($this->item->model->fieldset)) {
|
||
|
$fields = $this->item->model->fieldset->fields;
|
||
|
}
|
||
|
|
||
|
$accept_url = is_null($this->acceptance) ? null : route('account.accept.item', $this->acceptance);
|
||
|
|
||
|
return new Content(
|
||
|
markdown: 'mail.markdown.checkout-asset',
|
||
|
with: [
|
||
|
'item' => $this->item,
|
||
|
'admin' => $this->admin,
|
||
|
'status' => $this->item->assetstatus?->name,
|
||
|
'note' => $this->note,
|
||
|
'target' => $this->target,
|
||
|
'fields' => $fields,
|
||
|
'eula' => $eula,
|
||
|
'req_accept' => $req_accept,
|
||
|
'accept_url' => $accept_url,
|
||
|
'last_checkout' => $this->last_checkout,
|
||
|
'expected_checkin' => $this->expected_checkin,
|
||
|
],
|
||
|
);
|
||
|
}
|
||
|
// public function build()
|
||
|
// {
|
||
|
// $this->item->load('assetstatus');
|
||
|
// $eula = method_exists($this->item, 'getEula') ? $this->item->getEula() : '';
|
||
|
// $req_accept = method_exists($this->item, 'requireAcceptance') ? $this->item->requireAcceptance() : 0;
|
||
|
// $fields = [];
|
||
|
//
|
||
|
// // Check if the item has custom fields associated with it
|
||
|
// if (($this->item->model) && ($this->item->model->fieldset)) {
|
||
|
// $fields = $this->item->model->fieldset->fields;
|
||
|
// }
|
||
|
//
|
||
|
// $accept_url = is_null($this->acceptance) ? null : route('account.accept.item', $this->acceptance);
|
||
|
//
|
||
|
// return $this
|
||
|
// ->subject('Asset Checkout Notification')
|
||
|
// ->markdown('notifications.markdown.checkout-asset')
|
||
|
// ->with([
|
||
|
// 'item' => $this->item,
|
||
|
// 'admin' => $this->admin,
|
||
|
// 'status' => $this->item->assetstatus?->name,
|
||
|
// 'note' => $this->note,
|
||
|
// 'target' => $this->target,
|
||
|
// 'fields' => $fields,
|
||
|
// 'eula' => $eula,
|
||
|
// 'req_accept' => $req_accept,
|
||
|
// 'accept_url' => $accept_url,
|
||
|
// 'last_checkout' => $this->last_checkout,
|
||
|
// 'expected_checkin' => $this->expected_checkin,
|
||
|
// ]);
|
||
|
// }
|
||
|
|
||
|
/**
|
||
|
* Get the attachments for the message.
|
||
|
*
|
||
|
* @return array<int, Attachment>
|
||
|
*/
|
||
|
public function attachments(): array
|
||
|
{
|
||
|
return [];
|
||
|
}
|
||
|
}
|