mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Create Notifications classes for accepted and declined and add some necesary lang strings
This commit is contained in:
parent
c7d9baad8e
commit
509bbbc685
102
app/Notifications/AcceptanceAssetAcceptedNotification.php
Normal file
102
app/Notifications/AcceptanceAssetAcceptedNotification.php
Normal file
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Messages\SlackMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class AcceptanceAssetAcceptedNotification extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
$this->target = $params['target'];
|
||||
$this->item = $params['item'];
|
||||
$this->item_type = $params['item_type'];
|
||||
$this->item_quantity = $params['item_quantity'];
|
||||
$this->note = '';
|
||||
$this->last_checkout = '';
|
||||
$this->expected_checkin = '';
|
||||
$this->requested_date = Helper::getFormattedDateObject($params['requested_date'], 'datetime',
|
||||
false);
|
||||
$this->settings = Setting::getSettings();
|
||||
|
||||
if (array_key_exists('note', $params)) {
|
||||
$this->note = $params['note'];
|
||||
}
|
||||
|
||||
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 notification's delivery channels.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function via()
|
||||
{
|
||||
$notifyBy = [];
|
||||
|
||||
if (Setting::getSettings()->slack_endpoint != '') {
|
||||
$notifyBy[] = 'slack';
|
||||
}
|
||||
|
||||
$notifyBy[] = 'mail';
|
||||
|
||||
return $notifyBy;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||
*/
|
||||
public function toMail()
|
||||
{
|
||||
$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;
|
||||
}
|
||||
|
||||
$message = (new MailMessage)->markdown('notifications.markdown.asset-requested',
|
||||
[
|
||||
'item' => $this->item,
|
||||
'note' => $this->note,
|
||||
'requested_by' => $this->target,
|
||||
'requested_date' => $this->requested_date,
|
||||
'fields' => $fields,
|
||||
'last_checkout' => $this->last_checkout,
|
||||
'expected_checkin' => $this->expected_checkin,
|
||||
'intro_text' => trans('mail.acceptance_asset_accepted'),
|
||||
'qty' => $this->item_quantity,
|
||||
])
|
||||
->subject(trans('mail.acceptance_asset_accepted'));
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
}
|
102
app/Notifications/AcceptanceAssetDeclinedNotification.php
Normal file
102
app/Notifications/AcceptanceAssetDeclinedNotification.php
Normal file
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Messages\SlackMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class AcceptanceAssetDeclinedNotification extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
$this->target = $params['target'];
|
||||
$this->item = $params['item'];
|
||||
$this->item_type = $params['item_type'];
|
||||
$this->item_quantity = $params['item_quantity'];
|
||||
$this->note = '';
|
||||
$this->last_checkout = '';
|
||||
$this->expected_checkin = '';
|
||||
$this->requested_date = Helper::getFormattedDateObject($params['requested_date'], 'datetime',
|
||||
false);
|
||||
$this->settings = Setting::getSettings();
|
||||
|
||||
if (array_key_exists('note', $params)) {
|
||||
$this->note = $params['note'];
|
||||
}
|
||||
|
||||
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 notification's delivery channels.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
$notifyBy = [];
|
||||
|
||||
if (Setting::getSettings()->slack_endpoint != '') {
|
||||
$notifyBy[] = 'slack';
|
||||
}
|
||||
|
||||
$notifyBy[] = 'mail';
|
||||
|
||||
return $notifyBy;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||
*/
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
$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;
|
||||
}
|
||||
|
||||
$message = (new MailMessage)->markdown('notifications.markdown.asset-requested',
|
||||
[
|
||||
'item' => $this->item,
|
||||
'note' => $this->note,
|
||||
'requested_by' => $this->target,
|
||||
'requested_date' => $this->requested_date,
|
||||
'fields' => $fields,
|
||||
'last_checkout' => $this->last_checkout,
|
||||
'expected_checkin' => $this->expected_checkin,
|
||||
'intro_text' => trans('mail.acceptance_asset_declined'),
|
||||
'qty' => $this->item_quantity,
|
||||
])
|
||||
->subject(trans('mail.acceptance_asset_declined'));
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'acceptance_asset_accepted' => 'A user has accepted an item',
|
||||
'acceptance_asset_declined' => 'A user has declined an item',
|
||||
'a_user_canceled' => 'A user has canceled an item request on the website',
|
||||
'a_user_requested' => 'A user has requested an item on the website',
|
||||
'accessory_name' => 'Accessory Name:',
|
||||
|
|
Loading…
Reference in a new issue