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()));
 }
示例#2
0
 public function area(UserPolygon $up)
 {
     $sql = "SELECT ST_Area(polygon) AS area FROM user_polygon up WHERE up.id = :up_id";
     $rsm = new ResultSetMapping();
     $rsm->addScalarResult('area', 'area');
     $query = $this->em->createNativeQuery($sql, $rsm);
     $result = $query->setParameter('up_id', $up->getId())->getSingleResult();
     return $result['area'];
 }
示例#3
0
 public static function neighborhoodAdd(UserPolygon $np)
 {
     return 'A new neighborhood polygon has been added<br/><br/>' . '<a href="http://whathood.in/n/id/' . $np->getId() . '">Go to neighborhood</a>';
 }