diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index ee4dc230..57a8d2d6 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -42,7 +42,7 @@ protected function schedule(Schedule $schedule) $schedule->job(new ProcessSessionLogging())->everyMinute(); //Inactivity checks - $schedule->job(new ProcessRosterInactivity())->dailyAt('2:10'); + $schedule->job(new ProcessRosterInactivity())->dailyAt('7:00'); //CRONS FOR INACTIVITY EMAILS 2 weeks // $schedule->call(function () { diff --git a/app/Jobs/ProcessRosterInactivity.php b/app/Jobs/ProcessRosterInactivity.php index 12f1fa30..8dc587b4 100644 --- a/app/Jobs/ProcessRosterInactivity.php +++ b/app/Jobs/ProcessRosterInactivity.php @@ -39,6 +39,12 @@ public function __construct() */ public function handle() { + // Counter Variables (For Message at End) + $first_notice = 0; //305 Days without controlling + $second_notice = 0; //335 Days without controlling + $third_notice = 0; //358 Days without controlling + $termination_notice = 0; //365 Days without controlling (one year) + $roster_controllers = RosterMember::all(); // Lets now go through each RosterMember (gotta update dem all) @@ -47,43 +53,93 @@ public function handle() // get sessions within the last 12 months $sessions = SessionLog::where('cid', $roster->cid)->where('created_at', '>=', Carbon::now()->subMonths(12))->orderBy('created_at', 'asc')->get(); $last_session = SessionLog::where('cid', $roster->cid)->orderBy('created_at', 'desc')->first(); - // dd($last_session); // Set some variables (default values) $currency = 0; //Assume no connections $active_status = 1; //Assume roster member is active + $removeController = false; //Remove controller (false by default) // Go through each session to get some information foreach($sessions as $s){ $currency += $s->duration; } - // Currency is less than 1 hour and last connection was 305 days ago. - if($roster->active && $currency < 1 && $last_session->created_at->diffInDays(now()) >= 305){ - $active_status = 0; - // Send Message to user that they have been - if($roster->user->member_of_czqo && $roster->user->hasDiscord()){ - $discord = new DiscordClient(); - $discord->sendDM($roster->user->discord_user_id, 'Roster Status set as Inactive', 'Hello! - -Your status has been set as Inactive with Gander Oceanic. This is because you have not controlled at least one hour, within the last 305 days. -You have 60 days to control at least one hour, otherwise you will be removed as a certified controller. + // Check if there was a last session + if($last_session != null){ + + // Currency is less than 1 hour and last connection was 305 days ago. + if($roster->active && $currency < 1 && $last_session->created_at->diffInDays(now()) == 305){ + $active_status = 0; + + // Send Message to user that they have been set as inactive + if($roster->user->member_of_czqo && $roster->user->hasDiscord()){ + $discord = new DiscordClient(); + $discord->sendDM($roster->user->discord_user_id, 'Roster Status set as Inactive', 'Hello! + + Your status has been set as Inactive with Gander Oceanic. This is because you have not controlled at least one hour, within the last 305 days. + + You have 60 days to control at least one hour, otherwise you will be removed as a certified controller. + + If you have any questions, please reach out to the Gander Oceanic team on our Discord + + **Regards, + Gander Oceanic**'); + + } + + $first_notice++; + }; + + // User in inactive, has < 1hr of activity, and has not controlled for 335 days + if(!$roster->active && $currency < 1 && $last_session->created_at->diffInDays(now()) == 335){ + + $second_notice++; + } -If you have any questions, please reach out to the Gander Oceanic team on our Discord -**Regards, -Gander Oceanic**'); + // User is inactive, has <1hr of activity and has not controlled for 358 Days + if(!$roster->active && $currency < 1 && $last_session->created_at->diffInDays(now()) == 358){ + $third_notice++; } + + + // No Session was returned within the last 365 Days. + } else { + $removeController = true; } + // Save Roster Information $roster->active = $active_status; $roster->currency = $currency; $roster->save(); + + // Delete Controller if they should be removed. + if($removeController === true){ + // Send Message to user that they have been set as inactive + if($roster->user->member_of_czqo && $roster->user->hasDiscord()){ + $discord = new DiscordClient(); + $discord->sendDM($roster->user->discord_user_id, 'Gander Oceanic Certification Expired', 'Hello! + +Your Oceanic Certification has now been removed. This is because you have failed to control at least 1 hour, within the last 365 days. + +Should you wish to regain your certification, please apply to do so via the Gander Website. + +**Regards, +Gander Oceanic**'); + + $roster->user->removeRole('Certified Controller'); + $roster->user->assignRole('Guest'); + $roster->delete(); + $termination_notice++; + } } + + // Send Web Notification if any changes have been made + } -} +}} diff --git a/app/Jobs/ProcessSessionLogging.php b/app/Jobs/ProcessSessionLogging.php index 0c7fb603..65d782db 100644 --- a/app/Jobs/ProcessSessionLogging.php +++ b/app/Jobs/ProcessSessionLogging.php @@ -91,10 +91,10 @@ public function handle() } // Add Discord Role - if($log->user && $log->user->hasDiscord() && $log->user->member_of_czqo){ + if($session->user && $session->user->hasDiscord() && $session->user->member_of_czqo){ $discord = new DiscordClient(); - $discord->assignRole($log->user->discord_user_id, '1278868454606377040'); + $discord->assignRole($session->user->discord_user_id, '1278868454606377040'); } } } else { diff --git a/resources/views/admin/training/roster/index.blade.php b/resources/views/admin/training/roster/index.blade.php index bd5ec4d4..d4596e52 100644 --- a/resources/views/admin/training/roster/index.blade.php +++ b/resources/views/admin/training/roster/index.blade.php @@ -18,6 +18,7 @@ Name Status Active + Currency Action @@ -61,6 +62,16 @@ Inactive @endif + + @if($r->currency < 1) + + {{$r->currency}} + + @else + + {{$r->currency}} + + @endif  View