mapId = $mapId; $this->jsonResponse = $jsonResponse; } public function run(): IView { $bounds = $this->getMapBounds(); if (!isset($_SESSION['state']) || $_SESSION['state']['mapId'] !== $this->mapId) { $_SESSION['state'] = [ 'mapId' => $this->mapId, 'area' => $bounds->calculateApproximateArea(), 'rounds' => [] ]; } $data = ['mapId' => $this->mapId, 'bounds' => $bounds->toArray()]; if ($this->jsonResponse) { return new JsonView($data); } else { return new HtmlView('game', $data); } } private function getMapBounds(): Bounds { $select = new Select(\Container::$dbConnection, 'maps'); $select->columns(['bound_south_lat', 'bound_west_lng', 'bound_north_lat', 'bound_east_lng']); $select->whereId($this->mapId); $map = $select->execute()->fetch(IResultSet::FETCH_ASSOC); $bounds = Bounds::createDirectly($map['bound_south_lat'], $map['bound_west_lng'], $map['bound_north_lat'], $map['bound_east_lng']); return $bounds; } }