Private
Public Access
1
0

replace gridcol object to json array in db

This commit is contained in:
2016-11-01 13:41:30 +01:00
parent 31e3097da3
commit 2ed938f22a
4 changed files with 17 additions and 165 deletions

View File

@@ -1,96 +0,0 @@
<?php
namespace Mine\SeekerBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* GridCol
*
* @ORM\Table(name="grid_col")
* @ORM\Entity(repositoryClass="Mine\SeekerBundle\Repository\GridColRepository")
*/
class GridCol
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="col", type="string", length=1, nullable=false)
*/
private $col;
/**
* @var GridRow
*
* @ORM\ManyToOne(targetEntity="Mine\SeekerBundle\Entity\GridRow", inversedBy="gridCol", cascade={"persist"})
* @ORM\JoinColumn(name="grid_col", referencedColumnName="id", onDelete="CASCADE")
*/
private $gridCol;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set col
*
* @param integer $col
*
* @return GridCol
*/
public function setCol($col)
{
$this->col = $col;
return $this;
}
/**
* Get col
*
* @return integer
*/
public function getCol()
{
return $this->col;
}
/**
* Set gridCol
*
* @param GridRow $gridCol
*
* @return GridCol
*/
public function setGridCol(GridRow $gridCol = null)
{
$this->gridCol = $gridCol;
return $this;
}
/**
* Get gridCol
*
* @return GridRow
*/
public function getGridCol()
{
return $this->gridCol;
}
}

View File

@@ -2,7 +2,6 @@
namespace Mine\SeekerBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
@@ -31,20 +30,12 @@ class GridRow
private $grid;
/**
* @var GridCol
* @var array
*
* @ORM\OneToMany(targetEntity="Mine\SeekerBundle\Entity\GridCol", mappedBy="gridCol", cascade={"persist"})
* @ORM\JoinColumn(name="grid_row", referencedColumnName="id", onDelete="CASCADE")
* @ORM\Column(name="grid_col", type="json_array", nullable=false)
*/
private $gridCol;
/**
* Constructor
*/
public function __construct()
{
$this->gridCol = new ArrayCollection();
}
/**
* Get id
@@ -57,33 +48,23 @@ class GridRow
}
/**
* Add gridCol
* Set gridCol
*
* @param GridCol $gridCol
* @param array $gridCol
*
* @return GridRow
*/
public function addGridCol(GridCol $gridCol)
public function setGridCol($gridCol)
{
$this->gridCol[] = $gridCol;
$this->gridCol = $gridCol;
return $this;
}
/**
* Remove gridCol
*
* @param GridCol $gridCol
*/
public function removeGridCol(GridCol $gridCol)
{
$this->gridCol->removeElement($gridCol);
}
/**
* Get gridCol
*
* @return \Doctrine\Common\Collections\Collection
* @return array
*/
public function getGridCol()
{

View File

@@ -2,7 +2,6 @@
namespace Mine\SeekerBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
@@ -31,20 +30,12 @@ class GridRow
private $grid;
/**
* @var GridCol
* @var array
*
* @ORM\OneToMany(targetEntity="Mine\SeekerBundle\Entity\GridCol", mappedBy="gridCol", cascade={"persist"})
* @ORM\JoinColumn(name="grid_row", referencedColumnName="id", onDelete="CASCADE")
* @ORM\Column(name="grid_col", type="json_array", nullable=false)
*/
private $gridCol;
/**
* Constructor
*/
public function __construct()
{
$this->gridCol = new ArrayCollection();
}
/**
* Get id
@@ -57,33 +48,23 @@ class GridRow
}
/**
* Add gridCol
* Set gridCol
*
* @param GridCol $gridCol
* @param array $gridCol
*
* @return GridRow
*/
public function addGridCol(GridCol $gridCol)
public function setGridCol($gridCol)
{
$this->gridCol[] = $gridCol;
$this->gridCol = $gridCol;
return $this;
}
/**
* Remove gridCol
*
* @param GridCol $gridCol
*/
public function removeGridCol(GridCol $gridCol)
{
$this->gridCol->removeElement($gridCol);
}
/**
* Get gridCol
*
* @return \Doctrine\Common\Collections\Collection
* @return array
*/
public function getGridCol()
{

View File

@@ -56,7 +56,7 @@ class MineseekerRpc implements RpcInterface
*/
public function connectGame(ConnectionInterface $connection, WampRequest $request, array $params)
{
return base64_encode(json_encode($this->getGrid($params), JSON_NUMERIC_CHECK));
return base64_encode(json_encode($this->getGrid($params)));
}
/**
@@ -75,13 +75,7 @@ class MineseekerRpc implements RpcInterface
->getGrid();
foreach ($grid->getGridRow()->toArray() as $row) {
$bazmeg = array();
foreach ($row->getGridCol()->toArray() as $col) {
$bazmeg[] = $col->getCol();
}
$getsee[] = $bazmeg;
$getsee[] = $row->getGridCol();
}
return $getsee;
@@ -99,15 +93,7 @@ class MineseekerRpc implements RpcInterface
foreach (json_decode(base64_decode($data[0])) as $row) {
$gridRow = new GridRow();
foreach ($row as $col) {
$gridCol = new GridCol();
$gridCol->setCol($col);
/** Save Col */
$gridCol->setGridCol($gridRow);
$this->em->persist($gridCol);
}
$gridRow->setGridCol($row);
/** Save Row */
$gridRow->setGrid($grid);