notification

This commit is contained in:
sayliraut
2024-07-18 16:14:58 +05:30
parent 534b0d8d29
commit 5399d2814b
5 changed files with 137 additions and 106 deletions

View File

@@ -27,6 +27,7 @@ class ManageNotificationsController extends Controller
if ($activeQuery == 4) { // for customer
$notifications = NotificationDetails::with('Notification')
->where('is_active', 1)
->where('is_schedule', 0)
->whereHas('Notification', function ($query) {
$query->where('principal_type_xid', 3);
})
@@ -36,6 +37,7 @@ class ManageNotificationsController extends Controller
} else if ($activeQuery == 3) { // for restaurant
$notifications = NotificationDetails::with('Notification')
->where('is_active', 1)
->where('is_schedule', 0)
->whereHas('Notification', function ($query) {
$query->where('principal_type_xid', 4);
})
@@ -47,6 +49,7 @@ class ManageNotificationsController extends Controller
} else {
$notificationsOfType3 = NotificationDetails::with('Notification')
->where('is_active', 1)
->where('is_schedule', 0)
->whereHas('Notification', function ($query) {
$query->where('principal_type_xid', 3);
})
@@ -56,6 +59,7 @@ class ManageNotificationsController extends Controller
$notificationsOfType4 = NotificationDetails::with('Notification')
->where('is_active', 1)
->where('is_schedule', 0)
->whereHas('Notification', function ($query) {
$query->where('principal_type_xid', 4);
})
@@ -64,6 +68,7 @@ class ManageNotificationsController extends Controller
->get();
$notifications = $notificationsOfType3->merge($notificationsOfType4);
}
return view('Admin.pages.manage_notification.manage_notification', compact('notifications'));
@@ -86,7 +91,7 @@ class ManageNotificationsController extends Controller
* Use : To add notification .
*/
public function store_notificaton_data(Request $request)
public function store_notification_data(Request $request)
{
try {
$request->validate([
@@ -95,27 +100,20 @@ class ManageNotificationsController extends Controller
DB::beginTransaction();
if (isset($request->image)) {
$image = $request->image;
$image_db = null;
} else {
$image = null;
$image_db = $request->image;
$imagePath = null;
if ($request->hasFile('image')) {
$image = $request->file('image');
$imagePath = saveSingleImageWithoutCrop($image, 'notification_images');
$imagePath = ListingImageUrl('notification_images', $imagePath);
}
$tnormalImage = saveSingleImageWithoutCrop($image, 'notification_images', $image_db);
$imagePath = ListingImageUrl('notification_images', $tnormalImage);
$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)
@@ -129,23 +127,20 @@ class ManageNotificationsController extends Controller
$allCustomerOneSignalIds = $subscribe->pluck('id');
$UserData = IamPrincipal::whereIn('id', $allCustomerOneSignalIds)->get();
foreach ($UserData as $customerIdItem) {
// user_type 1 = subscribed user
if ($request->schedule_radio1 == 1 && $request->schedule_date) {
// Scheduled Notification
NotificationDetails::create([
'principal_xid' => $customerIdItem->id,
'description' => $request->description,
'type' => $request->title,
'image' => $imagePath,
'date_added' => $request->schedule_date,
'is_schedule' => 1,
'delivery_schedule' => $request->schedule_date,
'is_active' => 0,
]);
$scheduled = true;
} else {
// Immediate Notification
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,
@@ -160,16 +155,11 @@ class ManageNotificationsController extends Controller
}
}
} elseif ($request->user_type == 2) {
// user_type 2 unsubscribed users
$allPrincipalIds = IamPrincipal::where('principal_type_xid', 3)
->pluck('id');
$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)
@@ -179,22 +169,20 @@ class ManageNotificationsController extends Controller
$allRestaurantOneSignalIds = $unsubscribedPrincipals->pluck('id');
$restaurantData = IamPrincipal::whereIn('id', $allRestaurantOneSignalIds)->get();
foreach ($restaurantData as $restaurantsData) {
if ($request->schedule_radio1 == 1 && $request->schedule_date) {
// Scheduled Notification
NotificationDetails::create([
'principal_xid' => $restaurantsData->id,
'description' => $request->description,
'type' => $request->title,
'image' => $imagePath,
'date_added' => $request->schedule_date,
'is_schedule' => 1,
'delivery_schedule' => $request->schedule_date,
'is_active' => 0,
]);
$scheduled = true;
} else {
// Immediate Notification
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,
@@ -209,7 +197,6 @@ class ManageNotificationsController extends Controller
}
}
} elseif ($request->user_type == 3) {
// user_type 3 = subscribed and unsubscribed users
$userQuery = IamPrincipal::where('is_active', 1)
->where('notification_status', 1)
->where('principal_type_xid', 3)
@@ -218,22 +205,20 @@ class ManageNotificationsController extends Controller
$allUserOneSignalIds = $userQuery->pluck('id');
$UserData = IamPrincipal::whereIn('id', $allUserOneSignalIds)->get();
foreach ($UserData as $CustomerData) {
if ($request->schedule_radio1 == 1 && $request->schedule_date) {
// Scheduled Notification
NotificationDetails::create([
'principal_xid' => $CustomerData->id,
'description' => $request->description,
'type' => $request->title,
'image' => $imagePath,
'date_added' => $request->schedule_date,
'is_schedule' => 1,
'delivery_schedule' => $request->schedule_date,
'is_active' => 0,
]);
$scheduled = true;
} else {
// Immediate Notification
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,
@@ -268,6 +253,7 @@ class ManageNotificationsController extends Controller
/**
* Created By : Sayli Raut
* Created at : 10 June 2024