Skip to content

Commit

Permalink
NOISS switch from EA to scheddy
Browse files Browse the repository at this point in the history
  • Loading branch information
c0repwn3r committed Nov 16, 2024
1 parent 3b636e1 commit 5750830
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 224 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,6 @@ FLIGHTAWARE_START_DATE=
FLIGHTAWARE_END_DATE=
FLIGHTAWARE_MAX_FLIGHTS=100
FLIGHTAWARE_DRYRUN=true

SCHEDDY_BASE="https://scheddy.ztlartcc.org"
SCHEDDY_MASTER_API_KEY=
83 changes: 0 additions & 83 deletions app/Console/Commands/TrainingReminderEmails.php

This file was deleted.

2 changes: 0 additions & 2 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class Kernel extends ConsoleKernel {
'\App\Console\Commands\VATUSAEventsUpdate',
'\App\Console\Commands\UpdateAcademyExams',
'\App\Console\Commands\UploadTrainingTickets',
'\App\Console\Commands\TrainingReminderEmails'
];

/**
Expand All @@ -34,7 +33,6 @@ protected function schedule(Schedule $schedule): void {
$schedule->command('SoloCerts:UpdateSoloCerts')->dailyAt('05:01')->monitorName('VATUSA Solo Cert Sync');
$schedule->command('model:prune', ['--model' => MonitoredScheduledTaskLogItem::class])->dailyAt('05:17')->monitorName('Prune Task Monitor Database');
$schedule->command('Events:GenerateStatReports')->dailyAt('05:42')->monitorName('Event Stat Reports');
$schedule->command('Training:SendReminderEmails')->hourlyAt(3)->monitorName('Send Training Session Reminder Emails');
$schedule->command('RosterUpdate:UpdateRoster')->hourlyAt(7)->monitorName('Roster Update');
$schedule->command('Vatsim:AtcBookingSync')->hourlyAt(12)->monitorName('VATSIM ATC Booking Sync');
$schedule->command('VATUSAEvents:Update')->hourlyAt(22)->monitorName('VATUSA Events Sync');
Expand Down
70 changes: 25 additions & 45 deletions app/Http/Controllers/ControllerDash.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
use App\User;
use Auth;
use Carbon\Carbon;
use DB;
use GuzzleHttp\Client;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Mail;
use SimpleXMLElement;

class ControllerDash extends Controller {
protected static $SHOW_BOOKINGS_AFTER_APPT = 6; // Show bookings for X hours after appt start time

public function dash() {
$now = Carbon::now();
Expand Down Expand Up @@ -167,54 +167,34 @@ public function showProfile($year = null, $month = null) {
$last_training_given = null;
}

if (is_null(Auth::user()->ea_customer_id)) {
try {
$ea_users = DB::connection('ea_mysql')->table('ea_users')->select('id')->where(function ($query) {
$query->where('email', Auth::user()->email)
->orWhere('custom_field_1', Auth::user()->id);
})->where('id_roles', '3')->limit(1)->get();
foreach ($ea_users as $u) {
$user = Auth::user();
$user->ea_customer_id = $u->id;
$user->save();
}
} catch (\Illuminate\Database\QueryException $e) {
}
}
$ea_appointments = $ea_appointments_filtered = [];
if (!is_null(Auth::user()->ea_customer_id)) {
try {
$ea_appointments = DB::connection('ea_mysql')
->table('ea_appointments')
->join('ea_services', 'ea_appointments.id_services', '=', 'ea_services.id')
->join('ea_users', 'ea_appointments.id_users_provider', '=', 'ea_users.id')
->select(
'ea_appointments.start_datetime AS start_datetime',
'ea_appointments.hash AS link_token',
'ea_services.name AS service_description',
'ea_users.first_name AS staff_first_name',
'ea_users.last_name AS staff_last_name',
'ea_users.timezone AS booking_timezone'
)
->where('ea_appointments.id_users_customer', Auth::user()->ea_customer_id)
->where('ea_appointments.start_datetime', '>=', Carbon::now()->subHours(24)->format('Y-m-d H:i:s'))
->orderBy('ea_appointments.start_datetime', 'ASC')->get();
foreach ($ea_appointments as $ea_appointment) {
if (Carbon::parse($ea_appointment->start_datetime, $ea_appointment->booking_timezone) >= Carbon::now()->subHours(self::$SHOW_BOOKINGS_AFTER_APPT)) {
$appt_start_datetime = Carbon::parse($ea_appointment->start_datetime, $ea_appointment->booking_timezone)->setTimezone(Auth::user()->timezone);
$ea_appointment->res_date = $appt_start_datetime->format('m/d/Y');
$ea_appointment->res_time = $appt_start_datetime->format('H:i');
$ea_appointment->staff_name = $ea_appointment->staff_first_name . ' ' . $ea_appointment->staff_last_name;
$ea_appointments_filtered[] = $ea_appointment;
}
}
} catch (\Illuminate\Database\QueryException $e) {
$client = new Client();

$appointments = [];
$appointments_successful = false;

try {
//.$user_id
$res = $client->get(
Config::get('scheddy.base').'/api/userSessions/1710004',
['headers' => [
'Authorization' => 'Bearer '.Config::get('scheddy.api_key')
]]
);

if ($res->getStatusCode() == "200") {
Log::info($res->getBody());
$appointments = json_decode($res->getBody());
$appointments_successful = true;
}
} catch (\GuzzleHttp\Exception\ClientException $e) {
Log::error($e);
}

Log::info($appointments);

return view('dashboard.controllers.profile')->with('personal_stats', $personal_stats)->with('feedback', $feedback)
->with('training_feedback', $training_feedback)->with('tickets', $tickets)->with('last_training', $last_training)
->with('last_training_given', $last_training_given)->with('ea_appointments', $ea_appointments_filtered);
->with('last_training_given', $last_training_given)->with('appointments', $appointments)->with('appointments_successful', $appointments_successful);
}

public function showTicket($id) {
Expand Down
49 changes: 0 additions & 49 deletions app/Mail/TrainingReminder.php

This file was deleted.

15 changes: 0 additions & 15 deletions config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,6 @@
'port' => env('DB_PORT', '3306'),
],

'ea_mysql' => [
'driver' => 'mysql',
'host' => env('EA_DB_HOST', '127.0.0.1'),
'port' => env('EA_DB_PORT', '3306'),
'database' => env('EA_DATABASE', 'forge'),
'username' => env('EA_USERNAME', 'forge'),
'password' => env('EA_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],

'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', '127.0.0.1'),
Expand Down
8 changes: 8 additions & 0 deletions config/scheddy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

return [

'base' => env('SCHEDDY_BASE', 'https://scheddy.ztlartcc.org'),
'api_key' => env('SCHEDDY_MASTER_API_KEY'),

];
28 changes: 16 additions & 12 deletions resources/views/dashboard/controllers/profile.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,27 +129,31 @@
<table class="table table-bordered text-center">
<thead>
<tr>
<th scope="col">Date</th>
<th scope="col">Start Time</th>
<th scope="col">Date/time</th>
<th scope="col">Lesson Type</th>
<th scope="col">Instructor/Mentor</th>
<th scope="col">View/Modify</th>
</tr>
</thead>
<tbody>
@if(count($ea_appointments) > 0)
@foreach($ea_appointments as $ea_appointment)
@if($appointments_successful)
@if(count($appointments) > 0)
@foreach($appointments as $appointment)
<tr>
<td scope="col">{{ \Carbon\Carbon::parse($appointment->session->start)->setTimezone(Auth::User()->timezone) }} {{ Auth::User()->timezone_abbr }}</td>
<td scope="col">{{ $appointment->sessionType->name }}</td>
<td scope="col">{{ $appointment->mentor->firstName }} {{ $appointment->mentor->lastName }}</td>
<td scope="col"><i>Contact your mentor.</i></td>
</tr>
@endforeach
@else
<tr>
<td scope="col">{{ $ea_appointment->res_date }}</td>
<td scope="col">{{ $ea_appointment->res_time }} {{ Auth::user()->timezone_abbr }}</td>
<td scope="col">{{ $ea_appointment->service_description }}</td>
<td scope="col">{{ $ea_appointment->staff_name }}</td>
<td scope="col"><a href="https://scheduling.ztlartcc.org/index.php/booking/reschedule/{{ $ea_appointment->link_token }}?name_first={{ Auth::user()->fname }}&name_last={{ Auth::user()->lname }}&email={{ Auth::user()->email }}&cid={{ Auth::id() }}" target="_blank" class="btn btn-primary simple-tooltip" data-toggle="tooltip" title="View"><i class="fas fa-edit fa-fw"></i></a></td>
</tr>
@endforeach
<td scope="col" colspan="5">No appointments found.</td>
</tr>
@endif
@else
<tr>
<td scope="col" colspan="5">No appointments found.</td>
<td scope="col" colspan="5">Could not load appointment information :(</td>
</tr>
@endif
</tbody>
Expand Down
18 changes: 0 additions & 18 deletions tests/Feature/ConsoleTrainingReminderEmailsTest.php

This file was deleted.

0 comments on commit 5750830

Please sign in to comment.