Files
pathfinder/app/main/controller/api/rest/connection.php
Mark Friedrich a154fe80e8 - remove all PHP "_ZMQ_" related dependencies from Pathfinder. PHP´s native Sockets work as replacement
- added status information for "WebSocket" installations to `/setup` page (e.g. active connections, startup time)
- removed "ext-zmq" as required PHP extension
- removed "react/zmq" as required Composer package
- removed "websoftwares/monolog-zmq-handler" as required Composer package
2019-02-24 22:24:54 +01:00

107 lines
3.3 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: Exodus 4D
* Date: 10.11.2018
* Time: 12:10
*/
namespace Controller\Api\Rest;
use Model;
class Connection extends AbstractRestController {
/**
* save a new connection or updates an existing (drag/drop) between two systems
* if a connection is changed (drag&drop) to another system. -> this function is called for update
* @param \Base $f3
* @throws \Exception
*/
public function put(\Base $f3){
$requestData = $this->getRequestData($f3);
$connectionData = [];
if($mapId = (int)$requestData['mapId']){
$activeCharacter = $this->getCharacter();
/**
* @var Model\MapModel $map
*/
$map = Model\BasicModel::getNew('MapModel');
$map->getById($mapId);
if($map->hasAccess($activeCharacter)){
$source = $map->getSystemById((int)$requestData['source']);
$target = $map->getSystemById((int)$requestData['target']);
if(
!is_null($source) &&
!is_null($target)
){
/**
* @var $connection Model\ConnectionModel
*/
$connection = Model\BasicModel::getNew('ConnectionModel');
$connection->getById((int)$requestData['id']);
$connection->mapId = $map;
$connection->source = $source;
$connection->target = $target;
$connection->copyfrom($connectionData, ['scope', 'type']);
// change the default type for the new connection
$connection->setDefaultTypeData();
if($connection->save($activeCharacter)){
$connectionData = $connection->getData();
// broadcast map changes
$this->broadcastMapData($connection->mapId);
}
}
}
}
$this->out($connectionData);
}
/**
* @param \Base $f3
* @param $params
* @throws \Exception
*/
public function delete(\Base $f3, $params){
$requestData = $this->getRequestData($f3);
$connectionIds = array_map('intval', explode(',', (string)$params['id']));
$deletedConnectionIds = [];
if($mapId = (int)$requestData['mapId']){
$activeCharacter = $this->getCharacter();
/**
* @var Model\MapModel $map
*/
$map = Model\BasicModel::getNew('MapModel');
$map->getById($mapId);
if($map->hasAccess($activeCharacter)){
foreach($connectionIds as $connectionId){
if($connection = $map->getConnectionById($connectionId)){
$connection->delete( $activeCharacter );
$connection->reset();
$deletedConnectionIds[] = $connectionId;
}
}
// broadcast map changes
if(count($deletedConnectionIds)){
$this->broadcastMapData($map);
}
}
}
$this->out($deletedConnectionIds);
}
}