diff --git a/.gitignore b/.gitignore index df1576b..2f2f4cc 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,5 @@ composer.lock composer.lock index.php .htaccess -/database/database.sqlite +database/database.sqlite +database/airac.sqlite diff --git a/app/Http/Controllers/airac_info.php b/app/Http/Controllers/airac_info.php new file mode 100644 index 0000000..4613fad --- /dev/null +++ b/app/Http/Controllers/airac_info.php @@ -0,0 +1,134 @@ +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; + } +} diff --git a/config/database.php b/config/database.php index 137ad18..ce79e42 100644 --- a/config/database.php +++ b/config/database.php @@ -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', @@ -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' => [ diff --git a/routes/web.php b/routes/web.php index 797bc72..cd393ac 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,7 +1,5 @@ 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; + }); });