public function setGeoJson($geojson) { $polygon = \Whathood\Polygon::buildPolygonFromGeoJsonString($geojson, 4326); $this->setGeometry($polygon); }
public function addAction() { if (!$this->getRequest()->isPost()) { return new ViewModel(); } $neighborhood_name = $this->getRequest()->getPost('neighborhood_name'); $region_name = $this->getRequest()->getPost('region_name'); $polygon_array = $this->getRequest()->getPost('polygon_json'); if (empty($polygon_array)) { throw new \InvalidArgumentException("polygon_json may not be empty"); } if (empty($neighborhood_name)) { throw new \InvalidArgumentException("neighborhood_name may not be empty"); } $neighborhood = new Neighborhood(array('name' => $neighborhood_name)); $region = new Region(array('name' => $region_name)); $polygon = \Whathood\Polygon::buildPolygonFromGeoJsonArray($polygon_array, $srid = 4326); $whathoodUser = $this->getWhathoodUser(); $userPolygon = new UserPolygon(array('neighborhood' => $neighborhood, 'polygon' => $polygon, 'region' => $region, 'whathoodUser' => $whathoodUser)); $this->logger()->info(sprintf("saving user-polygon id=%s neighborhood=%s region=%s ip-address=%s", $userPolygon->getId(), $neighborhood->getName(), $region->getName(), $whathoodUser->getIpAddress())); $this->userPolygonMapper()->save($userPolygon); $this->logger()->info("user polygon added id(" . $userPolygon->getId() . ")"); return new JsonModel(array('status' => 'success', 'user_polygon_id' => $userPolygon->getId())); }
public function addPostAction() { if (!$this->getRequest()->isPost()) { throw new \Exception("addPostAction expects a POST"); } $neighborhood_name = $this->getRequest()->getPost('neighborhood_name'); $region_name = $this->getRequest()->getPost('region_name'); $polygon_array = $this->getRequest()->getPost('polygon_json'); if (empty($polygon_array)) { throw new \InvalidArgumentException("polygon_json may not be empty"); } if (empty($neighborhood_name)) { throw new \InvalidArgumentException("neighborhood_name may not be empty"); } $polygon = \Whathood\Polygon::buildPolygonFromGeoJsonArray($polygon_array, $srid = 4326); $whathoodUser = $this->getWhathoodUser(); $userPolygon = new UserPolygon(array('neighborhood' => new Neighborhood(array('name' => $neighborhood_name)), 'polygon' => $polygon, 'region' => new Region(array('name' => $region_name)), 'whathoodUser' => $whathoodUser)); $this->m()->userPolygonMapper()->save($userPolygon); $this->logger()->info(sprintf("saved user-polygon id=%s neighborhood=%s(%s) region=%s ip-address=%s", $userPolygon->getId(), $userPolygon->getNeighborhood()->getName(), $userPolygon->getNeighborhood()->getId(), $userPolygon->getRegion()->getName(), $whathoodUser->getIpAddress())); $this->messageQueue()->push('Whathood\\Job\\NeighborhoodBorderBuilderJob', array('neighborhood_id' => $userPolygon->getNeighborhood()->getId())); $this->pushEmailJob(\Whathood\View\MailMessageBuilder::buildNewUserPolygon($userPolygon)); return new JsonModel(array('status' => 'success', 'user_polygon_id' => $userPolygon->getId())); }