* fixed #194 PHP 5.6 error * - closed #102 added "set waypoint/destination" context menu to route finder module - update "Select2" 4.0.0 -> 4.0.3 - update "Font Awesome" 4.6.1 -> 4.6.3 * - added *.js files for develop branch * - closed #195 fixed "BASE" dir for subDir installations - fixed "Home" menu link * - #195 improved js load path * - added "clear cache" function for manually cache clearing to /setup #200 #105 #158 - added cache size information to /setup - added current pathfinder "VERSION" to /setup - updated "requireJs" 2.1.20 ->2.2.0 - removed unnecessary page cache timings from static templates (page cache) * - added "document_root", "port", "protocol" and "PHP framework version" to /setup page - added new "shattered" wormhole types to "signature table", closed #182, #179 * - added new "delete old signatures" option to "signature reader" dialog, closed #95 * - added new housekeeping cronjob für cached files, closed #200 - added new cache size information to /setup page * - fixed signature groupId/typeId "overwriting" for already known signatures. closed #207 - improved system search dialog. Added trim(); before "api/signatures-> search" request * updated README.me * fixed PHP error "default object from empty value", closed #209 * reduced image file size * - added local storage (IndexedDB) - added local storage for map scroll position. closed #69 * - added "notice" panel for upcoming release information - improved layout for "release dialog" (GitHub API) - improved pagespeed (removed render blocking javascripts) - improved map scrollbar configuration - improved Chrome browser custom scrollbar layout - removed "sign up" buttons from "map panels", closed #214 * - fixed some session and cookie bugs * - added new requirement check for `max_input_vars` to /setup URL, closed #224 * - fixed isWormhole(); bug * -v1.1.1 added js build files * - removed IGB support #206 - removed location tracking by IGB * - added build files for upcoming version 1.1.2 - improved ajax authentication check and "logout" notification | closed #198 - improved logging, added missing log file configuration to pathfinder.ini - added logging for "unauthorized" requests | closed #198 - updated js "jQuery" 1.11.3 -> 3.0.0 | #206 - updated js "datatables" plugin 1.10.7 -> 1.10.12 | #206 - updated js "mCustomScrollbar" 3.1.14 -> 3.1.4 | #206 * - fixed some minor bugs in signature table module * - fixed type "Cataclysmic", closed #241 * - added new setup DB indexing for "system_neighbour" table to /setup route, #125 - fixed system "TrueSec" rounding in "routes module", closed #109 * - fixed system "TrueSec" rounding in "routes module", closed #109 * - added new wormhole statics for "Thera", closed #240 * - fixed missing statics for constellation "21000062" , closed #232 * - added "static" wormholes for "shattered" systems , closed #180 - added im/export function for "index" tables (*.csv import), as an alternative to the *.sql import, closed #125 * - added new system tooltip for "region name", closed #236 - updated "Bootstrap" JS-library 3.3.0 -> 3.3.5 * - removed console.log(),,, * minor bugfixes in /setup page * - added basic support for Russian signatures, closed #256 - added warning notification for invalid signature stings * - added basic support for Russian signatures, closed #256 * - added requirement check for "PDO", "PDO_MYSQL" to "/setup" route - imrpved DB PDO connection (added "TIMEOUT", forced "ERRMODE") - fixed broken "system alias" renaming dialog * - fixed "system graph" module rendering if there was no data available - improved "image gallery" initialization on landing page - added navigation to /setup page - updated "blueImpGallery" (fixed some bugs after jQuery 3.0 upgrade) 1.15.2 -> 2.21.3 - updated "blueImpGalleryBootstrap" (fixed some bugs after jQuery 3.0 upgrade) 3.1.1 -> 3.4.2 * - JS build files vor 1.1.2 * Updated pathfinder.css
491 lines
14 KiB
PHP
491 lines
14 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: exodus4d
|
|
* Date: 23.02.15
|
|
* Time: 23:56
|
|
*/
|
|
|
|
namespace Model;
|
|
|
|
use DB\SQL\Schema;
|
|
|
|
class SystemModel extends BasicModel {
|
|
|
|
const MAX_POS_X = 2300;
|
|
const MAX_POS_Y = 498;
|
|
|
|
protected $table = 'system';
|
|
|
|
protected $fieldConf = [
|
|
'active' => [
|
|
'type' => Schema::DT_BOOL,
|
|
'nullable' => false,
|
|
'default' => 1,
|
|
'index' => true
|
|
],
|
|
'mapId' => [
|
|
'type' => Schema::DT_INT,
|
|
'index' => true,
|
|
'belongs-to-one' => 'Model\MapModel',
|
|
'constraint' => [
|
|
[
|
|
'table' => 'map',
|
|
'on-delete' => 'CASCADE'
|
|
]
|
|
]
|
|
],
|
|
'systemId' => [
|
|
'type' => Schema::DT_INT,
|
|
'index' => true,
|
|
],
|
|
'name' => [
|
|
'type' => Schema::DT_VARCHAR128,
|
|
'nullable' => false,
|
|
'default' => ''
|
|
],
|
|
'alias' => [
|
|
'type' => Schema::DT_VARCHAR128,
|
|
'nullable' => false,
|
|
'default' => ''
|
|
],
|
|
'regionId' => [
|
|
'type' => Schema::DT_INT,
|
|
'index' => true,
|
|
],
|
|
'region' => [
|
|
'type' => Schema::DT_VARCHAR128,
|
|
'nullable' => false,
|
|
'default' => ''
|
|
],
|
|
'constellationId' => [
|
|
'type' => Schema::DT_INT,
|
|
'index' => true,
|
|
],
|
|
'constellation' => [
|
|
'type' => Schema::DT_VARCHAR128,
|
|
'nullable' => false,
|
|
'default' => ''
|
|
],
|
|
'effect' => [
|
|
'type' => Schema::DT_VARCHAR128,
|
|
'nullable' => false,
|
|
'default' => ''
|
|
],
|
|
'typeId' => [
|
|
'type' => Schema::DT_INT,
|
|
'index' => true,
|
|
'belongs-to-one' => 'Model\SystemTypeModel',
|
|
'constraint' => [
|
|
[
|
|
'table' => 'system_type',
|
|
'on-delete' => 'CASCADE'
|
|
]
|
|
]
|
|
],
|
|
'security' => [
|
|
'type' => Schema::DT_VARCHAR128,
|
|
'nullable' => false,
|
|
'default' => ''
|
|
],
|
|
'trueSec' => [
|
|
'type' => Schema::DT_FLOAT,
|
|
'nullable' => false,
|
|
'default' => 1
|
|
],
|
|
'statusId' => [
|
|
'type' => Schema::DT_INT,
|
|
'nullable' => false,
|
|
'default' => 1,
|
|
'index' => true,
|
|
'belongs-to-one' => 'Model\SystemStatusModel',
|
|
'constraint' => [
|
|
[
|
|
'table' => 'system_status',
|
|
'on-delete' => 'CASCADE'
|
|
]
|
|
]
|
|
],
|
|
'locked' => [
|
|
'type' => Schema::DT_BOOL,
|
|
'nullable' => false,
|
|
'default' => 0
|
|
],
|
|
'rally' => [
|
|
'type' => Schema::DT_BOOL,
|
|
'nullable' => false,
|
|
'default' => 0
|
|
],
|
|
'description' => [
|
|
'type' => Schema::DT_VARCHAR512,
|
|
'nullable' => false,
|
|
'default' => ''
|
|
],
|
|
'posX' => [
|
|
'type' => Schema::DT_INT,
|
|
'nullable' => false,
|
|
'default' => 0
|
|
],
|
|
'posY' => [
|
|
'type' => Schema::DT_INT,
|
|
'nullable' => false,
|
|
'default' => 0
|
|
],
|
|
'createdCharacterId' => [
|
|
'type' => Schema::DT_INT,
|
|
'index' => true,
|
|
'belongs-to-one' => 'Model\CharacterModel',
|
|
'constraint' => [
|
|
[
|
|
'table' => 'character',
|
|
'on-delete' => 'CASCADE'
|
|
]
|
|
]
|
|
],
|
|
'updatedCharacterId' => [
|
|
'type' => Schema::DT_INT,
|
|
'index' => true,
|
|
'belongs-to-one' => 'Model\CharacterModel',
|
|
'constraint' => [
|
|
[
|
|
'table' => 'character',
|
|
'on-delete' => 'CASCADE'
|
|
]
|
|
]
|
|
],
|
|
'signatures' => [
|
|
'has-many' => ['Model\SystemSignatureModel', 'systemId']
|
|
]
|
|
];
|
|
|
|
/**
|
|
* set an array with all data for a system
|
|
* @param $systemData
|
|
*/
|
|
public function setData($systemData){
|
|
|
|
foreach((array)$systemData as $key => $value){
|
|
|
|
if($key == 'created'){
|
|
continue;
|
|
}
|
|
|
|
if(!is_array($value)){
|
|
if($this->exists($key)){
|
|
$this->$key = $value;
|
|
}
|
|
}else{
|
|
// special array data
|
|
if($key == 'constellation'){
|
|
$this->constellationId = (int)$value['id'];
|
|
$this->constellation = $value['name'];
|
|
}elseif($key == 'region'){
|
|
$this->regionId = (int)$value['id'];
|
|
$this->region = $value['name'];
|
|
}elseif($key == 'type'){
|
|
$this->typeId = (int)$value['id'];
|
|
}elseif($key == 'status'){
|
|
$this->statusId = (int)$value['id'];
|
|
}elseif($key == 'position'){
|
|
$this->posX = (int)$value['x'];
|
|
$this->posY = (int)$value['y'];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* get map data as object
|
|
* @return object
|
|
* @throws \Exception
|
|
*/
|
|
public function getData(){
|
|
|
|
// check if there is cached data
|
|
$systemData = $this->getCacheData();
|
|
|
|
if(is_null($systemData)){
|
|
// no cached system data found
|
|
|
|
$systemData = (object) [];
|
|
$systemData->id = $this->id;
|
|
$systemData->mapId = is_object($this->mapId) ? $this->mapId->id : 0;
|
|
$systemData->systemId = $this->systemId;
|
|
$systemData->name = $this->name;
|
|
$systemData->alias = $this->alias;
|
|
$systemData->effect = $this->effect;
|
|
$systemData->security = $this->security;
|
|
$systemData->trueSec = $this->trueSec;
|
|
|
|
$systemData->region = (object) [];
|
|
$systemData->region->id = $this->regionId;
|
|
$systemData->region->name = $this->region;
|
|
|
|
$systemData->constellation = (object) [];
|
|
$systemData->constellation->id = $this->constellationId;
|
|
$systemData->constellation->name = $this->constellation;
|
|
|
|
$systemData->type = (object) [];
|
|
$systemData->type->id = $this->typeId->id;
|
|
$systemData->type->name = $this->typeId->name;
|
|
|
|
$systemData->status = (object) [];
|
|
$systemData->status->id = is_object($this->statusId) ? $this->statusId->id : 0;
|
|
$systemData->status->name = is_object($this->statusId) ? $this->statusId->name : '';
|
|
|
|
$systemData->locked = $this->locked;
|
|
$systemData->rally = $this->rally;
|
|
$systemData->description = $this->description;
|
|
|
|
$systemData->statics = $this->getStaticWormholeData();
|
|
|
|
$systemData->position = (object) [];
|
|
$systemData->position->x = $this->posX;
|
|
$systemData->position->y = $this->posY;
|
|
|
|
|
|
$systemData->created = (object) [];
|
|
$systemData->created->created = strtotime($this->created);
|
|
if( is_object($this->createdCharacterId) ){
|
|
$systemData->created->character = $this->createdCharacterId->getData();
|
|
}
|
|
|
|
$systemData->updated = (object) [];
|
|
$systemData->updated->updated = strtotime($this->updated);
|
|
if( is_object($this->updatedCharacterId) ){
|
|
$systemData->updated->character = $this->updatedCharacterId->getData();
|
|
}
|
|
|
|
// max caching time for a system
|
|
// the cached date has to be cleared manually on any change
|
|
// this includes system, connection,... changes (all dependencies)
|
|
$this->updateCacheData($systemData, '', 300);
|
|
}
|
|
|
|
return $systemData;
|
|
}
|
|
|
|
/**
|
|
* setter for system security value
|
|
* @param $trueSec
|
|
* @return float
|
|
*/
|
|
public function set_trueSec($trueSec){
|
|
|
|
if(
|
|
$trueSec > 0 &&
|
|
$trueSec < 0.1
|
|
){
|
|
// 0.3 is still a LS -> no rounding
|
|
$trueSec = 0.1;
|
|
}else{
|
|
$trueSec = round($trueSec, 1);
|
|
}
|
|
|
|
return $trueSec;
|
|
}
|
|
|
|
/**
|
|
* setter validation for x coordinate
|
|
* @param $posX
|
|
* @return int|number
|
|
*/
|
|
public function set_posX($posX){
|
|
$posX = abs($posX);
|
|
if($posX > self::MAX_POS_X){
|
|
$posX = self::MAX_POS_X;
|
|
}
|
|
|
|
return $posX;
|
|
}
|
|
|
|
/**
|
|
* setter validation for y coordinate
|
|
* @param $posY
|
|
* @return int|number
|
|
*/
|
|
public function set_posY($posY){
|
|
$posY = abs($posY);
|
|
if($posY > self::MAX_POS_Y){
|
|
$posY = self::MAX_POS_Y;
|
|
}
|
|
|
|
return $posY;
|
|
}
|
|
|
|
/**
|
|
* check object for model access
|
|
* @param CharacterModel $characterModel
|
|
* @return mixed
|
|
*/
|
|
public function hasAccess(CharacterModel $characterModel){
|
|
return $this->mapId->hasAccess($characterModel);
|
|
}
|
|
|
|
/**
|
|
* delete a system from a map
|
|
* hint: signatures and connections will be deleted on cascade
|
|
* @param CharacterModel $characterModel
|
|
*/
|
|
public function delete(CharacterModel $characterModel){
|
|
if( !$this->dry() ){
|
|
// check if character has access
|
|
if($this->hasAccess($characterModel)){
|
|
$this->erase();
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* get all signatures of this system
|
|
* @return SystemModel array
|
|
*/
|
|
public function getSignatures(){
|
|
$this->filter('signatures', ['active = ?', 1], ['order' => 'name']);
|
|
|
|
$signatures = [];
|
|
if($this->signatures){
|
|
$signatures = $this->signatures;
|
|
}
|
|
|
|
return $signatures;
|
|
}
|
|
|
|
/**
|
|
* get all data for all Signatures in this system
|
|
* @return array
|
|
*/
|
|
public function getSignaturesData(){
|
|
$signatures = $this->getSignatures();
|
|
|
|
$signaturesData = [];
|
|
foreach($signatures as $signature){
|
|
$signaturesData[] = $signature->getData();
|
|
}
|
|
|
|
return $signaturesData;
|
|
}
|
|
|
|
/**
|
|
* get Signature by id and check for access
|
|
* @param CharacterModel $characterModel
|
|
* @param $id
|
|
* @return bool|null
|
|
*/
|
|
public function getSignatureById(CharacterModel $characterModel, $id){
|
|
$signature = null;
|
|
|
|
if($this->hasAccess($characterModel)){
|
|
$this->filter('signatures', ['active = ? AND id = ?', 1, $id]);
|
|
if($this->signatures){
|
|
$signature = reset( $this->signatures );
|
|
}
|
|
}
|
|
|
|
return $signature;
|
|
}
|
|
|
|
/**
|
|
* get a signature by its "unique" 3-digit name
|
|
* @param CharacterModel $characterModel
|
|
* @param $name
|
|
* @return mixed|null
|
|
*/
|
|
public function getSignatureByName(CharacterModel $characterModel, $name){
|
|
$signature = null;
|
|
|
|
if($this->hasAccess($characterModel)){
|
|
$this->filter('signatures', ['active = ? AND name = ?', 1, $name]);
|
|
if($this->signatures){
|
|
$signature = reset( $this->signatures );
|
|
}
|
|
}
|
|
|
|
return $signature;
|
|
}
|
|
|
|
/**
|
|
* check whether this system is a wormhole
|
|
* @return bool
|
|
*/
|
|
public function isWormhole(){
|
|
return ($this->typeId->id === 1);
|
|
}
|
|
|
|
/**
|
|
* check whether this syste is a shattered wormhole
|
|
* @return bool
|
|
*/
|
|
public function isShatteredWormhole(){
|
|
return ($this->isWormhole() && $this->security === 'SH');
|
|
}
|
|
|
|
/**
|
|
* get static WH data for this system
|
|
* -> any WH system has at least one static WH
|
|
* @return array
|
|
* @throws \Exception
|
|
*/
|
|
protected function getStaticWormholeData(){
|
|
$wormholeData = [];
|
|
|
|
// only wormholes have "static" connections
|
|
if($this->isWormhole()){
|
|
// get static systems by "constellationId" --------------------------------------------
|
|
$constellationWormholeModel = self::getNew('ConstellationWormholeModel');
|
|
$systemStatics = $constellationWormholeModel->find([
|
|
'constellationId = :constellationId',
|
|
':constellationId' => $this->constellationId
|
|
]);
|
|
|
|
if( is_object($systemStatics) ){
|
|
foreach($systemStatics as $systemStatic){
|
|
$wormholeData[] = $systemStatic->getData();
|
|
}
|
|
}
|
|
|
|
// get static systems by "systemId" (shattered wormholes) -----------------------------
|
|
$systemWormholeModel = self::getNew('SystemWormholeModel');
|
|
$systemStatics = $systemWormholeModel->find([
|
|
'systemId = :systemId',
|
|
':systemId' => $this->systemId
|
|
]);
|
|
|
|
if( is_object($systemStatics) ){
|
|
foreach($systemStatics as $systemStatic){
|
|
$wormholeData[] = $systemStatic->getData();
|
|
}
|
|
}
|
|
}
|
|
|
|
return $wormholeData;
|
|
}
|
|
|
|
/**
|
|
* see parent
|
|
*/
|
|
public function clearCacheData(){
|
|
parent::clearCacheData();
|
|
|
|
// clear map cache as well
|
|
$this->mapId->clearCacheData();
|
|
}
|
|
|
|
/**
|
|
* overwrites parent
|
|
* @param null $db
|
|
* @param null $table
|
|
* @param null $fields
|
|
* @return bool
|
|
*/
|
|
public static function setup($db=null, $table=null, $fields=null){
|
|
$status = parent::setup($db,$table,$fields);
|
|
|
|
if($status === true){
|
|
$status = parent::setMultiColumnIndex(['mapId', 'systemId'], true);
|
|
}
|
|
|
|
return $status;
|
|
}
|
|
|
|
}
|