forked from exodus4d/pathfinder
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from samoneilll/develop
Develop
- Loading branch information
Showing
382 changed files
with
68,389 additions
and
1,760 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.