Files
cheerstothe_season_2.0/app/Console/Commands/SentScheduleNotification.php
2024-07-09 15:54:23 +05:30

77 lines
2.2 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Models\IamPrincipal;
use App\Models\NotificationDetails;
use Illuminate\Console\Command;
use Carbon\Carbon;
use Exception;
use DateTime;
use App\Helpers\onesignalhelper;
use Illuminate\Support\Facades\Log;
class SentScheduleNotification extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:sent-schedule-notification';
/**
* The console command description.
*
* @var string
*/
protected $description = 'It will send Recommendation to users Based on stored Data';
/**
* Execute the console command.
*/
public function handle()
{
$getAllPushNotifications = NotificationDetails::where('is_schedule', 1)
->where('is_active', 0)
->orderByDesc('id')
->get();
$currentDateTime = new DateTime();
foreach ($getAllPushNotifications as $inAppNotificationItem) {
$storedDateTime = new DateTime($inAppNotificationItem->delivery_schedule);
$currentTime = $currentDateTime->format('Y-m-d H:i');
$storedTime = $storedDateTime->format('Y-m-d H:i');
if ($currentTime == $storedTime) {
$title = $inAppNotificationItem->type;
$description = $inAppNotificationItem->description;
$imagePath = $inAppNotificationItem->image;
$principalData = IamPrincipal::find($inAppNotificationItem->principal_xid);
if ($principalData && $principalData->one_signal_player_id) {
OneSignalHelper::sendNotificationApi(
$principalData->one_signal_player_id,
$title,
$description,
'Dashboard Notification',
$imagePath,
$id = null
);
Log::info("INAPP scheduled notification sent successfully");
$inAppNotificationItem->is_active = 1;
$inAppNotificationItem->save();
}
}
}
}
}