Files
pathfinder/app/Model/Pathfinder/ActivityLogModel.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

205 lines
5.8 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: Exodus
* Date: 01.10.2016
* Time: 15:11
*/
namespace Exodus4D\Pathfinder\Model\Pathfinder;
use DB\SQL\Schema;
class ActivityLogModel extends AbstractPathfinderModel {
/**
* @var string
*/
protected $table = 'activity_log';
/**
* @var array
*/
protected $fieldConf = [
'active' => [
'type' => Schema::DT_BOOL,
'nullable' => false,
'default' => 1,
'index' => true
],
'characterId' => [
'type' => Schema::DT_INT,
'index' => true,
'belongs-to-one' => 'Exodus4D\Pathfinder\Model\Pathfinder\CharacterModel',
'constraint' => [
[
'table' => 'character',
'on-delete' => 'CASCADE'
]
]
],
'mapId' => [
'type' => Schema::DT_INT,
'index' => true,
'belongs-to-one' => 'Exodus4D\Pathfinder\Model\Pathfinder\MapModel',
'constraint' => [
[
'table' => 'map',
'on-delete' => 'SET NULL' // keep log data on map delete
]
]
],
// map actions -----------------------------------------------------
'mapCreate' => [
'type' => Schema::DT_SMALLINT,
'nullable' => false,
'default' => 0,
'counter' => true
],
'mapUpdate' => [
'type' => Schema::DT_SMALLINT,
'nullable' => false,
'default' => 0,
'counter' => true
],
'mapDelete' => [
'type' => Schema::DT_SMALLINT,
'nullable' => false,
'default' => 0,
'counter' => true
],
// system actions -----------------------------------------------------
'systemCreate' => [
'type' => Schema::DT_SMALLINT,
'nullable' => false,
'default' => 0,
'counter' => true
],
'systemUpdate' => [
'type' => Schema::DT_SMALLINT,
'nullable' => false,
'default' => 0,
'counter' => true
],
'systemDelete' => [
'type' => Schema::DT_SMALLINT,
'nullable' => false,
'default' => 0,
'counter' => true
],
// connection actions -------------------------------------------------
'connectionCreate' => [
'type' => Schema::DT_SMALLINT,
'nullable' => false,
'default' => 0,
'counter' => true
],
'connectionUpdate' => [
'type' => Schema::DT_SMALLINT,
'nullable' => false,
'default' => 0,
'counter' => true
],
'connectionDelete' => [
'type' => Schema::DT_SMALLINT,
'nullable' => false,
'default' => 0,
'counter' => true
],
// signature actions -------------------------------------------------
'signatureCreate' => [
'type' => Schema::DT_SMALLINT,
'nullable' => false,
'default' => 0,
'counter' => true
],
'signatureUpdate' => [
'type' => Schema::DT_SMALLINT,
'nullable' => false,
'default' => 0,
'counter' => true
],
'signatureDelete' => [
'type' => Schema::DT_SMALLINT,
'nullable' => false,
'default' => 0,
'counter' => true
],
];
/**
* ActivityLogModel constructor.
* @param null $db
* @param null $table
* @param null $fluid
* @param int $ttl
*/
public function __construct($db = NULL, $table = NULL, $fluid = NULL, $ttl = 0){
$this->addStaticDateFieldConfig();
parent::__construct($db, $table, $fluid, $ttl);
}
/**
* extent the fieldConf Array with static fields for each table
*/
private function addStaticDateFieldConfig(){
if(is_array($this->fieldConf)){
$staticFieldConfig = [
'year' => [
'type' => Schema::DT_SMALLINT,
'nullable' => false,
'default' => date('o'), // 01.01 could be week 53 -> NOT "current" year!
'index' => true
],
'week' => [ // week in year [1-53]
'type' => Schema::DT_TINYINT,
'nullable' => false,
'default' => 1,
'index' => true
],
];
$this->fieldConf = array_merge($staticFieldConfig, $this->fieldConf);
}
}
/**
* get all table columns that are used as "counter" columns
* @return array
*/
public function getCountableColumnNames(): array {
$fieldConf = $this->getFieldConfiguration();
$filterCounterColumns = function($key, $value){
return isset($value['counter']) ? $key : false;
};
return array_values(array_filter(array_map($filterCounterColumns, array_keys($fieldConf), $fieldConf)));
}
/**
* overwrites parent
* @param null $db
* @param null $table
* @param null $fields
* @return bool
* @throws \Exception
*/
public static function setup($db = null, $table = null, $fields = null){
if($status = parent::setup($db, $table, $fields)){
$status = parent::setMultiColumnIndex(['year', 'week', 'characterId', 'mapId'], true);
if($status === true){
$status = parent::setMultiColumnIndex(['year', 'week', 'characterId']);
}
}
return $status;
}
}