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

Commit

Permalink
Add Airac for website
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcaussades committed Dec 2, 2023
1 parent badc81e commit 032fe8e
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 36 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ composer.lock
composer.lock
index.php
.htaccess
/database/database.sqlite
database/database.sqlite
database/airac.sqlite
134 changes: 134 additions & 0 deletions app/Http/Controllers/airac_info.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class airac_info extends Controller
{
public function connectToDatabase()
{
$connection = DB::connection('airac');

// Utilisez la connexion pour exécuter des requêtes sur la base de données

// Exemple : récupérer tous les enregistrements de la table "users"
return $connection;
}

public function get_approach($icao, $runway = NULL)
{
$connection = $this->connectToDatabase();

if ($runway == NULL) {
$approach = $connection->table('approach')->where('airport_ident', $icao)->where("suffix", "A")->pluck("fix_ident")->toArray();
} else if ($runway != NULL) {
$approach = $connection->table('approach')->where('airport_ident', $icao)->where("suffix", "A")->where("runway_name", $runway)->pluck("fix_ident")->toArray();
if(count($approach) == null){
$approach = $connection->table('approach')->where('airport_ident', $icao)->where("suffix", "A")->pluck("fix_ident")->toArray();
}
}

return $approach;
}

public function get_departure($icao, $runway = NULL)
{
$connection = $this->connectToDatabase();

if ($runway == NULL) {
$departure = $connection->table('approach')->where('airport_ident', $icao)->where("suffix", "D")->pluck("fix_ident")->toArray();




} else if ($runway != NULL) {
$departure = $connection->table('approach')->where('airport_ident', $icao)->where("suffix", "D")->where("runway_name", $runway)->pluck("fix_ident")->toArray();
if(count($departure) == null){
$departure = $connection->table('approach')->where('airport_ident', $icao)->where("suffix", "D")->pluck("fix_ident")->toArray();
}

}

return $departure;
}

public function get_ils_airport($icao)
{
$connection = $this->connectToDatabase();

$ils = $connection->table('ils')->where('loc_airport_ident', $icao)->get();
$LOC = [];
$RNAV = [];
if(count($ils) > 0){
foreach ($ils as $key => $value) {
if($value->name == NULL){
$LOC[] = $value;
}else if($value->type != NULL){
$RNAV[] = $value;
}
}
}
$LOC = collect($LOC)->sortBy('ils_id');
$RNAV = collect($RNAV)->sortBy('ils_id');
$Q = collect(["LOC" => $LOC, "RNAV" => $RNAV]);
return $Q;
}

Public function get_ils_information($icao, $runway = NULL)
{
$connection = $this->connectToDatabase();

if ($runway == NULL) {
$ils = $connection->table('ils')->where('loc_airport_ident', $icao)->get();
foreach ($ils as $key => $value) {
$frequency = $value->frequency;
$reformattedNumber = substr_replace($frequency, ".", 3, 0) . "Mhz";
$ils[$key]->frequency = $reformattedNumber;
}
$new_ils = [];
for ($i = 0; $i < count($ils); $i++) {
$new_ils[$i]["ident"] = $ils[$i]->ident;
$new_ils[$i]["type"] = $ils[$i]->type;
$new_ils[$i]["frequency"] = $ils[$i]->frequency;
$new_ils[$i]["loc_runway_name"] = $ils[$i]->loc_runway_name;
$new_ils[$i]["loc_heading"] = $ils[$i]->loc_heading;
$new_ils[$i]["loc_heading"] = explode(".", $new_ils[$i]["loc_heading"])[0];

}
$ils = collect($new_ils);

} else if ($runway != NULL) {
$ils = $connection->table('ils')->where('loc_airport_ident', $icao)->where("loc_runway_name", $runway)->whereNot("type", "T")->get();
$frequency = $ils->pluck("frequency")->toArray();
if(count($frequency) != null){
$reformattedNumber = substr_replace($frequency[0], ".", 3, 0) . "Mhz" ?? NULL;
$ils[0]->frequency = $reformattedNumber;
}

$new_ils = [];

$new_ils["ident"] = $ils[0]->ident;
$new_ils["type"] = $ils[0]->type;
$new_ils["frequency"] = $ils[0]->frequency;
$new_ils["loc_runway_name"] = $ils[0]->loc_runway_name;
$new_ils["loc_heading"] = $ils[0]->loc_heading;

$ils = collect($new_ils);
}

return $ils;
}

public function Get_info_all_airac($icao, $runway = NULL)
{

$approach = $this->get_approach($icao, $runway);
$departure = $this->get_departure($icao, $runway);
$ils = "";
$ils_info = $this->get_ils_information($icao, $runway);
$q = collect(["app" => $approach, "depa" => $departure, "ils" => $ils, "ils_info" => $ils_info]);
return $q;
}
}
9 changes: 8 additions & 1 deletion config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
'airac' => [
'driver' => 'sqlite',
'url' => env('DATABASE_URL'),
'database' => env('DB_DATABASE_AIRAC', database_path('airac.sqlite')),
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],

'mysql' => [
'driver' => 'mysql',
Expand Down Expand Up @@ -125,7 +132,7 @@

'options' => [
'cluster' => env('REDIS_CLUSTER', 'redis'),
'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_') . '_database_'),
],

'default' => [
Expand Down
41 changes: 7 additions & 34 deletions routes/web.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php



use App\Mail\MailTest;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -45,6 +43,7 @@
use App\Http\Controllers\CreatAuhUniqueUsersController;
use Symfony\Component\HttpKernel\Controller\ErrorController;
use App\Http\Controllers\my_fav_plateController;
use App\Http\Controllers\airac_info;

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -623,38 +622,12 @@
})->name("feedback.post");
})->middleware(["auth:web"]);

Route::get("test", function (Request $request) {
$w = new whazzupController();
$u = $w->get_rwys("LFBO");
$g = json_decode($u, true);
$unit_pi = "ft";
$unit_km = "km";
$rwy = [];
for ($i = 0; $i < count($g); $i++) {
$rwy[$i]["runway"] = $g[$i]["runway"];
$rwy[$i]["length_pi"] = $g[$i]["length"];
$rwy[$i]["length_KM"] = $g[$i]["length"] / 3281;
$rwy[$i]["length_KM"] = round($rwy[$i]["length_KM"], 2);
}
$data = [
"rwy" => $rwy,
"unit_pi" => $unit_pi,
"unit_km" => $unit_km
];
$data = json_encode($data);
return $data;
});

Route::prefix("devs")->group(function () {

Route::get("test2", function (Request $request) {
$w = new whazzupController();
$u = $w->event_ivao();
$g = json_decode($u);
return $g;
});

Route::get("test3", function (Request $request) {
$fav = new my_fav_plateController();
$fav = $fav->get();
return $fav;
Route::get("/ils", function (Request $request) {
$airac = new airac_info();
$airac = $airac->Get_info_all_airac("LFBO");
return $airac;
});
});

0 comments on commit 032fe8e

Please sign in to comment.