Files
pathfinder/app/main/model/universe/factionmodel.php
Mark Friedrich a33615445e - new "_NPC faction_" added for k-space systems, closed #773
- improved file structure for _Model_ classes (`app/main/model/..`). Group by database name
- improved database connection handling (fixed persistent DB connections)
2019-04-12 21:34:29 +02:00

78 lines
1.8 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: Exodus 4D
* Date: 30.03.2019
* Time: 09:51
*/
namespace Model\Universe;
use DB\SQL\Schema;
class FactionModel extends AbstractUniverseModel {
/**
* @var string
*/
protected $table = 'faction';
/**
* @var array
*/
protected $fieldConf = [
'name' => [
'type' => Schema::DT_VARCHAR128,
'nullable' => false,
'default' => ''
],
'description' => [
'type' => Schema::DT_TEXT
],
'sizeFactor' => [
'type' => Schema::DT_INT,
'nullable' => false,
'default' => 0
],
'stationCount' => [
'type' => Schema::DT_INT,
'nullable' => false,
'default' => 0
],
'stationSystemCount' => [
'type' => Schema::DT_INT,
'nullable' => false,
'default' => 0
],
'systems' => [
'has-many' => ['Model\Universe\SystemModel', 'factionId']
]
];
/**
* get data
* @return \stdClass
*/
public function getData(){
$factionData = (object) [];
$factionData->id = $this->_id;
$factionData->name = $this->name;
return $factionData;
}
/**
* @param int $id
* @param string $accessToken
* @param array $additionalOptions
*/
protected function loadData(int $id, string $accessToken = '', array $additionalOptions = []){
$data = self::getF3()->ccpClient()->getUniverseFactionData($id);
if(!empty($data)){
$this->copyfrom($data, ['id', 'name', 'description', 'sizeFactor', 'stationCount', 'stationSystemCount']);
$this->save();
}
}
}