109 lines
3.2 KiB
PHP
109 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Notifications;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
use Illuminate\Notifications\Notification;
|
|
use App\Notifications\Channels\FcmChannel;
|
|
|
|
class WorkerNoResponseNotification extends Notification implements ShouldQueue
|
|
{
|
|
use Queueable;
|
|
|
|
public $type;
|
|
public $messageTitle;
|
|
public $messageBody;
|
|
public $daysElapsed;
|
|
public $entityType;
|
|
public $entityId;
|
|
|
|
/**
|
|
* Create a new notification instance.
|
|
*/
|
|
public function __construct($type, $messageTitle, $messageBody, $daysElapsed, $entityType, $entityId)
|
|
{
|
|
$this->type = $type;
|
|
$this->messageTitle = $messageTitle;
|
|
$this->messageBody = $messageBody;
|
|
$this->daysElapsed = $daysElapsed;
|
|
$this->entityType = $entityType;
|
|
$this->entityId = $entityId;
|
|
}
|
|
|
|
/**
|
|
* Get the notification's delivery channels.
|
|
*/
|
|
public function via($notifiable): array
|
|
{
|
|
$channels = ['database'];
|
|
|
|
// Determine if email channel should be included
|
|
$emailEnabled = true;
|
|
if (method_exists($notifiable, 'employerProfile') && $notifiable->employerProfile) {
|
|
$emailEnabled = (bool) ($notifiable->employerProfile->email_notifications ?? true);
|
|
}
|
|
if ($emailEnabled && !empty($notifiable->email)) {
|
|
$channels[] = 'mail';
|
|
}
|
|
|
|
// Determine if push channel should be included
|
|
$pushEnabled = true;
|
|
if (method_exists($notifiable, 'employerProfile') && $notifiable->employerProfile) {
|
|
$pushEnabled = (bool) ($notifiable->employerProfile->push_notifications ?? true);
|
|
}
|
|
if ($pushEnabled && !empty($notifiable->fcm_token)) {
|
|
$channels[] = FcmChannel::class;
|
|
}
|
|
|
|
return $channels;
|
|
}
|
|
|
|
/**
|
|
* Get the mail representation of the notification.
|
|
*/
|
|
public function toMail($notifiable): MailMessage
|
|
{
|
|
$name = $notifiable->name ?? $notifiable->full_name ?? 'User';
|
|
return (new MailMessage)
|
|
->subject($this->messageTitle)
|
|
->greeting("Hello {$name},")
|
|
->line($this->messageBody)
|
|
->action('View details', url('/dashboard'))
|
|
->line('Thank you for using our application!');
|
|
}
|
|
|
|
/**
|
|
* Get the array representation of the notification for in-app storage.
|
|
*/
|
|
public function toArray($notifiable): array
|
|
{
|
|
return [
|
|
'title' => $this->messageTitle,
|
|
'body' => $this->messageBody,
|
|
'type' => $this->type,
|
|
'days_elapsed' => $this->daysElapsed,
|
|
'entity_type' => $this->entityType,
|
|
'entity_id' => $this->entityId,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get the push notification representation.
|
|
*/
|
|
public function toFcm($notifiable): array
|
|
{
|
|
return [
|
|
'token' => $notifiable->fcm_token,
|
|
'title' => $this->messageTitle,
|
|
'body' => $this->messageBody,
|
|
'data' => [
|
|
'type' => $this->type,
|
|
'entity_id' => $this->entityId,
|
|
'days_elapsed' => $this->daysElapsed,
|
|
],
|
|
];
|
|
}
|
|
}
|