Files
pathfinder/app/Controller/Api/Access.php
Mark Friedrich 647bd7db58 - BC Break: _PHP_ namespaces changed (PSR-4 standard). The _root_ namespace for all _PF_ related scripts is Exodus4D\Pathfinder
- BC Break: Project folder structure changed. Removed `app/main` dir.
- BC Break: Core _PHP_ framework + dependencies moved into `composer.json` and are no longer part of this repo
2019-12-15 22:27:17 +01:00

67 lines
1.9 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: exodus4d
* Date: 24.05.2015
* Time: 17:42
*/
namespace Exodus4D\Pathfinder\Controller\Api;
use Exodus4D\Pathfinder\Controller;
use Exodus4D\Pathfinder\Model\Pathfinder;
class Access extends Controller\AccessController {
/**
* search character/corporation or alliance by name
* @param \Base $f3
* @param $params
* @throws \Exception
*/
public function search($f3, $params){
$accessData = [];
if(
array_key_exists('arg1', $params) &&
array_key_exists('arg2', $params)
){
$searchType = strtolower($params['arg1']);
$searchToken = strtolower($params['arg2']);
$accessModel = null;
switch($searchType){
case 'character':
$accessModel = Pathfinder\AbstractPathfinderModel::getNew('CharacterModel');
break;
case 'corporation':
$accessModel = Pathfinder\AbstractPathfinderModel::getNew('CorporationModel');
break;
case 'alliance':
$accessModel = Pathfinder\AbstractPathfinderModel::getNew('AllianceModel');
break;
}
if( is_object($accessModel) ){
// find "active" entries that have their "sharing" option activated
$accessList = $accessModel->find( [
"LOWER(name) LIKE :token AND " .
"active = 1 AND " .
"shared = 1 ",
':token' => '%' . $searchToken . '%'
]);
if($accessList){
foreach($accessList as $accessObject){
$accessData[] = $accessObject->getData();
}
}
}
}
echo json_encode($accessData);
}
}