Example #1
0
 public function indexAction()
 {
     $queryString = $this->getUriParameter('q');
     /*
      * get regions
      */
     try {
         $regions = $this->m()->regionMapper()->nameLike($queryString);
     } catch (\Doctrine\ORM\NoResultException $e) {
         $regions = array();
     }
     try {
         $neighborhoods = $this->m()->neighborhoodMapper()->nameLike($queryString);
     } catch (\Doctrine\ORM\NoResultException $e) {
         $neighborhoods = array();
     }
     $this->logger()->info("neighbordhood/region search for '{$queryString}'");
     $this->pushEmailJob(\Whathood\View\MailMessageBuilder::buildSomeoneSearched($queryString));
     return new ViewModel(array('queryString' => $queryString, 'regions' => $regions, 'neighborhoods' => $neighborhoods));
 }
 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()));
 }