getId() !== null ? array('id'=>$grid->getId()) : array(); return $this->formFactory->create(GridType::class, $grid, array( 'action'=>$this->router->generate($route, $params), 'method'=>'post', 'data_route'=>$route, )); } public function getGridForm(string $route, Region $region): FormInterface { return $this->formFactory->create(GridType::class, null, array( 'action'=>$this->router->generate($route, array('regionId'=>$region->getId())), 'method'=>'post', 'data_route'=>$route, )); } /** * @param Region $region * @return Grid[] */ public function getGridCells(Region $region): array { $qb=$this->_em->createQueryBuilder(); $qb->select("grid") ->from(Grid::class, "grid") ->andWhere($qb->expr()->eq("grid.region", ":param_region")) ->orderBy("grid.row") ->addOrderBy("grid.col"); $qb->setParameter('param_region', $region->getId(), Types::INTEGER); return $qb->getQuery()->getResult(); } public function buildWorldmap(float $version, array $cells, array $maps, bool $withForm=false): array { $grid=array(); /** @var Map $map */ foreach($maps as $key=>$map) { if(!($map instanceof Map)) { throw new LogicException(sprintf( 'Variable passed must be an instance of "%s". "%s" given', Map::class, gettype($map) )); } $maps["cell_{$map->getGrid()->getId()}"]=array( 'map'=>$map, 'form'=>$withForm ? $this->mapRepository->getForm('bo_map_edit', $map->getGrid(), $map)->createView() : null ); unset($maps[$key]); } /** @var Grid $cell */ foreach($cells as $cell) { if(!($cell instanceof Grid)) { throw new LogicException(sprintf( 'Variable passed must be an instance of "%s". "%s" given', Grid::class, gettype($map) )); } if(!array_key_exists("cell_{$cell->getId()}", $maps)) { $_map=new Map(); $_map->setVersion($version); $maps["cell_{$cell->getId()}"]=array( 'map'=>$_map, 'form'=>$withForm ? $this->mapRepository->getForm('bo_map_new', $cell, $_map)->createView() : null ); } $grid[$cell->getRow()][$cell->getCol()]=array( 'id'=>$cell->getId(), 'map_data'=>$maps["cell_{$cell->getId()}"], ); } return $grid; } }