/**
  *  issue: when the neighborhood /Region/Neighborhood is pulled for neighborhoods that
  *  have user polygons drawn but no neighborhood borders drawn, they fail
  */
 public function testNeighborhoodsWithNoBorders()
 {
     $this->initDb();
     $region = new \Whathood\Entity\Region(array('name' => 'TestRegion' . rand(0, 99999999)));
     $this->m()->regionMapper()->save($region);
     $whathoodUser = new \Whathood\Entity\WhathoodUser(array('ipAddress' => '0.0.0.0'));
     $neighborhood = new Neighborhood(array('id' => 1, 'name' => "MyTest" . $this->getTestName(), 'region' => $region));
     $userPolygon = new UserPolygon(array('polygon' => Polygon::build(array(new LineString(array(new Point(30, 40), new Point(30, 50), new Point(40, 50), new Point(30, 40)))), 4326), 'neighborhood' => $neighborhood, 'region' => $region, 'whathoodUser' => $whathoodUser));
     $this->m()->userPolygonMapper()->save($userPolygon);
     $this->dispatch(sprintf("/%s/%s", $region->getName(), $neighborhood->getName()));
     $this->assertResponseStatusCode(200);
     $this->assertControllerName('whathood\\controller\\neighborhood');
 }
Example #2
0
 /**
  * 
  * @param \Whathood\Entity\Neighborhood $testNeighborhood
  * @param \Whathood\Entity\Region $testRegion
  * @param type $sideLength
  * @return null|\Whathood\Entity\HeatMap
  * @throws \InvalidArgumentException
  */
 public function getLatestHeatMap(Neighborhood $testNeighborhood, Region $testRegion, $sideLength)
 {
     if (empty($sideLength)) {
         throw new \InvalidArgumentException('sidLength may not be null');
     }
     $testNeighborhoodName = $testNeighborhood->getName();
     $testRegionName = $testRegion->getName();
     $neighborhoodPolygons = $this->neighborhoodPolygonMapper()->getNeighborhoodByName($testNeighborhoodName, $testRegionName);
     $testPoints = $this->getBoundarySquare($neighborhoodPolygons)->getTestPoints($sideLength);
     $heatMapPoints = $this->getHeatMapPoints($testPoints, $testNeighborhoodName);
     if (count($heatMapPoints) > 0) {
         return new HeatMap(array('neighborhood' => $testNeighborhood, 'region' => $testRegion, 'heatMapPoints' => $heatMapPoints, 'neighborhoodPolygons' => new ArrayCollection($neighborhoodPolygons)));
     } else {
         return null;
     }
 }
Example #3
0
 public function save(NeighborhoodEntity $neighborhood)
 {
     if ($neighborhood->getName() == null) {
         throw new \InvalidArgumentException("neighborhood.name may" . " not be null");
     }
     /*
      * does the region already exist, if it does reset it in the neighborhood
      */
     try {
         $region = $this->regionMapper()->getRegionByName($neighborhood->getRegion()->getName());
         $neighborhood->setRegion($region);
     } catch (\Doctrine\ORM\NoResultException $e) {
     }
     if ($neighborhood->getDateTimeAdded() == null) {
         $neighborhood->setDateTimeAdded(date("Y-m-d H:i:s"));
     }
     $this->em->persist($neighborhood);
     $this->em->flush($neighborhood);
 }
 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 getName()
 {
     $this->__load();
     return parent::getName();
 }