From 2ed938f22aca778d3e24fc9f388c04d24aa2ee88 Mon Sep 17 00:00:00 2001 From: Lang Date: Tue, 1 Nov 2016 13:41:30 +0100 Subject: [PATCH] replace gridcol object to json array in db --- src/Mine/SeekerBundle/Entity/GridCol.php | 96 --------------------- src/Mine/SeekerBundle/Entity/GridRow.php | 33 ++----- src/Mine/SeekerBundle/Entity/GridRow.php~ | 33 ++----- src/Mine/SeekerBundle/Rpc/MineseekerRpc.php | 20 +---- 4 files changed, 17 insertions(+), 165 deletions(-) delete mode 100644 src/Mine/SeekerBundle/Entity/GridCol.php diff --git a/src/Mine/SeekerBundle/Entity/GridCol.php b/src/Mine/SeekerBundle/Entity/GridCol.php deleted file mode 100644 index 0f052a7..0000000 --- a/src/Mine/SeekerBundle/Entity/GridCol.php +++ /dev/null @@ -1,96 +0,0 @@ -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; - } -} diff --git a/src/Mine/SeekerBundle/Entity/GridRow.php b/src/Mine/SeekerBundle/Entity/GridRow.php index 651036a..cd2769d 100644 --- a/src/Mine/SeekerBundle/Entity/GridRow.php +++ b/src/Mine/SeekerBundle/Entity/GridRow.php @@ -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() { diff --git a/src/Mine/SeekerBundle/Entity/GridRow.php~ b/src/Mine/SeekerBundle/Entity/GridRow.php~ index 651036a..cd2769d 100644 --- a/src/Mine/SeekerBundle/Entity/GridRow.php~ +++ b/src/Mine/SeekerBundle/Entity/GridRow.php~ @@ -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() { diff --git a/src/Mine/SeekerBundle/Rpc/MineseekerRpc.php b/src/Mine/SeekerBundle/Rpc/MineseekerRpc.php index e7ba0c0..88fcc26 100644 --- a/src/Mine/SeekerBundle/Rpc/MineseekerRpc.php +++ b/src/Mine/SeekerBundle/Rpc/MineseekerRpc.php @@ -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);