api code global jain
This commit is contained in:
101
app/Jobs/Notifications/Sant/SendRejectSant.php
Normal file
101
app/Jobs/Notifications/Sant/SendRejectSant.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?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 SendRejectSant implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, PushNotificationTraits;
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
protected $sant;
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
protected $rejectDesc;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct($user, $sant, $rejectDesc)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->sant = $sant;
|
||||
$this->rejectDesc = $rejectDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
//Push Notification to shravak who added
|
||||
$tokens = UserDeviceToken::where('user_id', $this->sant->updated_by)->get()->toArray();
|
||||
$pushData = [];
|
||||
$users = [];
|
||||
|
||||
if($tokens && $tokens > 0) {
|
||||
foreach ($tokens as $token) {
|
||||
$pushData['userToken'] = $token['token'] ?? [];
|
||||
$pushData['title'] = trans('notifications.notification_title.sant_rejected',['sant' => $this->sant->name]);
|
||||
$pushData['body'] = trans('notifications.push_sant.sant_rejected');
|
||||
$pushData['image'] = ($this->user->avatar) ? $this->user->avatar : "";
|
||||
$pushData['from_id'] = $this->sant->sant_id;
|
||||
$extraData = [];
|
||||
$extraData['user_id'] = $this->user->id ?? '';
|
||||
$extraData['user_name'] = $this->user->name ?? '';
|
||||
$extraData['user_type'] = 'sant';
|
||||
$extraData['type'] = trans('notifications.sant_notification_type.sant-rejected');
|
||||
$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 for rejected sant
|
||||
$notificationData = [];
|
||||
$notificationData['body'] = trans('notifications.sant.sant_rejected',['reason' => $this->rejectDesc]);
|
||||
$notificationData['user_id'] = $this->sant->updated_by;
|
||||
$notificationData['type'] = trans('notifications.sant_notification_type.sant-rejected');
|
||||
$notificationData['title'] = trans('notifications.notification_title.sant_rejected',['sant' => $this->sant->name]);
|
||||
$extraNotificationData = [];
|
||||
$extraNotificationData['from_id'] = $this->sant->sant_id ?? '';
|
||||
$extraNotificationData['user_id'] = $this->user->id ?? '';
|
||||
$extraNotificationData['name'] = $this->sant->name ?? '';
|
||||
$extraNotificationData['avatar'] = ($this->sant->avatar) ? $this->sant->avatar : "";
|
||||
$extraNotificationData['user_type'] = 'sant';
|
||||
$extraNotificationData['created_at'] = date('Y/m/d H:i:s');
|
||||
$notificationData['extraNotificationData'] = $extraNotificationData ?? [];
|
||||
|
||||
if (!in_array($this->sant->updated_by, $users)) {
|
||||
$users[$this->sant->updated_by] = $this->sant->updated_by;
|
||||
$this->storeNotification($notificationData);
|
||||
//Unread count increament
|
||||
unreadNotificationCounter($this->sant->updated_by);
|
||||
}
|
||||
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user