84 lines
2.9 KiB
PHP
84 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Constant\Constant;
|
|
use App\Mail\CertificateApprovedForHospitalMail;
|
|
use App\Mail\CertificateApprovedForPatientMail;
|
|
use App\Models\UserDeviceToken;
|
|
use App\Traits\PushNotificationTraits;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
class CertificateApprovedJob implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, PushNotificationTraits;
|
|
|
|
protected $certificate;
|
|
/**
|
|
* Create a new job instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct($certificate)
|
|
{
|
|
$this->certificate = $certificate;
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function handle()
|
|
{
|
|
//Patient
|
|
$email = new CertificateApprovedForPatientMail($this->certificate);
|
|
Mail::to($this->certificate->email)->queue($email);
|
|
|
|
//Hospital Admin
|
|
$email = new CertificateApprovedForHospitalMail($this->certificate);
|
|
Mail::to($this->certificate?->hospital?->email)->queue($email);
|
|
|
|
//Push Notification to user on comment
|
|
$tokens = UserDeviceToken::where('user_id', $this->certificate->user_id)->get()->toArray();
|
|
$pushData = [];
|
|
$users = [];
|
|
|
|
if($tokens && $tokens > 0) {
|
|
foreach ($tokens as $token) {
|
|
$pushData['userToken'] = $token['token'] ?? [];
|
|
$pushData['title'] = "JHC Letter Status";
|
|
$pushData['body'] = "JHC letter is approved. wishing you a speedy recovery.";
|
|
$extraData = [];
|
|
$extraData['type'] = "JHCStatus";
|
|
$extraData['os'] = $token['os'] ? getPlatform($token['os']) : [];
|
|
|
|
$pushData['extraData'] = $extraData ?? [];
|
|
$this->pushNotification($pushData, $extraData);
|
|
}
|
|
}
|
|
//Store Notification
|
|
$notificationData = [];
|
|
$notificationData['body'] = "JHC letter is approved. wishing you a speedy recovery.";
|
|
$notificationData['type'] = "JHCStatus";
|
|
$notificationData['title'] = "JHC Letter Status";
|
|
$extraNotificationData = [];
|
|
$notificationData['user_id'] = $this->certificate->user_id ?? '';
|
|
$extraNotificationData['notification_type'] = Constant::STATUS_ONE;
|
|
$notificationData['extraNotificationData'] = $extraNotificationData ?? [];
|
|
|
|
if (!in_array($this->certificate->user_id, $users)) {
|
|
$users[$this->certificate->user_id] = $this->certificate->user_id;
|
|
$this->storeNotification($notificationData);
|
|
//Unread count increment
|
|
unreadNotificationCounter($this->certificate->user_id);
|
|
}
|
|
}
|
|
}
|