Files
Global-Jain/app/Jobs/Notifications/Sangh/SendAdminDeclineSangh.php
2025-11-05 10:37:10 +05:30

108 lines
4.3 KiB
PHP

<?php
namespace App\Jobs\Notifications\Sangh;
use App\Constant\Constant;
use Illuminate\Bus\Queueable;
use App\Models\UserDeviceToken;
use Illuminate\Support\Facades\Log;
use App\Traits\PushNotificationTraits;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
class SendAdminDeclineSangh implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, PushNotificationTraits;
/**
* @var
*/
protected $user;
/**
* @var
*/
protected $sangh;
/**
* @var
*/
protected $roleName;
/**
*
*/
public function __construct($user, $sangh, $roleName)
{
$this->user = $user;
$this->sangh = $sangh;
$this->roleName = $roleName;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
try {
//Push Notification to user when admin declines join request
$tokens = UserDeviceToken::where('user_id', $this->user->id)->get()->toArray();
$pushData = [];
$users = [];
if($tokens && $tokens > 0) {
foreach ($tokens as $token) {
$pushData['userToken'] = $token['token'] ?? [];
$pushData['title'] = trans('notifications.notification_title.admin_declined_sangh_request', ['sangh' => $this->sangh->name]);
$pushData['body'] = trans('notifications.sangh.admin_declined_invitation', ['sangh' => $this->sangh->name]);
$pushData['image'] = ($this->sangh->avatar) ? $this->sangh->avatar : "";
$pushData['from_id'] = $this->sangh->id;
$extraData = [];
$extraData['from_id'] = $this->sangh->id;
$extraData['user_id'] = $this->sangh->id ?? '';
$extraData['user_name'] = $this->sangh->name ?? '';
$extraData['user_type'] = 'sangh';
$extraData['type'] = trans('notifications.sangh_notification_type.admin-declined-member-request');
$extraData['created_at'] = date('Y/m/d H:i:s');
$extraData['os'] = $token['os'] ? getPlatform($token['os']) : [];
$pushData['extraData'] = $extraData ?? [];
$this->pushNotification($pushData, $extraData);
}
}
//Store Notification
$notificationData = [];
$notificationData['body'] = trans('notifications.sangh.admin_declined_invitation', ['sangh' => $this->sangh->name]);
$notificationData['user_id'] = $this->user->id;
$notificationData['type'] = trans('notifications.sangh_notification_type.admin-declined-member-request');
$notificationData['title'] = trans('notifications.notification_title.admin_declined_sangh_request', ['sangh' => $this->sangh->name]);
$extraNotificationData = [];
$extraNotificationData['from_id'] = $this->sangh->id ?? '';
$extraNotificationData['user_id'] = $this->sangh->id ?? '';
$extraNotificationData['name'] = $this->sangh->name ?? '';
$extraNotificationData['avatar'] = ($this->sangh->avatar) ? $this->sangh->avatar : "";
$extraNotificationData['sangh_id'] = $this->sangh->id ?? '';
$extraNotificationData['sangh_name'] = $this->sangh->name ?? '';
$extraNotificationData['role'] = $this->roleName ?? '';
$extraNotificationData['notification_type'] = Constant::STATUS_TWO;
$extraNotificationData['user_type'] = 'sangh';
$extraNotificationData['created_at'] = date('Y/m/d H:i:s');
$notificationData['extraNotificationData'] = $extraNotificationData ?? [];
if (!in_array($this->user->id, $users)) {
$users[$this->user->id] = $this->user->id;
$this->storeNotification($notificationData);
//Unread count increament
unreadNotificationCounter($this->user->id);
}
} catch (\Exception $ex) {
Log::error($ex);
}
}
}