function bindSessionEntityArray($sessionEntitys)
{
    $sessionDtos = new SessionListDto();
    $sessionDtoArray = array();
    foreach ($sessionEntitys as $sessionEntity => $value) {
        array_push($sessionDtoArray, bindSessionEntity($value));
    }
    $sessionDtos->setSessions($sessionDtoArray);
    return $sessionDtos;
}
function bindSessionServiceEntity($sessionServiceEntity)
{
    if ($sessionServiceEntity != null) {
        $sessionServiceDto = new SessionServiceDto();
        $sessionServiceDto->setSessionServiceId($sessionServiceEntity->getSessionServiceId());
        $sessionServiceDto->setSession(bindSessionEntity($sessionServiceEntity->getSession()));
        $sessionServiceDto->setService(bindServiceEntity($sessionServiceEntity->getService()));
        return $sessionServiceDto;
    } else {
        return null;
    }
}
    }
});
$app->put('/sessions/:id', function ($id) use($app) {
    global $entityManager;
    $sessionEntity = $entityManager->find("SessionEntity", $id);
    $entityManager->flush();
    $sessionDto = bindSessionEntity($sessionEntity);
    $sessionDto->printData($app);
});
$app->post('/sessions', function () use($app) {
    global $entityManager;
    $sessionDto = new SessionDto();
    $sessionDto->bindJson($app);
    $entityManager->persist($sessionEntity);
    $entityManager->flush();
    $sessionDto = bindSessionEntity($sessionEntity);
    $sessionDto->printData($app);
});
$app->delete('/sessions/:id', function ($id) use($app) {
    global $entityManager;
    $sessionEntity = $entityManager->find("SessionEntity", $id);
    $entityManager->remove($sessionEntity);
    $entityManager->flush();
});
/*Referances*/
$app->get('/sessions/:id/sessionservices', function ($id) use($app) {
    global $entityManager;
    $sessionServiceEntities = $entityManager->getRepository("SessionServiceEntity")->findBy(array('session' => $id));
    $sessionService = bindSessionServiceEntityArray($sessionServiceEntities);
    $sessionService->printData($app);
});