Merge branch 'main' of https://github.com/WDI-Ideas/cheerstothe_season_laravel11 into HritikCheers
This commit is contained in:
@@ -81,78 +81,94 @@ class ManageNotificationsController extends Controller
|
||||
* Use : To add notification .
|
||||
*/
|
||||
public function store_notificaton_data(Request $request)
|
||||
{
|
||||
try {
|
||||
$request->validate([
|
||||
'image' => 'required|image|mimes:jpeg,png,jpg,gif|max:2048',
|
||||
]);
|
||||
{
|
||||
try {
|
||||
$request->validate([
|
||||
'image' => 'required|image|mimes:jpeg,png,jpg,gif|max:2048',
|
||||
]);
|
||||
|
||||
DB::beginTransaction();
|
||||
DB::beginTransaction();
|
||||
|
||||
if (isset($request->image)) {
|
||||
$image = $request->image;
|
||||
$image_db = null;
|
||||
} else {
|
||||
$image = null;
|
||||
$image_db = $request->image;
|
||||
}
|
||||
|
||||
$tnormalImage = saveSingleImageWithoutCrop($image, 'notification_images', $image_db);
|
||||
$imagePath = ListingImageUrl('notification_images', $tnormalImage);
|
||||
|
||||
// Fetch OneSignal IDs based on the selected states and user type
|
||||
$states = $request->states;
|
||||
|
||||
$userQuery = IamPrincipal::where('is_active', 1)
|
||||
->where('notification_status', 1)
|
||||
->where('principal_type_xid', 3)
|
||||
->whereIn('state_xid', $states);
|
||||
|
||||
|
||||
if ($request->user_type == 1) {
|
||||
$allCustomerOneSignalIds = $userQuery->pluck('id');
|
||||
$UserData = IamPrincipal::whereIn('id', $allCustomerOneSignalIds)->get();
|
||||
|
||||
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);
|
||||
if (isset($request->image)) {
|
||||
$image = $request->image;
|
||||
$image_db = null;
|
||||
} else {
|
||||
$image = null;
|
||||
$image_db = $request->image;
|
||||
}
|
||||
} elseif ($request->user_type == 2) {
|
||||
$allRestaurantOneSignalIds = $userQuery->pluck('id');
|
||||
$restaurantData = IamPrincipal::whereIn('id', $allRestaurantOneSignalIds)->get();
|
||||
|
||||
foreach ($restaurantData as $restIdItem) {
|
||||
if ($restIdItem->one_signal_player_id) {
|
||||
onesignalhelper::sendNotificationApi(
|
||||
$restIdItem->one_signal_player_id,
|
||||
$request->title,
|
||||
$request->description,
|
||||
'Dashboard Notification',
|
||||
$imagePath,
|
||||
$id = null
|
||||
);
|
||||
$tnormalImage = saveSingleImageWithoutCrop($image, 'notification_images', $image_db);
|
||||
$imagePath = ListingImageUrl('notification_images', $tnormalImage);
|
||||
|
||||
$states = $request->states;
|
||||
|
||||
$userQuery = IamPrincipal::where('is_active', 1)
|
||||
->where('notification_status', 1)
|
||||
->where('principal_type_xid', 3)
|
||||
->whereIn('state_xid', $states);
|
||||
|
||||
if ($request->user_type == 1) {
|
||||
$allCustomerOneSignalIds = $userQuery->pluck('id');
|
||||
$UserData = IamPrincipal::whereIn('id', $allCustomerOneSignalIds)->get();
|
||||
|
||||
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);
|
||||
}
|
||||
onesignalhelper::StoreNotificationDetails($restIdItem->id, 'Notification', $request->title, $imagePath);
|
||||
}
|
||||
}
|
||||
} elseif ($request->user_type == 2) {
|
||||
$allRestaurantOneSignalIds = $userQuery->pluck('id');
|
||||
$restaurantData = IamPrincipal::whereIn('id', $allRestaurantOneSignalIds)->get();
|
||||
|
||||
DB::commit();
|
||||
return jsonResponseWithSuccessMessage(__('success.save_data'));
|
||||
} catch (Exception $e) {
|
||||
DB::rollBack();
|
||||
Log::error("Notification send Failed " . $e->getMessage());
|
||||
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
|
||||
foreach ($restaurantData as $restIdItem) {
|
||||
if ($restIdItem->one_signal_player_id) {
|
||||
onesignalhelper::sendNotificationApi(
|
||||
$restIdItem->one_signal_player_id,
|
||||
$request->title,
|
||||
$request->description,
|
||||
'Dashboard Notification',
|
||||
$imagePath,
|
||||
$id = null
|
||||
);
|
||||
}
|
||||
onesignalhelper::StoreNotificationDetails($restIdItem->id, 'Notification', $request->title, $imagePath);
|
||||
}
|
||||
} elseif ($request->user_type == 3) {
|
||||
$allUserOneSignalIds = $userQuery->pluck('id');
|
||||
$UserData = IamPrincipal::whereIn('id', $allUserOneSignalIds)->get();
|
||||
|
||||
foreach ($UserData as $userItem) {
|
||||
if ($userItem->one_signal_player_id) {
|
||||
onesignalhelper::sendNotificationApi(
|
||||
$userItem->one_signal_player_id,
|
||||
$request->title,
|
||||
$request->description,
|
||||
'Dashboard Notification',
|
||||
$imagePath,
|
||||
$id = null
|
||||
);
|
||||
}
|
||||
onesignalhelper::StoreNotificationDetails($userItem->id, 'Notification', $request->title, $imagePath);
|
||||
}
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
return jsonResponseWithSuccessMessage(__('success.save_data'));
|
||||
} catch (Exception $e) {
|
||||
DB::rollBack();
|
||||
Log::error("Notification send Failed " . $e->getMessage());
|
||||
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -71,13 +71,19 @@
|
||||
users who are in their respective states</label><br>
|
||||
<div id="dropdown-1"
|
||||
style="display: none; max-height: 200px; overflow-y: auto;">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input select-all-checkbox" type="checkbox"
|
||||
id="select-all-1" />
|
||||
<label class="form-check-label" for="select-all-1">Select All
|
||||
States</label>
|
||||
</div>
|
||||
@foreach ($state as $states)
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="states[]"
|
||||
value="{{ $states['id'] }}"
|
||||
id="state-{{ $states['id'] }}" />
|
||||
<div class="form-check">
|
||||
<input class="form-check-input state-checkbox" type="checkbox"
|
||||
name="states[]" value="{{ $states['id'] }}"
|
||||
id="state-1-{{ $states['id'] }}" />
|
||||
<label class="form-check-label"
|
||||
for="state-{{ $states['id'] }}">{{ $states['name'] }}</label>
|
||||
for="state-1-{{ $states['id'] }}">{{ $states['name'] }}</label>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
@@ -87,13 +93,41 @@
|
||||
users who are in their respective states</label><br>
|
||||
<div id="dropdown-2"
|
||||
style="display: none; max-height: 200px; overflow-y: auto;">
|
||||
@foreach ($state as $states)
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="states[]"
|
||||
value="{{ $states['id'] }}"
|
||||
id="state-{{ $states['id'] }}" />
|
||||
<div class="form-check">
|
||||
<input class="form-check-input select-all-checkbox" type="checkbox"
|
||||
id="select-all-2" />
|
||||
<label class="form-check-label" for="select-all-2">Select All
|
||||
States</label>
|
||||
</div>
|
||||
@foreach ($state as $states)
|
||||
<div class="form-check">
|
||||
<input class="form-check-input state-checkbox" type="checkbox"
|
||||
name="states[]" value="{{ $states['id'] }}"
|
||||
id="state-2-{{ $states['id'] }}" />
|
||||
<label class="form-check-label"
|
||||
for="state-{{ $states['id'] }}">{{ $states['name'] }}</label>
|
||||
for="state-2-{{ $states['id'] }}">{{ $states['name'] }}</label>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
<input class="form-check-input" type="radio" name="user_type"
|
||||
id="select-ids" value="3" />
|
||||
<label class="form-check-label" for="select-ids">Send to subscribed and
|
||||
unsubscribe users who are in their respective states</label><br>
|
||||
<div id="dropdown-3"
|
||||
style="display: none; max-height: 200px; overflow-y: auto;">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input select-all-checkbox"
|
||||
type="checkbox" id="select-all-3" />
|
||||
<label class="form-check-label" for="select-all-3">Select All
|
||||
States</label>
|
||||
</div>
|
||||
@foreach ($state as $states)
|
||||
<div class="form-check">
|
||||
<input class="form-check-input state-checkbox" type="checkbox"
|
||||
name="states[]" value="{{ $states['id'] }}"
|
||||
id="state-3-{{ $states['id'] }}" />
|
||||
<label class="form-check-label"
|
||||
for="state-3-{{ $states['id'] }}">{{ $states['name'] }}</label>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
@@ -216,9 +250,11 @@
|
||||
function handleUserTypeChange() {
|
||||
var dropdown1 = document.getElementById('dropdown-1');
|
||||
var dropdown2 = document.getElementById('dropdown-2');
|
||||
var dropdown3 = document.getElementById('dropdown-3');
|
||||
|
||||
dropdown1.style.display = this.value === '1' ? 'block' : 'none';
|
||||
dropdown2.style.display = this.value === '2' ? 'block' : 'none';
|
||||
dropdown3.style.display = this.value === '3' ? 'block' : 'none';
|
||||
}
|
||||
|
||||
var userTypeRadios = document.getElementsByName('user_type');
|
||||
@@ -230,6 +266,19 @@
|
||||
if (checkedRadio) {
|
||||
handleUserTypeChange.call(checkedRadio);
|
||||
}
|
||||
|
||||
function handleSelectAllChange() {
|
||||
var dropdown = this.closest('div[id^="dropdown-"]');
|
||||
var checkboxes = dropdown.querySelectorAll('.state-checkbox');
|
||||
for (var i = 0; i < checkboxes.length; i++) {
|
||||
checkboxes[i].checked = this.checked;
|
||||
}
|
||||
}
|
||||
|
||||
var selectAllCheckboxes = document.querySelectorAll('.select-all-checkbox');
|
||||
for (var i = 0; i < selectAllCheckboxes.length; i++) {
|
||||
selectAllCheckboxes[i].addEventListener('change', handleSelectAllChange);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@endsection
|
||||
|
||||
Reference in New Issue
Block a user