Skip to content

Commit

Permalink
Merge pull request #406 from czqoocavatsim/JoshuaBranch
Browse files Browse the repository at this point in the history
RosterInactivity Switched to Year Based
  • Loading branch information
JoshuaMicallefYBSU authored Oct 25, 2024
2 parents 2a1cd00 + 9f35470 commit 71ca54d
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 54 deletions.
2 changes: 1 addition & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function schedule(Schedule $schedule)
$schedule->job(new DiscordAccountCheck())->dailyAt('04:00');

//Roster Inactivity checks
$schedule->job(new ProcessRosterInactivity())->daily();
$schedule->job(new ProcessRosterInactivity())->dailyAt('23:55');

// Shanwick Controller Roster Update
$schedule->job(new ProcessShanwickControllers())->daily();
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/DiscordTestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Http\Request;
use App\Services\DiscordClient;
use Illuminate\Support\Facades\Http;
use App\Jobs\DiscordAccountCheck;
use App\Jobs\ProcessRosterInactivity;
use App\Jobs\ProcessShanwickController;

class DiscordTestController extends Controller
Expand All @@ -28,7 +28,7 @@ public function EditTagTest()
public function Job()
{
// Dispatch the job
$job = DiscordAccountCheck::dispatch();
$job = ProcessRosterInactivity::dispatch();

// Call the handle method directly to get the result synchronously
$result = $job->handle();
Expand Down
5 changes: 5 additions & 0 deletions app/Jobs/DiscordAccountCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ public function handle()
continue;
}

// Skip Server Owner (Gary)
if($discord_uid == 350995372627197954){
continue;
}

$accounts_not_linked++; //records that Account Not Linked Role Assigned

sleep(1);
Expand Down
103 changes: 53 additions & 50 deletions app/Jobs/ProcessRosterInactivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Notification;
use App\Notifications\Network\TwoMonthInactivityReminder;
use App\Notifications\Network\OneMonthInactivityReminder;
use App\Notifications\Network\OneWeekInactivityReminder;
use App\Notifications\Network\ControllerTerminated;
use App\Notifications\Roster\TwoMonthFromRemoval;
use App\Services\DiscordClient;

class ProcessRosterInactivity implements ShouldQueue
Expand Down Expand Up @@ -42,31 +39,35 @@ 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)
$first_notice = 0; //1NOV message sent out
$second_notice = 0; //1DEC message sent out
$third_notice = 0; //24DEC message
$termination_notice = 0; //31DEC Message Sent Out

$first_names = [];
$second_names = [];
$third_names = [];
$termination_names = [];

$roster_controllers = RosterMember::all();
// dd($roster_controllers);

// Lets now go through each RosterMember (gotta update dem all)
foreach($roster_controllers as $roster){

// 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)->where('created_at', '>=', Carbon::now()->subMonths(12))->orderBy('created_at', 'desc')->first();
// get sessions since start of year
$sessions = SessionLog::where('cid', $roster->cid)->where('created_at', '>=', Carbon::now()->startOfYear())->orderBy('created_at', 'asc')->get();

// Name of user being checked - Will link to the Users Roster Profile
$name = "[" . $roster->user->fullName('FLC') . "](" . route('training.admin.roster.viewcontroller', $roster->cid) . ")";

// user being checked.
$name = $roster->user->discord_user_id;

// Set some variables (default values)
$currency = 0; //Assume no connections
$active_status = 1; //Assume roster member is active
if($roster->active) { //Assume based off current set
$active_status = 1;
} else {
$active_status = 0;
}

// Go through each session to get some information
foreach($sessions as $s){
Expand All @@ -80,59 +81,61 @@ public function handle()
$currency += $s->duration;
}

// If Currency is greater than 1, set status active
if($currency > 0.99){
$active_status = 1;
}

// 1NOV - 2 Month Activity Check
if($roster->active && Carbon::now()->format('d/m') == "11/11" && $roster->currency < 1) {
$active_status = 0;

$first_names[] = $name;

// Check if there was a last session
if($last_session != null && $roster->certification === "certified"){
$first_notice++;

// 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;
Notification::send($roster->user, new TwoMonthFromRemoval($roster->user));
}

$first_names[] = "<@".$name.">";
// 1DEC - 1 Month till Removal
if(Carbon::now()->format('d/m') == "1/12" && $roster->currency < 1){
$second_names[] = $name;

$first_notice++;
};
$second_notice++;
}

// User in inactive, has < 1hr of activity, and has not controlled for 335 days
if($currency < 1 && $last_session->created_at->diffInDays(now()) == 335){
$second_names[] = "<@".$name.">";
// 24DEC - 7 Days Till Removal
if(Carbon::now()->format('d/m') == "24/12" && $roster->currency < 1){
$third_names[] = $name;

$second_notice++;
}
$third_notice++;
}

// End Of Year - Reset Time
if(Carbon::now()->format('d/m') == "31/12"){

// User is inactive, has <1hr of activity and has not controlled for 358 Days
if($currency < 1 && $last_session->created_at->diffInDays(now()) == 358){
$third_names[] = "<@".$name.">";
// User to be terminated
if($roster->currency < 1){
$termination_names[] = $name;

$third_notice++;
$termination_notice++;
}

// Save Roster Information based of above if statements
$roster->active = $active_status;
$roster->currency = $currency;
$roster->save();


// No Session was returned within the last 365 Days.
} else {
if($roster->certification === "certified"){
$termination_notice++;
$termination_names[] = "<@".$name.">";

$roster->user->removeRole('Certified Controller');
$roster->user->assignRole('Guest');
$roster->delete();
}
// Set Total Currency back to Zero (New Year Begins)
$currency = 0;
}
}

// Save Roster Information based of above if statements
$roster->active = $active_status;
$roster->currency = $currency;
$roster->save();
}

