- added new "select connection" feature to map - ctrl + click for multiselect, closed #174 - added new "wormhole type" table to "Jump info" dialog, closed #174 - added new re-order drag&drop feature for pannels, #470 closed #234 - fixed PHP-Doc comments - added @throw statements - fixed some Javascript memory leaks with infinite counters - updated "Peity jQuery plugin" `3.2.0` -> `3.2.1`
96 lines
3.0 KiB
PHP
96 lines
3.0 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: exodu
|
|
* Date: 29.07.2017
|
|
* Time: 11:31
|
|
*/
|
|
|
|
namespace Controller\Ccp;
|
|
|
|
|
|
use Controller\Controller;
|
|
use Model\BasicModel;
|
|
|
|
class Universe extends Controller {
|
|
|
|
/**
|
|
* Set up "Universe" Database
|
|
* @param \Base $f3
|
|
* @throws \Exception
|
|
*/
|
|
public function setupDB(\Base $f3){
|
|
$this->setupRegions($f3);
|
|
$this->setupConstellations($f3);
|
|
}
|
|
|
|
/**
|
|
* get all regions from CCP and store region data
|
|
* @param \Base $f3
|
|
* @throws \Exception
|
|
*/
|
|
private function setupRegions(\Base $f3){
|
|
$this->getDB('UNIVERSE');
|
|
$regionIds = $f3->ccpClient->getRegions();
|
|
$regionModel = BasicModel::getNew('Universe\RegionModel');
|
|
|
|
foreach($regionIds as $regionId){
|
|
$regionModel->getById($regionId);
|
|
|
|
if($regionModel->dry()){
|
|
$regionData = $f3->ccpClient->getRegionData($regionId);
|
|
if( !empty($regionData) ){
|
|
$regionModel->copyfrom($regionData, ['id', 'name', 'description']);
|
|
$regionModel->save();
|
|
}
|
|
}
|
|
|
|
$regionModel->reset();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* get all constellations from CCP and store constellation data
|
|
* @param \Base $f3
|
|
* @throws \Exception
|
|
*/
|
|
private function setupConstellations(\Base $f3){
|
|
$this->getDB('UNIVERSE');
|
|
$constellationIds = $f3->ccpClient->getConstellations();
|
|
$constellationModel = BasicModel::getNew('Universe\ConstellationModel');
|
|
|
|
foreach($constellationIds as $constellationId){
|
|
$constellationModel->getById($constellationId);
|
|
|
|
if($constellationModel->dry()){
|
|
$constellationData = $f3->ccpClient->getConstellationData($constellationId);
|
|
|
|
if( !empty($constellationData) ){
|
|
// $constellationModel->copyfrom($constellationData, ['id', 'name', 'regionId']);
|
|
$constellationModel->copyfrom($constellationData, function($fields){
|
|
// add position coordinates as separate columns
|
|
if(is_array($fields['position'])){
|
|
$position = $fields['position'];
|
|
if(
|
|
isset($position['x']) &&
|
|
isset($position['y']) &&
|
|
isset($position['z'])
|
|
){
|
|
$fields['x'] = $position['x'];
|
|
$fields['y'] = $position['y'];
|
|
$fields['z'] = $position['z'];
|
|
}
|
|
}
|
|
|
|
// filter relevant data for insert
|
|
return array_intersect_key($fields, array_flip(['id', 'name', 'regionId', 'x', 'y', 'z']));
|
|
});
|
|
|
|
$constellationModel->save();
|
|
}
|
|
}
|
|
|
|
$constellationModel->reset();
|
|
}
|
|
}
|
|
} |