Private
Public Access
1
0

save the step data to db

This commit is contained in:
2016-11-01 12:38:46 +01:00
parent 6bfb08b21c
commit 311e966c89

View File

@@ -8,6 +8,7 @@ use Gos\Bundle\WebSocketBundle\Topic\TopicInterface;
use Gos\Bundle\WebSocketBundle\Router\WampRequest;
use Guzzle\Http\Message\Request;
use Mine\SeekerBundle\Entity\Gamer;
use Mine\SeekerBundle\Entity\Step;
use Ratchet\ConnectionInterface;
use Ratchet\Wamp\Topic;
use Symfony\Component\HttpFoundation\RequestStack;
@@ -55,6 +56,7 @@ class MineseekerTopic implements TopicInterface
if ($topic->count() > 2) {
$topic->remove($connection);
} else {
/** @var $users array Save users to database */
$users = $this->saveUserToDb($topic, $userName, $user, $topic->count());
$topic->broadcast([
@@ -99,6 +101,9 @@ class MineseekerTopic implements TopicInterface
$user = $this->clientManipulator->getClient($connection);
$userName = is_string($user) ? $user : $user->getUsername();
/** Save every step by user to db */
$this->saveStepToDb($topic, $event);
$topic->broadcast([
'userTopicId' => $connection->resourceId,
'channel' => $topic->getId(),
@@ -117,6 +122,36 @@ class MineseekerTopic implements TopicInterface
return 'mineseeker.topic';
}
/**
* @param $topic
* @param $event
*/
private function saveStepToDb($topic, $event)
{
$gameAssoc = explode('/', $topic->getId())[2];
$playedGame = $this->em
->getRepository('MineSeekerBundle:PlayedGame')
->findOneByGameAssoc($gameAssoc);
$step = new Step();
$step->setRow($event['coords'][0]);
$step->setCol($event['coords'][1]);
$step->setWBomb($event['bomb']);
$step->setPlayedGame($playedGame);
$this->em->persist($step);
$this->em->flush();
}
/**
* @param $topic
* @param $userName
* @param $user
* @param $count
* @return array
*/
private function saveUserToDb($topic, $userName, $user, $count)
{
$gameAssoc = explode('/', $topic->getId())[2];