#Generate Discord Message
$message_contents = "The following changes have been made to the Controller Roster.";

if($first_notice != 0){
$message_contents .= "\n\n**60 Days Until Removed (Set as Inactive)**";
$message_contents .= "\n\n**60 Days To Complete Activity (Set as Inactive)**";

foreach($first_names as $n){
$message_contents .= "\n- ".$n;
Expand Down
64 changes: 64 additions & 0 deletions app/Notifications/Roster/TwoMonthFromRemoval.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace App\Notifications\Roster;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;

class TwoMonthFromRemoval extends Notification
{
use Queueable;
protected $user;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($user)
{
$this->user = $user;
}

/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
*
* @return array
*/
public function via($notifiable)
{
return ['mail'];
}

/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
*
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage())->view(
'emails.roster.twomonthstillremoval',
['user' => $this->user]
)->subject('Two Months to Fufill Activity Requirements');
}

/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
*
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}
23 changes: 23 additions & 0 deletions resources/views/emails/roster/twomonthstillremoval.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@extends('layouts.email')

@section('to-line', 'Dear '. $user->fullName('F') . ',')

@section('message-content')
<p>Our records indicate that you currently do not meet the currency requirements for your endorsement with Gander Oceanic</p>

<p>This is a friendly reminder that you must control a minimum of 1 hour per calendar year. You currently have {{$user->currency}} minutes recorded on Gander & Shanwick Positions.</p>

<p></p>

<p>If you believe this is a mistake or have any questions, please email the <a href="{{route('staff')}}">Chief Instructor</a> with your query.</p>
@endsection

@section('from-line')
Sent by Gander Oceanic OCA
@endsection

@section('footer-to-line', $user->fullName('FLC').' ('.$user->email.')')

@section('footer-reason-line')
of Currency Policy Requirements
@endsection
2 changes: 1 addition & 1 deletion resources/views/layouts/email.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
<div style="border-top:0px solid transparent; border-left:0px solid transparent; border-bottom:0px solid transparent; border-right:0px solid transparent; padding-top:5px; padding-bottom:5px; padding-right: 0px; padding-left: 0px;">
<!--<![endif]-->
<div align="left" class="img-container left fixedwidth" style="padding-right: 0px;padding-left: 0px;">
<!--[if mso]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr style="line-height:0px"><td style="padding-right: 0px;padding-left: 0px;" align="left"><![endif]--><img alt="Image" border="0" class="left fixedwidth" src="{{asset('assets/resources/media/img/brand/sqr/ZQO_SQ_TSPBLUE.png')}}" style="text-decoration: none; -ms-interpolation-mode: bicubic; border: 0; height: auto; width: 100%; max-width: 100px; display: block;" title="Image" width="100"/>
<!--[if mso]><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr style="line-height:0px"><td style="padding-right: 0px;padding-left: 0px;" align="left"><![endif]--><img alt="Image" border="0" class="left fixedwidth" src="{{asset('assets/resources/media/img/brand/sqr/ZQO_SQ_BLUE.png')}}" style="text-decoration: none; -ms-interpolation-mode: bicubic; border: 0; height: auto; width: 100%; max-width: 100px; display: block;" title="Image" width="100"/>
<!--[if mso]></td></tr></table><![endif]-->
</div>
<!--[if (!mso)&(!IE)]><!-->
Expand Down

0 comments on commit 71ca54d

Please sign in to comment.