- New ESI data import for wormhole type data from _ESI_, closed #852 - New ESI data import static wormholes, closed #852 - Improved performance for character authorization (PHP). Reduced number of _SQL_ queries. - Improved HTTP cache header for `api/map/initData`, 'api/user/getEveServerStatus' ajax requests
87 lines
2.3 KiB
PHP
87 lines
2.3 KiB
PHP
<?php
|
|
|
|
|
|
namespace Model\Universe;
|
|
|
|
use DB\SQL\Schema;
|
|
|
|
class AllianceModel extends AbstractUniverseModel {
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $table = 'alliance';
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $fieldConf = [
|
|
'name' => [
|
|
'type' => Schema::DT_VARCHAR128,
|
|
'nullable' => false,
|
|
'default' => ''
|
|
],
|
|
'ticker' => [
|
|
'type' => Schema::DT_VARCHAR128,
|
|
'nullable' => false,
|
|
'default' => ''
|
|
],
|
|
'dateFounded' => [
|
|
'type' => Schema::DT_DATETIME,
|
|
'default' => null
|
|
],
|
|
'factionId' => [
|
|
'type' => Schema::DT_INT,
|
|
'index' => true,
|
|
'belongs-to-one' => 'Model\Universe\FactionModel',
|
|
'constraint' => [
|
|
[
|
|
'table' => 'faction',
|
|
'on-delete' => 'SET NULL'
|
|
]
|
|
]
|
|
],
|
|
'corporations' => [
|
|
'has-many' => ['Model\Universe\CorporationModel', 'allianceId']
|
|
],
|
|
'sovereigntySystems' => [
|
|
'has-many' => ['Model\Universe\SovereigntyMapModel', 'allianceId']
|
|
]
|
|
];
|
|
|
|
/**
|
|
* get data
|
|
* @return \stdClass
|
|
*/
|
|
public function getData(){
|
|
$data = (object) [];
|
|
$data->id = $this->_id;
|
|
$data->name = $this->name;
|
|
$data->ticker = $this->ticker;
|
|
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* load alliance by Id either from DB or load data from API
|
|
* @param int $id
|
|
* @param string $accessToken
|
|
* @param array $additionalOptions
|
|
*/
|
|
protected function loadData(int $id, string $accessToken = '', array $additionalOptions = []){
|
|
$data = self::getF3()->ccpClient()->getAllianceData($id);
|
|
if(!empty($data) && !isset($data['error'])){
|
|
if($data['factionId']){
|
|
/**
|
|
* @var $faction FactionModel
|
|
*/
|
|
$faction = $this->rel('factionId');
|
|
$faction->loadById($data['factionId'], $accessToken, $additionalOptions);
|
|
$data['factionId'] = $faction;
|
|
}
|
|
|
|
$this->copyfrom($data, ['id', 'name', 'ticker', 'dateFounded', 'factionId']);
|
|
$this->save();
|
|
}
|
|
}
|
|
} |