Files
pathfinder/app/main/controller/api/system.php
Mark Friedrich ecd505a202 v1.0.0 (#183)
* #84 test data dump from CREST login

* updated "credits" dialog (Google+ link)
fixed login form layout

* updated Cortex Data-Mapper

* - #84 CREST Login (WIP)
- New CREST controller
- Database restructuring
- improved type-casting for some controller functions
- New login process
- Fixed some bugs during the setup process (/setup root)
- Added CREST request caching by response headers

* pathfinder-84 [Feature Request] CREST Pilot Tracking, many smaller Bugfixes

* pathfinder-84 [Feature Request] added develop JS files

* closed #121 fixed wormhole signature type caching

* closed #120 removed map-loading animation for larger maps (same behaviour as IGB)

* closed #119 fixed wormhole signature id count

* closed #114 Added check for already existing system when adding a new one. (fixed PDO 'duplicate entry' error)

* closed #112 fixed DataTables error for missing "status" data (signature table)

* closed #111 fixed convertDataToUTC(); client side date transformation

* closed #109 fixed system TrueSec rounding

* closed #103 fixed system updated timestamp in getData()

* fixed CSS class for secStatus in Routes module

* closed #121 fixed wormhole signature type caching

* changed dateTime format from German to US format
fixed some minor bugs in signatureTable module

* closed #81 fixed "signature type" overwriting by "signature reader" update

* closed #106 added new signature_types form C5/6 wormholes (gas/ore)

* closed #129 fixed parameter hinting

* closed #131 new "route search" algorithm, added current map systems to live search, added refresh/update functionality for each found route, added bulk route refresh function, added "meta map" route search (search on multiple maps), added route "filters" (restrict search on "stargates", "wormholes", "jumpbridges"), added route "filter" for wormholes (reduced/critical wormholes)
closed #89 fixed "loop connections" on same system
#84 added error messages for "invalid" CREST "Client ID"
added "bootboxjs" (customized styled checkboxes/radio buttons) CSS only
"Font Awesome" version upgrade 4.4.0 -> 4.61
"Bootbox.js" version upgrade 4.3.0 -> 4.4.0
fixed "system dialog" (added responsive layout)

* closed #134  fixed db column type DT_INT (8 bytes) to DT_BIGINT

* closed #138 added new cookie based login

* closed #137 fixed javascript errors on trying to establish an "invalid" connection

* - #84, #138 improved "character selection" on login page (expired cookies are deleted, character panel layout improvements)
- added new "Server info panel" to the login page
- added new cronjob to delete expired cookie authentication data

* #138 enables character switching between characters which have same user

* - PHP Framework upgrade 3.5.0 -> 3.5.1 (fixes some issues with CREST cURL caching, and SESSION management)
- #138 added "cookie logout" to "logout" menu entry

* - updated "feature page" with new feature descriptions and label
- added some new images to the "feature gallery"
- removed "beta" status from "magnetizing" feature on map menu
- hide "server status" panel on "mobile" breakpoint

* - #138 clear character authentication data on sold characters

* closed #142 added custom "onsuspect()" session handler

* #142 do not log suspect if no file is defined in pathfinder.ini

* #142 added NullSec Data/Relic sites to C1/2/3 wormholes as signature option

* #144 fixed "Character not found" warning

* #144 fixed "Character not found" warning

* closed #144 fixed broken routes panel in IGB

* updated README.md for upcoming release

* #147 response header validation

* #149 changed comment for 'BASE' framework var

* fixed map  import

* - added minimal SDE dump (EVE Online: Citadel)
- #147 improved CREST API error logging (WIP)
- improved SSO controller (removed access_token from public endpoints)

* closed #154 added alliance maps to CREST API

* - updated Gulp build dependencies
- increased CREST timeout from 3s -> 4s
- added "Accept" Headers for some CREST endpoints

* cloased #147

* - closed #153 added character verification check for getAll(); Signatures Ajax endpoint

* - updated README.md (added Slack developer chat information)

* Bugfix frig holes (#159)

* added missing frigate wormholes and fixed Q003 destination in shattered wormholes

* changed C7 to 0.0 for Q003

* - fixed broken "graph" data for system

* added a  "failover" system  for bad crest requests (HTTP status 5xx,.. )

* Red Gaint => Red Giant (#161)

* closed #163 added CREST endpoint support for "waypoints"

* fixed typo

* closed #160 fixed tooltip container

* - added new features to login page

* closes #154 added alliance map support

* fixed XML path for cronjobs

* fixed a bug with inactive "private" maps

* closes #175 added alternative environment configuration

* - v1.0.0  build
2016-06-03 23:05:34 +02:00

431 lines
13 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: exodus4d
* Date: 08.02.15
* Time: 20:23
*/
namespace Controller\Api;
use Controller\Ccp\Sso;
use Data\Mapper as Mapper;
use Model;
class System extends \Controller\AccessController {
private $mainQuery = "SELECT
map_sys.constellationID `connstallation_id`,
map_sys.solarSystemID `system_id`,
map_sys.solarSystemName `system_name`,
map_sys.security `system_security`,
map_con.constellationName `constallation_name`,
map_reg.regionID `region_id`,
map_reg.regionName `region_name`,
'0' `trueSec`,
'' `type`,
IFNULL(
(
SELECT
LOWER( system_effect.typeName )
FROM
invTypes system_effect INNER JOIN
mapDenormalize map_norm ON
map_norm.typeID = system_effect.typeID
WHERE
system_effect.groupID = 995 AND
map_norm.solarSystemID = map_sys.solarSystemID
LIMIT 1
), '') `effect`,
IFNULL(
(
SELECT
map_worm_class.wormholeClassID system_class
FROM
mapLocationWormholeClasses map_worm_class
WHERE
map_worm_class.locationID = map_sys.regionID
LIMIT 1
), 7) `security`
FROM
mapSolarSystems map_sys INNER JOIN
mapConstellations map_con ON
map_con.constellationID = map_sys.constellationID INNER JOIN
mapRegions map_reg ON
map_reg.regionID = map_sys.regionID";
private $whereQuery = "";
// exclude Jove Space
private $havingQuery = "HAVING
security IS NOT NULL";
private $orderByQuery = "ORDER BY
system_name";
private $limitQuery = "";
/**
* @param \Base $f3
*/
function beforeroute(\Base $f3) {
parent::beforeroute($f3);
// set header for all routes
header('Content-type: application/json');
}
/**
* build query
* @return string
*/
private function _getQuery(){
$query = $this->mainQuery;
$query .= ' ' . $this->whereQuery;
$query .= ' ' . $this->havingQuery;
$query .= ' ' . $this->orderByQuery;
$query .= ' ' . $this->limitQuery;
return $query;
}
/**
* get static system Data from CCPs Static DB export
* search column for IDs can be (solarSystemID, regionID, constellationID)
* @param array $columnIDs
* @param string $column
* @return Model\SystemModel[]
* @throws \Exception
*/
protected function _getSystemModelByIds($columnIDs = [], $column = 'solarSystemID'){
$systemModels = [];
$ccpDB = $this->getDB('CCP');
$this->whereQuery = "WHERE
map_sys." . $column . " IN (" . implode(',', $columnIDs) . ")";
$query = $this->_getQuery();
$rows = $ccpDB->exec($query, null, 60 * 60 * 24);
// format result
$mapper = new Mapper\CcpSystemsMapper($rows);
$ccpSystemsData = $mapper->getData();
foreach($ccpSystemsData as $ccpSystemData){
/**
* @var Model\SystemModel $system
*/
$system = Model\BasicModel::getNew('SystemModel');
$system->setData($ccpSystemData);
$systemModels[] = $system;
}
return $systemModels;
}
/**
* Get all static system Data from CCP DB (long cache timer)
* @return array
*/
public function getSystems(){
$ccpDB = $this->getDB('CCP');
$query = $this->_getQuery();
$rows = $ccpDB->exec($query, null, 60 * 60 * 24);
// format result
$mapper = new Mapper\CcpSystemsMapper($rows);
return $mapper->getData();
}
/**
* search systems by name
* @param \Base $f3
* @param array $params
*/
public function search(\Base $f3, $params){
$ccpDB = $this->getDB('CCP');
$searchToken = '';
// check for search parameter
if( isset($params['arg1']) ){
$searchToken = $params['arg1'];
}
// some "edge cases for testing if rounding works correct
//$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)
$this->whereQuery = "WHERE
map_sys.solarSystemName LIKE '%" . $searchToken . "%'";
$query = $this->_getQuery();
$rows = $ccpDB->exec($query);
// format result
$mapper = new Mapper\CcpSystemsMapper($rows);
$data = $mapper->getData();
echo json_encode($data);
}
/**
* save a new system to a a map
* @param \Base $f3
*/
public function save(\Base $f3){
$newSystemData = [];
$postData = (array)$f3->get('POST');
// system to be saved
$systemModel = null;
if(
isset($postData['systemData']) &&
isset($postData['mapData'])
){
$activeCharacter = $this->getCharacter();
if($activeCharacter){
$systemData = (array)$postData['systemData'];
$mapData = (array)$postData['mapData'];
if( isset($systemData['id']) ){
// update existing system (e.g. changed system description) -------------------
/**
* @var $system Model\SystemModel
*/
$system = Model\BasicModel::getNew('SystemModel');
$system->getById($systemData['id']);
if( !$system->dry() ){
if( $system->hasAccess($activeCharacter) ){
// system model found
$systemModel = $system;
}
}
}elseif( isset($mapData['id']) ){
// save NEW system ------------------------------------------------------------
/**
* @var $map Model\MapModel
*/
$map = Model\BasicModel::getNew('MapModel');
$map->getById($mapData['id']);
if(
!$map->dry() &&
$map->hasAccess($activeCharacter)
){
// make sure system is not already on map
// --> (e.g. multiple simultaneously save() calls for the same system)
if( is_null( $systemModel = $map->getSystemByCCPId($systemData['systemId']) ) ){
// system not found on map -> get static system data (CCP DB)
$systemModel = array_values( $this->_getSystemModelByIds([$systemData['systemId']]) )[0];
$systemModel->createdCharacterId = $activeCharacter;
}
// map is not changeable for a system! (security)
$systemData['mapId'] = $map;
}
}
}
}
if( !is_null($systemModel) ){
// set/update system
$systemModel->setData($systemData);
$systemModel->updatedCharacterId = $activeCharacter;
$systemModel->save();
$newSystemData = $systemModel->getData();
}
echo json_encode($newSystemData);
}
/**
* get system log data from CCP API import
* system Kills, Jumps,....
* @param \Base $f3
*/
public function graphData(\Base $f3){
$graphData = [];
$systemIds = $f3->get('POST.systemIds');
// number of log entries in each table per system (24 = 24h)
$logEntryCount = 24;
// table names with system data
$logTables = [
'jumps' => 'SystemJumpModel',
'shipKills' => 'SystemShipKillModel',
'podKills' => 'SystemPodKillModel',
'factionKills' => 'SystemFactionKillModel'
];
foreach($systemIds as $systemId){
foreach($logTables as $label => $ModelClass){
$systemLogModel = Model\BasicModel::getNew($ModelClass);
// 10min cache (could be up to 1h cache time)
$systemLogModel->getByForeignKey('systemId', $systemId, [], 60 * 10);
if( !$systemLogModel->dry() ){
$counter = 0;
for( $i = $logEntryCount; $i >= 1; $i--){
$column = 'value' . $i;
// ship and pod kills should be merged into one table
if($label == 'podKills'){
$graphData[$systemId]['shipKills'][$counter]['z'] = $systemLogModel->$column;
}else{
$dataSet = [
'x' => ($i - 1) . 'h',
'y' => $systemLogModel->$column
];
$graphData[$systemId][$label][] = $dataSet;
}
$counter++;
}
}
}
}
echo json_encode($graphData);
}
/**
* get system data for all systems within a constellation
* @param \Base $f3
* @param array $params
*/
public function constellationData(\Base $f3, $params){
$return = (object) [];
$return->error = [];
$return->systemData = [];
if( $activeCharacter = $this->getCharacter() ){
$constellationId = 0;
// check for search parameter
if( isset($params['arg1']) ){
$constellationId = (int)$params['arg1'];
}
$cacheKey = 'CACHE_CONSTELLATION_SYSTEMS_' . self::formatHiveKey($constellationId);
if($f3->exists($cacheKey)){
$return->systemData = $f3->get($cacheKey);
}else{
if($constellationId > 0){
$systemModels = $this->_getSystemModelByIds([$constellationId], 'constellationID');
foreach($systemModels as $systemModel){
$return->systemData[] = $systemModel->getData();
}
$f3->set($cacheKey, $return->systemData, $f3->get('PATHFINDER.CACHE.CONSTELLATION_SYSTEMS') );
}
}
}
echo json_encode($return);
}
/**
* set destination for specific systemIds
* @param \Base $f3
*/
public function setDestination(\Base $f3){
$postData = (array)$f3->get('POST');
$return = (object) [];
$return->error = [];
$return->systemData = [];
if(
($activeCharacter = $this->getCharacter()) &&
!empty($postData['systemData'])
){
$return->clearOtherWaypoints = (bool)$postData['clearOtherWaypoints'];
$return->first = (bool)$postData['first'];
/**
* @var Sso $ssoController
*/
$ssoController = self::getController('Sso');
foreach($postData['systemData'] as $systemData){
$waypointData = $ssoController->setWaypoint($activeCharacter, $systemData['systemId'], [
'clearOtherWaypoints' => $return->clearOtherWaypoints,
'first' => $return->first,
]);
if($waypointData['systemId']){
$return->systemData[] = $systemData;
}elseif( isset($waypointData['error']) ){
$return->error[] = $waypointData['error'];
}
}
}
echo json_encode($return);
}
/**
* delete systems and all its connections
* @param \Base $f3
*/
public function delete(\Base $f3){
$systemIds = (array)$f3->get('POST.systemIds');
if($activeCharacter = $this->getCharacter()){
/**
* @var Model\SystemModel $system
*/
$system = Model\BasicModel::getNew('SystemModel');
foreach((array)$systemIds as $systemId){
$system->getById($systemId);
$system->delete($activeCharacter);
$system->reset();
}
}
echo json_encode([]);
}
}