96 lines
3.7 KiB
PHP
96 lines
3.7 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Jobs\Notifications\Sant;
|
||
|
|
|
||
|
|
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 SendRejectThana implements ShouldQueue
|
||
|
|
{
|
||
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, PushNotificationTraits;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @var
|
||
|
|
*/
|
||
|
|
protected $thana;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @var
|
||
|
|
*/
|
||
|
|
protected $removedSant;
|
||
|
|
|
||
|
|
/**
|
||
|
|
*
|
||
|
|
*/
|
||
|
|
public function __construct($thana, $removedSant)
|
||
|
|
{
|
||
|
|
$this->thana = $thana;
|
||
|
|
$this->removedSant = $removedSant;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Execute the job.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function handle()
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
//Push Notification to shravak who added
|
||
|
|
$tokens = UserDeviceToken::where('user_id', $this->thana->created_by)->get()->toArray();
|
||
|
|
$pushData = [];
|
||
|
|
$users = [];
|
||
|
|
|
||
|
|
if ($tokens && $tokens > 0) {
|
||
|
|
foreach ($tokens as $token) {
|
||
|
|
$data['userToken'] = $token['token'] ?? [];
|
||
|
|
$data['title'] = trans('notifications.notification_title.thana_rejected');
|
||
|
|
$data['body'] = trans('notifications.sant.thana_rejected',['sant' => $this->removedSant->name]);
|
||
|
|
$data['image'] = ($this->removedSant->avatar) ? $this->removedSant->avatar : "";
|
||
|
|
$data['from_id'] = $this->removedSant->id;
|
||
|
|
$extraData = [];
|
||
|
|
$extraData['user_id'] = $this->thana['created_by'] ?? '';
|
||
|
|
$extraData['user_name'] = $this->removedSant->name ?? '';
|
||
|
|
$extraData['user_type'] = 'sant';
|
||
|
|
$extraData['type'] = trans('notifications.sant_notification_type.thana-rejected');
|
||
|
|
$extraData['created_at'] = date('Y/m/d H:i:s');
|
||
|
|
$extraData['os'] = $token['os'] ? getPlatform($token['os']) : [];
|
||
|
|
|
||
|
|
$data['extraData'] = $extraData ?? [];
|
||
|
|
$this->pushNotification($data, $extraData);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
//Store notification for reject thana
|
||
|
|
$notificationData = [];
|
||
|
|
$notificationData['body'] = trans('notifications.sant.thana_rejected',['sant' => $this->removedSant->name]);
|
||
|
|
$notificationData['user_id'] = $this->thana['created_by'];
|
||
|
|
$notificationData['type'] = trans('notifications.sant_notification_type.thana-rejected');
|
||
|
|
$notificationData['title'] = trans('notifications.notification_title.thana_rejected');
|
||
|
|
$extraNotificationData = [];
|
||
|
|
$extraNotificationData['from_id'] = $this->removedSant->id ?? '';
|
||
|
|
$extraNotificationData['user_id'] = $this->thana['created_by'] ?? '';
|
||
|
|
$extraNotificationData['name'] = $this->removedSant->name ?? '';
|
||
|
|
$extraNotificationData['avatar'] = ($this->removedSant->avatar) ? $this->removedSant->avatar : "";
|
||
|
|
$extraNotificationData['user_type'] = 'sant';
|
||
|
|
$extraNotificationData['created_at'] = date('Y/m/d H:i:s');
|
||
|
|
$notificationData['extraNotificationData'] = $extraNotificationData ?? [];
|
||
|
|
|
||
|
|
if (!in_array($this->thana['created_by'], $users)) {
|
||
|
|
$users[$this->thana['created_by']] = $this->thana['created_by'];
|
||
|
|
$this->storeNotification($notificationData);
|
||
|
|
//Unread count increament
|
||
|
|
unreadNotificationCounter($this->thana['created_by']);
|
||
|
|
}
|
||
|
|
|
||
|
|
} catch (\Exception $ex) {
|
||
|
|
Log::error($ex);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|