notification changes
This commit is contained in:
@@ -68,16 +68,16 @@ class ManageNotificationsController extends Controller
|
||||
->get();
|
||||
|
||||
$notifications = $notificationsOfType3->merge($notificationsOfType4);
|
||||
|
||||
$scheduledNotifications = NotificationDetails::where('is_schedule', 1)->where('is_active', 1)->orderByDesc('id')->get();
|
||||
}
|
||||
|
||||
return view('Admin.pages.manage_notification.manage_notification', compact('notifications'));
|
||||
return view('Admin.pages.manage_notification.manage_notification', compact('notifications', 'scheduledNotifications'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Created By : Sayli Raut
|
||||
* Created at : 10 June 2024
|
||||
* Use : To view notification details.s
|
||||
* Use : To view add notification.
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
@@ -88,180 +88,217 @@ class ManageNotificationsController extends Controller
|
||||
/**
|
||||
* Created By : Sayli Raut
|
||||
* Created at : 10 June 2024
|
||||
* Use : To add notification .
|
||||
* Use : To store notification .
|
||||
*/
|
||||
|
||||
public function store_notification_data(Request $request)
|
||||
{
|
||||
try {
|
||||
$request->validate([
|
||||
'image' => 'required|image|mimes:jpeg,png,jpg,gif|max:2048',
|
||||
]);
|
||||
public function store_notification_data(Request $request)
|
||||
{
|
||||
try {
|
||||
$request->validate([
|
||||
'image' => 'required|image|mimes:jpeg,png,jpg,gif|max:2048',
|
||||
]);
|
||||
|
||||
DB::beginTransaction();
|
||||
DB::beginTransaction();
|
||||
|
||||
$imagePath = null;
|
||||
if ($request->hasFile('image')) {
|
||||
$image = $request->file('image');
|
||||
$imagePath = saveSingleImageWithoutCrop($image, 'notification_images');
|
||||
$imagePath = ListingImageUrl('notification_images', $imagePath);
|
||||
}
|
||||
$imagePath = null;
|
||||
if ($request->hasFile('image')) {
|
||||
$image = $request->file('image');
|
||||
$imagePath = saveSingleImageWithoutCrop($image, 'notification_images');
|
||||
$imagePath = ListingImageUrl('notification_images', $imagePath);
|
||||
}
|
||||
|
||||
$states = $request->states;
|
||||
$dateTime = now();
|
||||
$formattedDateTime = $dateTime->format('Y-m-d H:i:s');
|
||||
$iamPrincipals = Subscriptions::select('iam_principal_xid')
|
||||
->where('next_payment_date', '>=', $formattedDateTime)
|
||||
->get();
|
||||
$iamPrincipalIds = $iamPrincipals->pluck('iam_principal_xid');
|
||||
$subscribe = IamPrincipal::whereIn('id', $iamPrincipalIds)
|
||||
->where('is_active', 1)
|
||||
->where('notification_status', 1)
|
||||
->where('principal_type_xid', 3)
|
||||
->whereIn('state_xid', $states)
|
||||
->get();
|
||||
$states = $request->states;
|
||||
$dateTime = now();
|
||||
$formattedDateTime = $dateTime->format('Y-m-d H:i:s');
|
||||
$iamPrincipals = Subscriptions::select('iam_principal_xid')
|
||||
->where('next_payment_date', '>=', $formattedDateTime)
|
||||
->get();
|
||||
$iamPrincipalIds = $iamPrincipals->pluck('iam_principal_xid');
|
||||
$subscribe = IamPrincipal::whereIn('id', $iamPrincipalIds)
|
||||
->where('is_active', 1)
|
||||
->where('notification_status', 1)
|
||||
->where('principal_type_xid', 3)
|
||||
->whereIn('state_xid', $states)
|
||||
->get();
|
||||
|
||||
$scheduled = false;
|
||||
$scheduled = false;
|
||||
|
||||
if ($request->user_type == 1) {
|
||||
$allCustomerOneSignalIds = $subscribe->pluck('id');
|
||||
$UserData = IamPrincipal::whereIn('id', $allCustomerOneSignalIds)->get();
|
||||
if ($request->user_type == 1) {
|
||||
$allCustomerOneSignalIds = $subscribe->pluck('id');
|
||||
$UserData = IamPrincipal::whereIn('id', $allCustomerOneSignalIds)->get();
|
||||
|
||||
if ($request->schedule_radio1 == 1 && $request->schedule_date) {
|
||||
NotificationDetails::create([
|
||||
'user_type' => $request->user_type,
|
||||
'description' => $request->description,
|
||||
'type' => $request->title,
|
||||
'image' => $imagePath,
|
||||
'date_added' => $request->schedule_date,
|
||||
'is_schedule' => 1,
|
||||
'delivery_schedule' => $request->schedule_date,
|
||||
'state_ids' => json_encode($states),
|
||||
]);
|
||||
$scheduled = true;
|
||||
} else {
|
||||
foreach ($UserData as $customerIdItem) {
|
||||
if ($customerIdItem->one_signal_player_id) {
|
||||
onesignalhelper::sendNotificationApi(
|
||||
$customerIdItem->one_signal_player_id,
|
||||
$request->title,
|
||||
$request->description,
|
||||
'Dashboard Notification',
|
||||
$imagePath,
|
||||
$id = null
|
||||
);
|
||||
}
|
||||
onesignalhelper::StoreNotificationDetails($customerIdItem->id, 'Notification', $request->title, $imagePath);
|
||||
}
|
||||
}
|
||||
} elseif ($request->user_type == 2) {
|
||||
$allPrincipalIds = IamPrincipal::where('principal_type_xid', 3)->pluck('id');
|
||||
$subscribedIds = Subscriptions::select('iam_principal_xid')
|
||||
->where('next_payment_date', '>=', $formattedDateTime)
|
||||
->pluck('iam_principal_xid');
|
||||
$unsubscribedIds = $allPrincipalIds->diff($subscribedIds);
|
||||
$unsubscribedPrincipals = IamPrincipal::whereIn('id', $unsubscribedIds)
|
||||
->where('is_active', 1)
|
||||
->where('notification_status', 1)
|
||||
->whereIn('state_xid', $states)
|
||||
->get();
|
||||
if ($request->schedule_radio1 == 1 && $request->schedule_date) {
|
||||
NotificationDetails::create([
|
||||
'user_type' => $request->user_type,
|
||||
'description' => $request->description,
|
||||
'type' => $request->title,
|
||||
'image' => $imagePath,
|
||||
'date_added' => $request->schedule_date,
|
||||
'is_schedule' => 1,
|
||||
'delivery_schedule' => $request->schedule_date,
|
||||
'state_ids' => json_encode($states),
|
||||
]);
|
||||
$scheduled = true;
|
||||
} else {
|
||||
foreach ($UserData as $customerIdItem) {
|
||||
if ($customerIdItem->one_signal_player_id) {
|
||||
onesignalhelper::sendNotificationApi(
|
||||
$customerIdItem->one_signal_player_id,
|
||||
$request->title,
|
||||
$request->description,
|
||||
'Dashboard Notification',
|
||||
$imagePath,
|
||||
$id = null
|
||||
);
|
||||
}
|
||||
onesignalhelper::StoreNotificationDetails($customerIdItem->id, 'Notification', $request->title, $imagePath);
|
||||
}
|
||||
}
|
||||
} elseif ($request->user_type == 2) {
|
||||
$allPrincipalIds = IamPrincipal::where('principal_type_xid', 3)->pluck('id');
|
||||
$subscribedIds = Subscriptions::select('iam_principal_xid')
|
||||
->where('next_payment_date', '>=', $formattedDateTime)
|
||||
->pluck('iam_principal_xid');
|
||||
$unsubscribedIds = $allPrincipalIds->diff($subscribedIds);
|
||||
$unsubscribedPrincipals = IamPrincipal::whereIn('id', $unsubscribedIds)
|
||||
->where('is_active', 1)
|
||||
->where('notification_status', 1)
|
||||
->whereIn('state_xid', $states)
|
||||
->get();
|
||||
|
||||
$allRestaurantOneSignalIds = $unsubscribedPrincipals->pluck('id');
|
||||
$restaurantData = IamPrincipal::whereIn('id', $allRestaurantOneSignalIds)->get();
|
||||
|
||||
if ($request->schedule_radio1 == 1 && $request->schedule_date) {
|
||||
NotificationDetails::create([
|
||||
'user_type' => $request->user_type,
|
||||
'description' => $request->description,
|
||||
'type' => $request->title,
|
||||
'image' => $imagePath,
|
||||
'date_added' => $request->schedule_date,
|
||||
'is_schedule' => 1,
|
||||
'delivery_schedule' => $request->schedule_date,
|
||||
'state_ids' => json_encode($states),
|
||||
]);
|
||||
$scheduled = true;
|
||||
} else {
|
||||
foreach ($restaurantData as $restaurantsData) {
|
||||
if ($restaurantsData->one_signal_player_id) {
|
||||
onesignalhelper::sendNotificationApi(
|
||||
$restaurantsData->one_signal_player_id,
|
||||
$request->title,
|
||||
$request->description,
|
||||
$request->title,
|
||||
$imagePath,
|
||||
$id = null
|
||||
);
|
||||
}
|
||||
onesignalhelper::StoreNotificationDetails($restaurantsData->id, 'Notification', $request->title, $imagePath);
|
||||
}
|
||||
}
|
||||
} elseif ($request->user_type == 3) {
|
||||
$userQuery = IamPrincipal::where('is_active', 1)
|
||||
->where('notification_status', 1)
|
||||
->where('principal_type_xid', 3)
|
||||
->whereIn('state_xid', $states);
|
||||
|
||||
$allUserOneSignalIds = $userQuery->pluck('id');
|
||||
$UserData = IamPrincipal::whereIn('id', $allUserOneSignalIds)->get();
|
||||
|
||||
if ($request->schedule_radio1 == 1 && $request->schedule_date) {
|
||||
NotificationDetails::create([
|
||||
'user_type' => $request->user_type,
|
||||
'description' => $request->description,
|
||||
'type' => $request->title,
|
||||
'image' => $imagePath,
|
||||
'date_added' => $request->schedule_date,
|
||||
'is_schedule' => 1,
|
||||
'delivery_schedule' => $request->schedule_date,
|
||||
'state_ids' => json_encode($states),
|
||||
]);
|
||||
$scheduled = true;
|
||||
} else {
|
||||
foreach ($UserData as $CustomerData) {
|
||||
if ($CustomerData->one_signal_player_id) {
|
||||
onesignalhelper::sendNotificationApi(
|
||||
$CustomerData->one_signal_player_id,
|
||||
$request->title,
|
||||
$request->description,
|
||||
'Dashboard Notification',
|
||||
$imagePath,
|
||||
$id = null
|
||||
);
|
||||
}
|
||||
onesignalhelper::StoreNotificationDetails($CustomerData->id, 'Notification', $request->title, $imagePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
if ($scheduled) {
|
||||
return jsonResponseWithSuccessMessage(__('success.save_data_scheduled'));
|
||||
} else {
|
||||
return jsonResponseWithSuccessMessage(__('success.save_data_immediate'));
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
DB::rollBack();
|
||||
Log::error("Notification send Failed " . $e->getMessage());
|
||||
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
|
||||
}
|
||||
}
|
||||
$allRestaurantOneSignalIds = $unsubscribedPrincipals->pluck('id');
|
||||
$restaurantData = IamPrincipal::whereIn('id', $allRestaurantOneSignalIds)->get();
|
||||
|
||||
if ($request->schedule_radio1 == 1 && $request->schedule_date) {
|
||||
NotificationDetails::create([
|
||||
'user_type' => $request->user_type,
|
||||
'description' => $request->description,
|
||||
'type' => $request->title,
|
||||
'image' => $imagePath,
|
||||
'date_added' => $request->schedule_date,
|
||||
'is_schedule' => 1,
|
||||
'delivery_schedule' => $request->schedule_date,
|
||||
'state_ids' => json_encode($states),
|
||||
]);
|
||||
$scheduled = true;
|
||||
} else {
|
||||
foreach ($restaurantData as $restaurantsData) {
|
||||
if ($restaurantsData->one_signal_player_id) {
|
||||
onesignalhelper::sendNotificationApi(
|
||||
$restaurantsData->one_signal_player_id,
|
||||
$request->title,
|
||||
$request->description,
|
||||
$request->title,
|
||||
$imagePath,
|
||||
$id = null
|
||||
);
|
||||
}
|
||||
onesignalhelper::StoreNotificationDetails($restaurantsData->id, 'Notification', $request->title, $imagePath);
|
||||
}
|
||||
}
|
||||
} elseif ($request->user_type == 3) {
|
||||
$userQuery = IamPrincipal::where('is_active', 1)
|
||||
->where('notification_status', 1)
|
||||
->where('principal_type_xid', 3)
|
||||
->whereIn('state_xid', $states);
|
||||
|
||||
$allUserOneSignalIds = $userQuery->pluck('id');
|
||||
$UserData = IamPrincipal::whereIn('id', $allUserOneSignalIds)->get();
|
||||
|
||||
if ($request->schedule_radio1 == 1 && $request->schedule_date) {
|
||||
NotificationDetails::create([
|
||||
'user_type' => $request->user_type,
|
||||
'description' => $request->description,
|
||||
'type' => $request->title,
|
||||
'image' => $imagePath,
|
||||
'date_added' => $request->schedule_date,
|
||||
'is_schedule' => 1,
|
||||
'delivery_schedule' => $request->schedule_date,
|
||||
'state_ids' => json_encode($states),
|
||||
]);
|
||||
$scheduled = true;
|
||||
} else {
|
||||
foreach ($UserData as $CustomerData) {
|
||||
if ($CustomerData->one_signal_player_id) {
|
||||
onesignalhelper::sendNotificationApi(
|
||||
$CustomerData->one_signal_player_id,
|
||||
$request->title,
|
||||
$request->description,
|
||||
'Dashboard Notification',
|
||||
$imagePath,
|
||||
$id = null
|
||||
);
|
||||
}
|
||||
onesignalhelper::StoreNotificationDetails($CustomerData->id, 'Notification', $request->title, $imagePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
if ($scheduled) {
|
||||
return jsonResponseWithSuccessMessage(__('success.save_data_scheduled'));
|
||||
} else {
|
||||
return jsonResponseWithSuccessMessage(__('success.save_data_immediate'));
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
DB::rollBack();
|
||||
Log::error("Notification send Failed " . $e->getMessage());
|
||||
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Created By : Sayli Raut
|
||||
* Created at : 10 June 2024
|
||||
* Use : To view notification details.s
|
||||
* Use : To view notification detail.
|
||||
*/
|
||||
public function view($id)
|
||||
{
|
||||
$notification = NotificationDetails::with('notification')->findOrFail($id);
|
||||
return view('Admin.pages.manage_notification.manage_notifications_view', compact('notification'));
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$edit_notification = NotificationDetails::findOrFail($id);
|
||||
$states = ManageState::where('is_active', 1)->get();
|
||||
return view('Admin.pages.manage_notification.manage_notification_edit', compact('edit_notification', 'states'));
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
try {
|
||||
|
||||
|
||||
$notification = NotificationDetails::findOrFail($request->id);
|
||||
|
||||
$notification->type = $request->type;
|
||||
$notification->description = $request->description;
|
||||
$notification->delivery_schedule = $request->delivery_schedule;
|
||||
if ($request->hasFile('image')) {
|
||||
$image = $request->file('image');
|
||||
$imagePath = saveSingleImageWithoutCrop($image, 'notification_images');
|
||||
$imagePath = ListingImageUrl('notification_images', $imagePath);
|
||||
$notification->image = $imagePath;
|
||||
}
|
||||
$notification->user_type = $request->user_type;
|
||||
$notification->state_ids = json_encode($request->state_ids);
|
||||
$notification->save();
|
||||
return jsonResponseWithSuccessMessage(__('success.save_data_scheduled'));
|
||||
|
||||
} catch (Exception $e) {
|
||||
DB::rollBack();
|
||||
Log::error("Notification update Failed " . $e->getMessage());
|
||||
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$data = NotificationDetails::find($id)->delete();
|
||||
return redirect()->back()->with('success', '');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user