Skip to content

Commit

Permalink
Merge pull request #337 from czqoocavatsim/JoshuaBranch
Browse files Browse the repository at this point in the history
ProcessRosterInactivity Updates
  • Loading branch information
JoshuaMicallefYBSU authored Aug 30, 2024
2 parents 929146f + b62eb3c commit 01c300a
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
86 changes: 71 additions & 15 deletions app/Jobs/ProcessRosterInactivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand 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


}
}
}}
4 changes: 2 additions & 2 deletions app/Jobs/ProcessSessionLogging.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions resources/views/admin/training/roster/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<th>Name</th>
<th>Status</th>
<th>Active</th>
<th>Currency</th>
<th>Action</th>
</thead>
<tbody>
Expand Down Expand Up @@ -61,6 +62,16 @@
Inactive
</td>
@endif

@if($r->currency < 1)
<td class="bg-danger text-dark">
{{$r->currency}}
</td>
@else
<td class="bg-success text-white">
{{$r->currency}}
</td>
@endif
<td>
<a href="{{route('training.admin.roster.viewcontroller', $r->cid)}}"><i class="fas fa-eye"></i>&nbsp;View</a>
</td>
Expand Down

0 comments on commit 01c300a

Please sign in to comment.