improved request caching, new C4 statics, landing page carousel,

This commit is contained in:
exodus4d
2015-07-06 20:39:36 +02:00
parent d223ac6555
commit 075d2330bd
34 changed files with 1333 additions and 1062 deletions

View File

@@ -24,6 +24,7 @@ class Connection extends \Controller\AccessController{
/**
* 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 $f3
*/
public function save($f3){
@@ -40,40 +41,32 @@ class Connection extends \Controller\AccessController{
$user = $this->_getUser();
if($user){
// get map model
// get map model and check map access
$map = Model\BasicModel::getNew('MapModel');
$map->getById( (int)$mapData['id'] );
// get source model (system)
$source = Model\BasicModel::getNew('SystemModel');
$source->getById( (int)$connectionData['source'] );
// get target model (system)
$target = Model\BasicModel::getNew('SystemModel');
$target->getById( (int)$connectionData['target'] );
// map model and systeme are required for a new connection!
if(
!$map->dry() &&
!$source->dry() &&
!$target->dry()
){
$connection = Model\BasicModel::getNew('ConnectionModel');
$connection->getById( (int)$connectionData['id'] );
$connection->mapId = $map;
$connection->source = $source;
$connection->target = $target;
if( $map->hasAccess($user) ){
$source = $map->getSystem( (int)$connectionData['source'] );
$target = $map->getSystem( (int)$connectionData['target'] );
if(
$connection->isValid() &&
$connection->hasAccess($user)
!is_null($source) &&
!is_null($target)
){
$connection->save();
$newConnectionData = $connection->getData();
$connection = Model\BasicModel::getNew('ConnectionModel');
$connection->getById( (int)$connectionData['id'] );
$connectionData['mapId'] = $map;
$connection->setData($connectionData);
if( $connection->isValid() ){
$connection->save();
$newConnectionData = $connection->getData();
}
}
}
}
}

View File

@@ -157,12 +157,8 @@ class Map extends \Controller\AccessController {
$map->getById( (int)$formData['id'] );
// check if the user has access to this map
$mapAccess = true;
if(! $map->dry() ){
$mapAccess = $map->hasAccess($user);
}
if( $map->hasAccess($user) ){
if($mapAccess){
$map->setData($formData);
$map = $map->save();
@@ -316,10 +312,13 @@ class Map extends \Controller\AccessController {
if($f3->exists($cacheKey) === false ){
$mapData = (array)$f3->get('POST.mapData');
// get current map data ========================================================
$maps = $user->getMaps();
// loop all submitted map data that should be saved
// -> currently there will only be ONE map data change submitted -> single loop
foreach($mapData as $data){
$config = $data['config'];
$systems = [];
$connections = [];
@@ -339,76 +338,73 @@ class Map extends \Controller\AccessController {
count($connections) > 0
){
$map = Model\BasicModel::getNew('MapModel');
$map->getById( (int)$config['id'] );
// map changes expected =============================================
// -> get active user object
$activeCharacter = $user->getActiveUserCharacter();
if( $map->hasAccess($user) ){
// map changes expected =============================================
// -> get active user object
$activeCharacter = $user->getActiveUserCharacter();
// empty system model for changes
$system = Model\BasicModel::getNew('SystemModel');
// empty connection model for changes
$connection = Model\BasicModel::getNew('ConnectionModel');
// clear map cache on change
$clearMapCache = false;
// loop current user maps and check for changes
foreach($maps as $map){
// update system data -----------------------------------------------
foreach($systems as $systemData){
foreach($systems as $i => $systemData){
// get object
$system->getById($systemData['id']);
// check if current system belongs to the current map
$map->filter('systems', array('id = ?', $systemData['id'] ));
$filteredMap = $map->find(
array('id = ?', $map->id ),
array('limit' => 1)
);
// check if system exists and is part of the current map (security)
if( $system->mapId->id === $map->id ){
// update
$system->setData($systemData);
$system->updatedCharacterId = $activeCharacter->characterId;
$system->save();
// this should never fail
if(is_object($filteredMap)){
$filteredMap = $filteredMap->current();
$clearMapCache = true;
// system belongs to the current map
if(is_object($filteredMap->systems)){
// update
$system = $filteredMap->systems->current();
$system->setData($systemData);
$system->updatedCharacterId = $activeCharacter->characterId;
$system->save();
// a system belongs to ONE map -> speed up for multiple maps
unset($systemData[$i]);
}
}
$system->reset();
}
// update connection data -------------------------------------------
foreach($connections as $connectionData){
// get object
$connection->getById($connectionData['id']);
foreach($connections as $i => $connectionData){
// check if object exists
if( $connection->mapId->id === $map->id ){
// update
$connectionData['mapId'] = $map;
$connection->setData($connectionData);
$connection->save($user);
// check if the current connection belongs to the current map
$map->filter('connections', array('id = ?', $connectionData['id'] ));
$filteredMap = $map->find(
array('id = ?', $map->id ),
array('limit' => 1)
);
$clearMapCache = true;
// this should never fail
if(is_object($filteredMap)){
$filteredMap = $filteredMap->current();
// connection belongs to the current map
if(is_object($filteredMap->connections)){
// update
$connection = $filteredMap->connections->current();
$connection->setData($connectionData);
$connection->save($user);
// a connection belongs to ONE map -> speed up for multiple maps
unset($connectionData[$i]);
}
}
$connection->reset();
}
}
// map data has changed -> clear map cache
if($clearMapCache){
$map->clearCacheData();
}
$map->reset();
}
}
// get map data ======================================================
$activeMaps = $user->getMaps($responseTTL);
// format map Data for return
$return->mapData = self::getFormattedMapData($activeMaps);
$return->mapData = self::getFormattedMapData($maps);
$f3->set($cacheKey, $return, $responseTTL);
}else{
@@ -432,6 +428,8 @@ class Map extends \Controller\AccessController {
$mapData = [];
foreach($mapModels as $mapModel){
//$mapModel->update();
//$mapModel->cast();
$allMapData = $mapModel->getData();
$mapData[] = [

View File

@@ -58,7 +58,16 @@ class User extends Controller\Controller{
if($user !== false){
// user is verified -> ready for login
$loginSuccess = $this->_logIn($user);
// set Session login
$dateTime = new \DateTime();
$this->f3->set('SESSION.user.time', $dateTime->getTimestamp());
$this->f3->set('SESSION.user.name', $user->name);
$this->f3->set('SESSION.user.id', $user->id);
// update/check api data
// $this->_updateCharacterData();
$loginSuccess = true;
}
return $loginSuccess;