Files
pathfinder/app/main/model/connectionlogmodel.php
Mark Friedrich 07d5be71b2 - added custom/editable ship jump logs, #709
- fixed DB setup error: "`system`.`description` can´t have a default value", closed #701
- upgraded "lazyload" js lib `v1.9.5` → `v1.9.7`
- upgraded multiple 3rd party NPM dependencies for Gulp build
2018-10-27 00:45:53 +02:00

138 lines
3.8 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: exodu
* Date: 05.11.2017
* Time: 17:51
*/
namespace Model;
use DB\SQL\Schema;
class ConnectionLogModel extends BasicModel {
protected $table = 'connection_log';
protected $fieldConf = [
'active' => [
'type' => Schema::DT_BOOL,
'nullable' => false,
'default' => 1,
'index' => true
],
'connectionId' => [
'type' => Schema::DT_INT,
'index' => true,
'belongs-to-one' => 'Model\ConnectionModel',
'constraint' => [
[
'table' => 'connection',
'on-delete' => 'CASCADE'
]
],
'validate' => 'notDry'
],
'record' => [
'type' => Schema::DT_BOOL,
'nullable' => false,
'default' => 1,
'index' => true
],
'shipTypeId' => [
'type' => Schema::DT_INT,
'index' => true,
'validate' => 'notEmpty'
],
'shipTypeName' => [
'type' => Schema::DT_VARCHAR128,
'nullable' => false,
'default' => ''
],
'shipMass' => [
'type' => Schema::DT_FLOAT,
'nullable' => false,
'default' => 0,
'validate' => 'notEmpty'
],
'characterId' => [
'type' => Schema::DT_INT,
'index' => true,
'validate' => 'notEmpty'
],
'characterName' => [
'type' => Schema::DT_VARCHAR128,
'nullable' => false,
'default' => ''
]
];
/**
* set map data by an associative array
* @param array $data
*/
public function setData(array $data){
$this->copyfrom($data, ['shipTypeId', 'shipTypeName', 'shipMass', 'characterId', 'characterName']);
}
/**
* get connection log data
* @return \stdClass
*/
public function getData() : \stdClass {
$logData = (object) [];
$logData->id = $this->id;
$logData->active = $this->active;
$logData->record = $this->record;
$logData->connection = (object) [];
$logData->connection->id = $this->get('connectionId', true);
$logData->ship = (object) [];
$logData->ship->typeId = (int)$this->shipTypeId;
$logData->ship->typeName = $this->shipTypeName;
$logData->ship->mass = $this->shipMass;
$logData->character = (object) [];
$logData->character->id = $this->characterId;
$logData->character->name = $this->characterName;
$logData->created = (object) [];
$logData->created->created = strtotime($this->created);
$logData->updated = (object) [];
$logData->updated->updated = strtotime($this->updated);
return $logData;
}
/**
* validate shipTypeId
* @param string $key
* @param string $val
* @return bool
*/
protected function validate_shipTypeId(string $key, string $val): bool {
return !empty((int)$val);
}
/**
* @return ConnectionModel
*/
public function getConnection() : ConnectionModel {
return $this->get('connectionId');
}
/**
* check object for model access
* @param CharacterModel $characterModel
* @return bool
*/
public function hasAccess(CharacterModel $characterModel) : bool {
$access = false;
if( !$this->dry() ){
$access = $this->getConnection()->hasAccess($characterModel);
}
return $access;
}
}