citadel lookup

This commit is contained in:
2019-10-21 00:55:58 -05:00
parent d9dec56700
commit c18ebcba22
7 changed files with 158 additions and 5 deletions

View File

@@ -39,17 +39,32 @@ class DashboardController extends Controller
foreach($tempContracts as $con) {
if($con->status == 'outstanding') {
//Find the start station or citadel
if($con->start_location_id) {
$startStation = $lookupHelper->GetCitadelDetails($con->start_location_id);
} else if($con->start_location_id) {
$startStation = $lookupHelper->GetStationDetails($con->start_location_id);
} else {
$startSystem = 'N/A';
}
//Find start and end station. Need to work on how to tell citadels later.
$startStation = $lookupHelper->GetStationDetails($con->start_location_id);
$endStation = $lookupHelper->GetStationDetails($con->end_location_id);
//Find the end station or citadel
if($con->end_location_id) {
$endStation = $lookupHelper->GetCitadelDetails($con->end_location_id);
} else if($con->end_location_id) {
$endStation = $lookupHelper->GetStationDetails($con->end_location_id);
} else {
$endSystem = 'N/A';
}
//Find the system via it's id.
if(isset($startStation->system_id)) {
$startSystem = $lookupHelper->GetSolarSystemName($startStation->system_id);
} else {
$startSystem = 'N/A';
}
//Find the system via it's id.
if(isset($endStation->system_id)) {
$endSystem = $lookupHelper->GetSolarSystemName($endStation->system_id);
} else {

View File

@@ -748,7 +748,7 @@ class LookupHelper {
} else if( $name != null) {
$count = StationLookup::where(['name' => $name])->count();
if($coutn > 0) {
if($count > 0) {
$station = StationLookup::where(['name' => $name])->first();
} else {
return null;
@@ -781,6 +781,73 @@ class LookupHelper {
$station->type_id = $response->type_id;
$station->save();
}
public function GetCitadelDetails($citadelId) {
//Check if the citadel is stored in the database
$citadel = $this->LookupCitadel($citadelId, null);
//If the citadel id is null, then we didn't find it, and we run esi
//to find the details if possible
if($citadel != null) {
return $citadel;
} else {
try {
$citadel = $this->esi->invoke('get', '/universe/structures/{structure_id}/', [
'structure_id' => $citadelId,
]);
} catch(RequestFailedException $e) {
Log::warning("Failed to get citadel details from /universe/structures/{structure_id}/");
return null;
}
//Save the citadel in the database
$this->SaveCitadel($citadel, $citadelId);
return $citadel;
}
}
public function LookupCitadel($id = null, $name = null) {
//If both the id and name are null, then there is nothing to look up
if($id == null && $name == null) {
return null;
}
//Run through the checks to try to find the station either by id first,
//then from the citadel name
if($id != null) {
$count = CitadelLookup::where(['structure_id' => $id])->count();
if($count > 0) {
$citadel = CitadelLookup::where(['structure_id' => $id])->first();
} else {
return null;
}
} else if($name != null) {
$count = CitadelLookup::where(['name' => $name])->count();
if($count > 0) {
$citadel = CitadelLookup::where(['name' => $name])->first();
} else {
return null;
}
}
//Return the details of the station if they were found
return $citadel;
}
private function SaveCitadel($response, $id) {
$citadel = new CitadelLookup;
$citadel->structure_id = $id;
$citadel->name = $response->name;
$citadel->position_x = $response->position->x;
$citadel->position_y = $response->position->y;
$citadel->position_z = $response->position->z;
$citadel->solar_system_id = $response->solar_system_id;
$citadel->type_id = $response->type_id;
$citadel->save();
}
}
?>

View File

@@ -0,0 +1,29 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class CitadelLookup extends Model
{
//Table Name
public $table = 'citadel_lookup';
//Timestamps
public $timestamps = true;
/**
* The attributes that are mass assignable
*
* @var array
*/
protected $fillable = [
'structure_id',
'name',
'position_x',
'position_y',
'position_z',
'solar_system_id',
'type_id',
];
}

View File

@@ -0,0 +1,40 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCitadelLookupTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if(!Schema::hasTable('citadel_lookup')) {
Schema::create('citadel_lookup', function(Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('structure_id');
$table->string('name');
$table->bigInteger('position_x');
$table->bigInteger('position_y');
$table->bigInteger('position_z');
$table->unsignedBigInteger('solar_system_id');
$table->unsignedBigInteger('type_id');
$table->timestamps();
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('citadel_lookup');
}
}

View File

@@ -279,7 +279,7 @@ class ClassLoader
*/
public function setApcuPrefix($apcuPrefix)
{
$this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
$this->apcuPrefix = function_exists('apcu_fetch') && ini_get('apc.enabled') ? $apcuPrefix : null;
}
/**

View File

@@ -6,6 +6,7 @@ $vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'App\\CitadelLookup' => $baseDir . '/app/Models/Lookups/CitadelLookup.php',
'App\\Console\\Kernel' => $baseDir . '/app/Console/Kernel.php',
'App\\Exceptions\\Handler' => $baseDir . '/app/Exceptions/Handler.php',
'App\\Http\\Controllers\\Auth\\EsiScopeController' => $baseDir . '/app/Http/Controllers/Auth/EsiScopeController.php',

View File

@@ -486,6 +486,7 @@ class ComposerStaticInit33afb8ba5b252c3933eb137784fa7f04
);
public static $classMap = array (
'App\\CitadelLookup' => __DIR__ . '/../..' . '/app/Models/Lookups/CitadelLookup.php',
'App\\Console\\Kernel' => __DIR__ . '/../..' . '/app/Console/Kernel.php',
'App\\Exceptions\\Handler' => __DIR__ . '/../..' . '/app/Exceptions/Handler.php',
'App\\Http\\Controllers\\Auth\\EsiScopeController' => __DIR__ . '/../..' . '/app/Http/Controllers/Auth/EsiScopeController.php',