104 lines
3.5 KiB
PHP
104 lines
3.5 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 WorkerReviewReminderNotification extends Notification implements ShouldQueue
|
|
{
|
|
use Queueable;
|
|
|
|
public $employerName;
|
|
public $applicationId;
|
|
public $reviewLevel;
|
|
|
|
/**
|
|
* Create a new notification instance.
|
|
*/
|
|
public function __construct($employerName, $applicationId, $reviewLevel)
|
|
{
|
|
$this->employerName = $employerName;
|
|
$this->applicationId = $applicationId;
|
|
$this->reviewLevel = $reviewLevel;
|
|
}
|
|
|
|
/**
|
|
* 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("Review reminder: Rate your experience with {$this->employerName}")
|
|
->greeting("Hello {$name},")
|
|
->line("It has been {$this->reviewLevel} since you started working with {$this->employerName}.")
|
|
->line("Please take a moment to review and share your experience with {$this->employerName}.")
|
|
->action('Submit Review', url('/dashboard/reviews'))
|
|
->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' => "Review reminder: {$this->employerName}",
|
|
'body' => "Please take a moment to review and share your experience with {$this->employerName}.",
|
|
'employer_name' => $this->employerName,
|
|
'application_id' => $this->applicationId,
|
|
'review_level' => $this->reviewLevel,
|
|
'type' => 'review_employer_reminder',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get the push notification representation.
|
|
*/
|
|
public function toFcm($notifiable): array
|
|
{
|
|
return [
|
|
'token' => $notifiable->fcm_token,
|
|
'title' => "Review reminder: {$this->employerName}",
|
|
'body' => "Please take a moment to review and share your experience with {$this->employerName}.",
|
|
'data' => [
|
|
'type' => 'review_employer_reminder',
|
|
'application_id' => $this->applicationId,
|
|
'review_level' => $this->reviewLevel,
|
|
],
|
|
];
|
|
}
|
|
}
|