- New map option for inline system region names, closed #947
- Upgraded "[_jsPlumb_](http://jsplumb.github.io/jsplumb/home.html)" js lib `v2.9.3` → `v2.13.1` - Moved endpoint `/api/universe/systems` into new REST structure 'GET /api/rest/SystemSearch'
This commit is contained in:
@@ -14,7 +14,6 @@ use Exodus4D\Pathfinder\Data\File\FileHandler;
|
||||
use Exodus4D\Pathfinder\Model\AbstractModel;
|
||||
use Exodus4D\Pathfinder\Model\Pathfinder;
|
||||
use Exodus4D\Pathfinder\Model\Universe;
|
||||
use Exodus4D\Pathfinder\Exception;
|
||||
|
||||
/**
|
||||
* Map controller
|
||||
|
||||
82
app/Controller/Api/Rest/SystemSearch.php
Normal file
82
app/Controller/Api/Rest/SystemSearch.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Exodus4D\Pathfinder\Controller\Api\Rest;
|
||||
|
||||
use Exodus4D\Pathfinder\Model;
|
||||
|
||||
class SystemSearch extends AbstractRestController {
|
||||
|
||||
/**
|
||||
* system data properties that will be returned
|
||||
* -> filter system data, save bandwidth
|
||||
*/
|
||||
const SYSTEM_DATA_KEYS = ['id', 'name', 'trueSec', 'security', 'effect', 'shattered'];
|
||||
|
||||
/**
|
||||
* max results per page
|
||||
*/
|
||||
const PAGE_SIZE_SYSTEMS = 50;
|
||||
|
||||
/**
|
||||
* @param \Base $f3
|
||||
* @param $params
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function get(\Base $f3, $params){
|
||||
$requestData = $this->getRequestData($f3);
|
||||
$morePages = false;
|
||||
$count = 0;
|
||||
|
||||
$result = (object) [];
|
||||
$result->results = [];
|
||||
|
||||
// some "edge cases" for testing trueSec rounding...
|
||||
//$searchToken = 'H472-N'; // -0.000001 -> 0.0
|
||||
//$searchToken = 'X1E-OQ'; // -0.099426 -> -0.10
|
||||
//$searchToken = 'BKK4-H'; // -0.049954 -> -0.05
|
||||
//$searchToken = 'Uhtafal'; // 0.499612 -> 0.5 (HS)
|
||||
//$searchToken = 'Oshaima'; // 0.453128 -> 0.5 (HS)
|
||||
//$searchToken = 'Ayeroilen'; // 0.446568 -> 0.4 (LS)
|
||||
//$searchToken = 'Enderailen'; // 0.448785 -> 0.4 (LS)
|
||||
//$searchToken = 'Neziel'; // 0.449943 -> 0.4 (LS)
|
||||
//$searchToken = 'Naga'; // 0.033684 -> 0.1 (LS)
|
||||
|
||||
if(strlen($search = (string)$params['id']) >= 3){
|
||||
$page = max((int)$requestData['page'],1);
|
||||
$offset = ($page - 1) * self::PAGE_SIZE_SYSTEMS;
|
||||
$system = Model\Universe\AbstractUniverseModel::getNew('SystemModel');
|
||||
|
||||
$filter = [
|
||||
'id LIKE :id OR name LIKE :name',
|
||||
':id' => $search . '%', // -> match first
|
||||
':name' => '%' . $search . '%' // -> match between
|
||||
];
|
||||
$options = [
|
||||
'order' => 'name',
|
||||
'offset' => $offset,
|
||||
'limit' => self::PAGE_SIZE_SYSTEMS
|
||||
];
|
||||
$count = $system->count($filter);
|
||||
$endCount = $offset + self::PAGE_SIZE_SYSTEMS;
|
||||
$morePages = $endCount < $count;
|
||||
|
||||
/**
|
||||
* @var Model\Universe\SystemModel[] $systems
|
||||
*/
|
||||
$systems = $system->find($filter, $options);
|
||||
if($systems){
|
||||
$allowedKeys = array_flip(self::SYSTEM_DATA_KEYS);
|
||||
foreach($systems as $system){
|
||||
if($systemData = $system->fromIndex()){
|
||||
$result->results[] = (object)array_intersect_key((array)$systemData, $allowedKeys);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result->pagination = ['more' => $morePages, 'count' => $count];
|
||||
|
||||
$this->out($result);
|
||||
}
|
||||
}
|
||||
@@ -37,71 +37,6 @@ class Universe extends Controller\AccessController {
|
||||
echo json_encode($universeNameData);
|
||||
}
|
||||
|
||||
/**
|
||||
* search systems by name
|
||||
* @param \Base $f3
|
||||
* @param $params
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function systems(\Base $f3, $params){
|
||||
$getData = (array)$f3->get('GET');
|
||||
$page = isset($getData['page']) ? (int)max($getData['page'],1) : 1;
|
||||
$search = isset($params['arg1']) ? (string)$params['arg1'] : '';
|
||||
$morePages = false;
|
||||
$count = 0;
|
||||
// reduce returned system data to required keys (save bandwidth)
|
||||
$allowedProperties = array_flip(['id', 'name', 'trueSec', 'security', 'effect', 'shattered']);
|
||||
|
||||
$return = (object) [];
|
||||
$return->results = [];
|
||||
|
||||
// some "edge cases" for testing trueSec rounding...
|
||||
//$searchToken = 'H472-N'; // -0.000001 -> 0.0
|
||||
//$searchToken = 'X1E-OQ'; // -0.099426 -> -0.10
|
||||
//$searchToken = 'BKK4-H'; // -0.049954 -> -0.05
|
||||
//$searchToken = 'Uhtafal'; // 0.499612 -> 0.5 (HS)
|
||||
//$searchToken = 'Oshaima'; // 0.453128 -> 0.5 (HS)
|
||||
//$searchToken = 'Ayeroilen'; // 0.446568 -> 0.4 (LS)
|
||||
//$searchToken = 'Enderailen'; // 0.448785 -> 0.4 (LS)
|
||||
//$searchToken = 'Neziel'; // 0.449943 -> 0.4 (LS)
|
||||
//$searchToken = 'Naga'; // 0.033684 -> 0.1 (LS)
|
||||
|
||||
if( strlen($search) >= 3 ){
|
||||
$offset = ($page - 1) * self::PAGE_SIZE_SYSTEMS;
|
||||
$system = Model\Universe\AbstractUniverseModel::getNew('SystemModel');
|
||||
|
||||
$filter = [
|
||||
'id LIKE :id OR name LIKE :name',
|
||||
':id' => $search . '%', // -> match first
|
||||
':name' => '%' . $search . '%' // -> match between
|
||||
];
|
||||
$options = [
|
||||
'order' => 'name',
|
||||
'offset' => $offset,
|
||||
'limit' => self::PAGE_SIZE_SYSTEMS
|
||||
];
|
||||
$count = $system->count($filter);
|
||||
$endCount = $offset + self::PAGE_SIZE_SYSTEMS;
|
||||
$morePages = $endCount < $count;
|
||||
|
||||
/**
|
||||
* @var Model\Universe\SystemModel[] $systems
|
||||
*/
|
||||
$systems = $system->find($filter, $options);
|
||||
if($systems){
|
||||
foreach($systems as $system){
|
||||
if($systemData = $system->fromIndex()){
|
||||
$return->results[] = (object)array_intersect_key((array)$systemData, $allowedProperties);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$return->pagination = ['more' => $morePages, 'count' => $count];
|
||||
|
||||
echo json_encode($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* get system data for all systems within a constellation
|
||||
* @param \Base $f3
|
||||
|
||||
Reference in New Issue
Block a user