Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

Commit

Permalink
Whazzup and Patch Airac (#32)
Browse files Browse the repository at this point in the history
* New recuperation whazzup

* mod minieur

* Patch Airac

* whazzup final
  • Loading branch information
alexcaussades authored Jul 19, 2023
1 parent e7fd35f commit b61178d
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 65 deletions.
46 changes: 32 additions & 14 deletions app/Http/Controllers/ChartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

class ChartController extends Controller
{
Public function config_Date(){
$date = "2023-06-15";
public function config_Date()
{
$date = date("m");
$date = $this->Airac_date($date);
return $date;
}
public function DateAirac()
Expand All @@ -20,31 +22,47 @@ public function DateAirac()
return $date;
}


public function chartIFR($icao){
$chart = "https://www.sia.aviation-civile.gouv.fr/dvd/eAIP_".$this->DateAirac()."/FRANCE/AIRAC-".$this->config_Date()."/html/eAIP/FR-AD-2.".$icao."-fr-FR.html";

public function chartIFR($icao)
{
$chart = "https://www.sia.aviation-civile.gouv.fr/dvd/eAIP_" . $this->DateAirac() . "/FRANCE/AIRAC-" . $this->config_Date() . "/html/eAIP/FR-AD-2." . $icao . "-fr-FR.html";
$header = get_headers($chart);
if($header[0] == "HTTP/1.1 404 Not Found"){
if ($header[0] == "HTTP/1.1 404 Not Found") {
$chart = "#";
}
if($header[0] == "HTTP/1.1 200 OK"){
$chart = "https://www.sia.aviation-civile.gouv.fr/dvd/eAIP_".$this->DateAirac()."/FRANCE/AIRAC-".$this->config_Date()."/html/eAIP/FR-AD-2.".$icao."-fr-FR.html";
if ($header[0] == "HTTP/1.1 200 OK") {
$chart = "https://www.sia.aviation-civile.gouv.fr/dvd/eAIP_" . $this->DateAirac() . "/FRANCE/AIRAC-" . $this->config_Date() . "/html/eAIP/FR-AD-2." . $icao . "-fr-FR.html";
}

return $chart;
}


Public function chartVFR($icao)

public function chartVFR($icao)
{
$chart = "https://www.sia.aviation-civile.gouv.fr/dvd/eAIP_".$this->DateAirac()."/Atlas-VAC/PDF_AIPparSSection/VAC/AD/AD-2.".$icao.".pdf";
$chart = "https://www.sia.aviation-civile.gouv.fr/dvd/eAIP_" . $this->DateAirac() . "/Atlas-VAC/PDF_AIPparSSection/VAC/AD/AD-2." . $icao . ".pdf";
$header = get_headers($chart);
if($header[0] == "HTTP/1.1 404 Not Found"){
if ($header[0] == "HTTP/1.1 404 Not Found") {
$chart = "#";
}
if($header[0] == "HTTP/1.1 200 OK"){
$chart = "https://www.sia.aviation-civile.gouv.fr/dvd/eAIP_".$this->DateAirac()."/Atlas-VAC/PDF_AIPparSSection/VAC/AD/AD-2.".$icao.".pdf";
if ($header[0] == "HTTP/1.1 200 OK") {
$chart = "https://www.sia.aviation-civile.gouv.fr/dvd/eAIP_" . $this->DateAirac() . "/Atlas-VAC/PDF_AIPparSSection/VAC/AD/AD-2." . $icao . ".pdf";
}
return $chart;
}

public function Airac_date($value)
{
$airac = $value;
$airac_table = [
"07" => "2023-07-13",
"08" => "2023-08-10",
"09" => "2023-09-07",
"10" => "2023-10-05",
"11" => "2023-11-02",
"12" => "2023-12-28",
];
$date = $airac_table[$airac];
return $date;
}
}
11 changes: 6 additions & 5 deletions app/Http/Controllers/PilotIvaoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
use Spatie\FlareClient\Api;

class PilotIvaoController extends Controller
{

public function whazzup()
{
$api = new whazzupController();
$api = $api->donwload_whazzup();
$api = $api->getwhazzup();
return $api;
}

public function getApideparturePilot($icao)
{
$api = $this->whazzup();
$count = $api->json()["connections"]["pilot"];
$pilot = $api->json()["clients"]["pilots"];
$count = $api["connections"]["pilot"];
$pilot = $api["clients"]["pilots"];
$pilotDeparture = [];
for ($i = 0; $i <= $count; $i++) {
foreach ($pilot as $key => $value) {
Expand All @@ -34,8 +35,8 @@ public function getApideparturePilot($icao)
public function getApiArrivalPilot($icao)
{
$api = $this->whazzup();
$count = $api->json()["connections"]["pilot"];
$pilot = $api->json()["clients"]["pilots"];
$count = $api["connections"]["pilot"];
$pilot = $api["clients"]["pilots"];
$PilotArrival = [];
for ($i = 0; $i <= $count; $i++) {
foreach ($pilot as $key => $value) {
Expand Down
11 changes: 6 additions & 5 deletions app/Http/Controllers/metarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ public function index()

public function whazzup(){
$api = new whazzupController();
$api = $api->donwload_whazzup();
$api = $api->getwhazzup();
return $api;
}

public function getApiATC_APP($icao)
{
$api = $this->whazzup();
foreach ($api->json()["clients"]["atcs"] as $key => $value) {
//dd($api["clients"]["atcs"]);
foreach ($api["clients"]["atcs"] as $key => $value) {
if ($value["callsign"] == $icao . "_APP") {
return $value;
}
Expand All @@ -37,7 +38,7 @@ public function getApiATC_TWR($icao)
{
$api = $this->whazzup();

foreach ($api->json()["clients"]["atcs"] as $key => $value) {
foreach ($api["clients"]["atcs"] as $key => $value) {

if ($value["callsign"] == $icao . "_TWR") {
return $value;
Expand All @@ -48,7 +49,7 @@ public function getApiATC_TWR($icao)
public function getApiATC_GND($icao)
{
$api = $this->whazzup();
foreach ($api->json()["clients"]["atcs"] as $key => $value) {
foreach ($api["clients"]["atcs"] as $key => $value) {

if ($value["callsign"] == $icao . "_GND") {
return $value;
Expand All @@ -59,7 +60,7 @@ public function getApiATC_GND($icao)
public function getApiATC_FSS($icao)
{
$api = $this->whazzup();
foreach ($api->json()["clients"]["atcs"] as $key => $value) {
foreach ($api["clients"]["atcs"] as $key => $value) {

if ($value["callsign"] == $icao . "_FSS") {
return $value;
Expand Down
81 changes: 52 additions & 29 deletions app/Http/Controllers/whazzupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,69 @@
namespace App\Http\Controllers;

use App\Models\whazzupdd;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage;
use PHPUnit\TestRunner\TestResult\Collector;

class whazzupController extends Controller
{
public function getwhazzup()
{
$api = Http::get('https://api.ivao.aero/v2/tracker/whazzup');
return $api;

$api = $this->store_Whazzup();
$whazzup = json_decode($api[0], true);
return $whazzup;
}

public function donwload_whazzup(){
public function donwload_whazzup()
{
$whazzup = Http::get('https://api.ivao.aero/v2/tracker/whazzup');
return $whazzup;
}

public function store_Whazzup(){
if($this->getwhazzupbdd() == null){
$whazzup = $this->donwload_whazzup();
$whazzup_date = $whazzup["updatedAt"];
$whazzup = json_encode($whazzup);
$whazzup_date = $this->add_date($whazzup_date);
$whazzupbdd = new whazzupdd();
$whazzupbdd->whazzup = $whazzup;
$whazzupbdd->whazzup_date = $whazzup_date;
$whazzupbdd->save();
return $whazzupbdd;
}

$datenow = date('Y-m-d H:i:s');
$date = $this->getwhazzupbdd()->whazzup_date;
public function store_file_whazzup()
{
$wha = $this->donwload_whazzup();
$date = json_decode($wha);
$name = Str::random(15);
$sto = Storage::put('public/whazzup/' . $name . '.json', $wha);
$sto = Storage::url('public/whazzup/' . $name . '.json', $wha);
//$review = Storage::get('public/whazzup/'.$name.'.json');
$r = [
"name" => $name,
"date" => $date->updatedAt,
"url" => $sto
];
//$a = json_decode($r["review"]);
return $r;
}

public function store_Whazzup()
{
$datenow = date('Y-m-d H:i:s');
$date = $this->getwhazzupbdd()->whazzup_date;
// si la date de la bdd est superieur a la date actuelle
if($date > $datenow){
if ($date > $datenow) {
$whazzupbdd = $this->getwhazzupbdd();
$whazzup = $whazzupbdd->whazzup;
$whazzup = json_decode($whazzup);
$review = Storage::get('public/whazzup/' . $whazzupbdd['whazzup'] . '.json');
$whazzup = collect($review);
return $whazzup;
}else{
$whazzup = $this->donwload_whazzup();
$whazzup_date = $whazzup["updatedAt"];
$whazzup = $whazzup;
} else {
$whazzup = $this->store_file_whazzup();
$whazzup_date = $whazzup["date"];
$whazzup_date = $this->add_date($whazzup_date);
$whazzupbdd = new whazzupdd();
$whazzupbdd->whazzup = $whazzup;
$whazzupbdd->whazzup = $whazzup["name"];
$whazzupbdd->whazzup_date = $whazzup_date;
$whazzupbdd->save();
return $whazzupbdd;
return $this->store_Whazzup();
}
}

public function add_date($value){
public function add_date($value)
{
$dateIn = $value;
$datenew = date('Y-m-d H:i:s', strtotime($dateIn));
// ajout de 5 minutes a la nouvelle date
Expand All @@ -72,4 +82,17 @@ public function getwhazzupbdd()
$whazzupbdd = $whazzupbdd->last();
return $whazzupbdd;
}

public function connexion()
{
$api = $this->getwhazzup();
return $api["connections"];
}

public function bddid()
{
$whazzupbdd = whazzupdd::all();
$whazzupbdd = $whazzupbdd->last();
return $whazzupbdd;
}
}
2 changes: 1 addition & 1 deletion resources/views/navbar-metar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href={{ Route("auth.login") }}>Home</a>
<a class="nav-link active" aria-current="page" href={{ Route("home") }}>Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ Route("metars.index") }}">Metar</a>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/navbar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href={{ Route("auth.login") }}>Home</a>
<a class="nav-link active" aria-current="page" href={{ Route("home") }}>Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ Route("metars.index") }}">Metar</a>
Expand Down
36 changes: 31 additions & 5 deletions resources/views/welcome.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@


<div class="col-12">

<div class="card border-dark">
<div class="card-header bg-dark border-dark text-white text-opacity-90">
<h1 class="container title d-flex align-items-center">IVAO - Tracker <span class="material-symbols-outlined fs-1">connecting_airports</span></h1>
</div>
</div>
</div>
</div>

<div class="container">
@auth
<h4 class="mt-3"> Welcome {{ auth()->user()->name }} ({{auth()->user()->vid}}) </h4>
Expand All @@ -29,8 +28,8 @@
<div class="card text-white bg-dark">
<div class="card-body bg-dark border-dark text-white text-opacity-75">
<h4 class="card-title text-center">Metar</h4>
<p class="card-text d-flex align-items-center"><span class="material-symbols-outlined">arrow_forward_ios</span> Search the metar at the plateform </p>
<p class="card-footer text-center"><a href="{{ Route("metars.index")}}" class="btn btn-success">Search Metar</a></p>
<p class="card-text d-flex align-items-center"><span class="material-symbols-outlined">arrow_forward_ios</span> Search the metar at the plateform </p>
<p class="card-footer text-center"><a href="{{ Route("metars.index")}}" class="btn btn-success">Search Metar</a></p>
</div>
</div>
</div>
Expand All @@ -44,5 +43,32 @@
</div>
</div>
</div>

<hr>
<div class="row">
<div class="text-end d-flex align-items-center"><span class="material-symbols-outlined">database </span>{{$idlast["id"]}}</div>
<div class="col-4 mt-2">
<div class="card text-white bg-dark">
<div class="card-body">
<h4 class="card-title text-center">Total</h4>
<p class="card-text text-center">{{ $whazzup["total"] }}</p>
</div>
</div>
</div>
<div class="col-4 mt-2">
<div class="card text-white bg-dark">
<div class="card-body">
<h4 class="card-title text-center">ATC</h4>
<p class="card-text text-center">{{ $whazzup["atc"] }}</p>
</div>
</div>
</div>
<div class="col-4 mt-2">
<div class="card text-white bg-dark">
<div class="card-body">
<h4 class="card-title text-center">Pilot</h4>
<p class="card-text text-center">{{ $whazzup["pilot"] }}</p>
</div>
</div>
</div>
</div>
@endsection
18 changes: 13 additions & 5 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@

Route::get('/welcome', function (usersController $usersController, Request $request, Session $session) {
$users = $usersController->get_info_user(session()->get("id"));
return view('welcome', ["users" => $users]);
$whazzup = new whazzupController();
$whazzup = $whazzup->connexion();
dd($whazzup);
return view('welcome', ["users" => $users, "whazzup" => $whazzup]);
})->name("welcome");

Route::get('/login', function (Request $request) {
Expand All @@ -56,10 +59,15 @@
return to_route("auth.logout");
})->name("logout");

Route::get('/', function (Request $request) {
Route::get('/', function (Request $request , usersController $usersController) {
/** creation d'un cookie sur laravel */
return response()->view('welcome');
})->where('client', '[0-9]+');
$users = $usersController->autentification_via_cookie();
$whazzup = new whazzupController();
$whazzup = $whazzup->connexion();
$bddid = new whazzupController();
$idlast = $bddid->bddid();
return response()->view('welcome', ["whazzup" => $whazzup, "idlast" => $idlast]);
})->where('client', '[0-9]+')->name("home");


Route::prefix("auth/")->group(function () {
Expand Down Expand Up @@ -414,6 +422,6 @@

Route::get("test", function (Request $request) {
$whazzup = new whazzupController();
$whazzup = $whazzup->donwload_whazzup();
$whazzup = $whazzup->connexion();
return $whazzup;
})->name("test");

0 comments on commit b61178d

Please sign in to comment.