- New CREST controller - Database restructuring - improved type-casting for some controller functions - New login process - Fixed some bugs during the setup process (/setup root) - Added CREST request caching by response headers
124 lines
2.9 KiB
PHP
124 lines
2.9 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: exodus4d
|
|
* Date: 30.03.15
|
|
* Time: 00:04
|
|
*/
|
|
|
|
namespace Model;
|
|
|
|
use DB\SQL\Schema;
|
|
|
|
class CharacterLogModel extends BasicModel {
|
|
|
|
protected $table = 'character_log';
|
|
|
|
/**
|
|
* caching for relational data
|
|
* -> 10s matches REST API - Expire: Header-Data
|
|
* for "Location" calls
|
|
* @var int
|
|
*/
|
|
protected $rel_ttl = 10;
|
|
|
|
protected $fieldConf = [
|
|
'active' => [
|
|
'type' => Schema::DT_BOOL,
|
|
'nullable' => false,
|
|
'default' => 1,
|
|
'index' => true
|
|
],
|
|
'characterId' => [
|
|
'type' => Schema::DT_INT,
|
|
'index' => true,
|
|
'unique' => true,
|
|
'belongs-to-one' => 'Model\CharacterModel',
|
|
'constraint' => [
|
|
[
|
|
'table' => 'character',
|
|
'on-delete' => 'CASCADE'
|
|
]
|
|
]
|
|
],
|
|
'systemId' => [
|
|
'type' => Schema::DT_INT,
|
|
'index' => true
|
|
],
|
|
'systemName' => [
|
|
'type' => Schema::DT_VARCHAR128,
|
|
'nullable' => false,
|
|
'default' => ''
|
|
],
|
|
'shipId' => [
|
|
'type' => Schema::DT_INT,
|
|
'index' => true
|
|
],
|
|
'shipName' => [
|
|
'type' => Schema::DT_VARCHAR128,
|
|
'nullable' => false,
|
|
'default' => ''
|
|
],
|
|
'shipTypeName' => [
|
|
'type' => Schema::DT_VARCHAR128,
|
|
'nullable' => false,
|
|
'default' => ''
|
|
]
|
|
];
|
|
|
|
public function __construct($db = NULL, $table = NULL, $fluid = NULL, $ttl = 0){
|
|
|
|
parent::__construct($db, $table, $fluid, $ttl);
|
|
|
|
// events -----------------------------------------
|
|
$this->beforeerase(function($self){
|
|
$self->clearCacheData();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* set log data from object
|
|
* @param object $logData
|
|
*/
|
|
public function setData($logData){
|
|
if( !empty($logData->system) ){
|
|
$this->systemId = $logData->system['id'];
|
|
$this->systemName = $logData->system['name'];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* get all character log data
|
|
* @return object
|
|
*/
|
|
public function getData(){
|
|
|
|
$logData = (object) [];
|
|
$logData->system = (object) [];
|
|
$logData->system->id = $this->systemId;
|
|
$logData->system->name = $this->systemName;
|
|
|
|
$logData->ship = (object) [];
|
|
$logData->ship->id = $this->shipId;
|
|
$logData->ship->name = $this->shipName;
|
|
$logData->ship->typeName = $this->shipTypeName;
|
|
|
|
return $logData;
|
|
}
|
|
|
|
/**
|
|
* see parent
|
|
*/
|
|
public function clearCacheData(){
|
|
parent::clearCacheData();
|
|
|
|
// delete log cache key as well
|
|
$f3 = self::getF3();
|
|
$character = $this->characterId;
|
|
|
|
$character->clearCacheData();
|
|
$f3->clear('LOGGED.user.character.id_' . $character->id);
|
|
|
|
return true;
|
|
}
|
|
}
|