Skip to content

Commit

Permalink
Merge pull request #1 from samoneilll/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
samoneilll authored Aug 30, 2020
2 parents 62dc991 + 6cbccff commit cab7695
Show file tree
Hide file tree
Showing 382 changed files with 68,389 additions and 1,760 deletions.
1 change: 0 additions & 1 deletion app/Controller/Api/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Exodus4D\Pathfinder\Model\AbstractModel;
use Exodus4D\Pathfinder\Model\Pathfinder;
use Exodus4D\Pathfinder\Model\Universe;
use Exodus4D\Pathfinder\Exception;

/**
* Map controller
Expand Down
82 changes: 82 additions & 0 deletions app/Controller/Api/Rest/SystemSearch.php
Original file line number Diff line number Diff line change
@@ -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);
}
}
60 changes: 0 additions & 60 deletions app/Controller/Api/Universe.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,66 +37,6 @@ public function search(\Base $f3, $params){
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;

$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;

$systems = $system->find($filter, $options);
if($systems){
foreach($systems as $system){
if($systemData = $system->fromIndex()){
$return->results[] = $systemData;
}
}
}
}

$return->pagination = ['more' => $morePages, 'count' => $count];

echo json_encode($return);
}

/**
* get system data for all systems within a constellation
* @param \Base $f3
Expand Down
2 changes: 0 additions & 2 deletions app/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ public function init(\Base $f3){
$resource = Resource::instance();
$resource->register('script', 'app/login');
$resource->register('script', 'app/mappage', 'prefetch');
$resource->register('image', 'sso/signature.png');
$resource->register('image', 'sso/gameplay.png');
}

}
File renamed without changes.
2 changes: 1 addition & 1 deletion app/Controller/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ class_exists('\Redis')
// -> the DSN format is not the same, convert URL format into DSN
if(
strtolower(session_module_name()) == 'redis' &&
($parts = parse_url(strtolower(session_save_path())))
($parts = parse_url(session_save_path()))
){
// parse URL parameters
parse_str((string)$parts['query'], $params);
Expand Down
76 changes: 76 additions & 0 deletions app/Db/Sql/Mysql/Column.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php


namespace Exodus4D\Pathfinder\Db\Sql\Mysql;

use DB\SQL;

class Column extends SQL\Column {

/**
* missing table name error
*/
const ERROR_TABLE_NAME_MISSING = 'Table name missing for FOREIGN KEY in `%s`';

/**
* drop constraint from this column
* @param Constraint $constraint
*/
public function dropConstraint(Constraint $constraint){
$this->table->dropConstraint($constraint);
}

/**
* add constraint to this column
* @param Constraint $constraint
*/
public function addConstraint(Constraint $constraint){
$this->table->addConstraint($constraint);
}

/**
* @param Constraint $constraint
* @return mixed
*/
public function constraintExists(Constraint $constraint){
return $this->table->constraintExists($constraint);
}

/**
* get a new column based constraint
* $constraintData['table'] => referenceTable name (required)
* $constraintData['id'] => referenceColumns (optional) default: ['id']
* $constraintData['on-delete'] => ON DELETE action (optional) default: see \DB\SQL\MySQL\Constraint const
* $constraintData['on-update'] => ON UPDATE action (optional) default: see \DB\SQL\MySQL\Constraint const
*
* @param array $constraintData
* @return Constraint
*/
public function newConstraint($constraintData){

$constraint = null;

if(isset($constraintData['table'])){
if(isset($constraintData['column'])){
$constraintData['column'] = (array)$constraintData['column'];
}else{
$constraintData['column'] = ['id'];
}

$constraint = new Constraint($this->table, $this->name, $constraintData['table'], $constraintData['column']);

if(isset($constraintData['on-delete'])){
$constraint->setOnDelete($constraintData['on-delete']);
}

if(isset($constraintData['on-update'])){
$constraint->setOnUpdate($constraintData['on-update']);
}

}else{
trigger_error(sprintf(self::ERROR_TABLE_NAME_MISSING, $this->table->name . '->' . $this->name));
}

return $constraint;
}
}
Loading

0 comments on commit cab7695

Please sign in to comment.