Exemple #1
0
 /**
  * @FW\Route("/{slug}/map", name="location_map", options={"expose"=true})
  * @FW\Template()          
  */
 public function locationMapAction(City $city)
 {
     $elasticaManager = $this->container->get('fos_elastica.manager');
     $em = $this->getDoctrine()->getManager();
     $placeFilter = new PlaceFilter();
     $placeFilter->setAggregations(['categories']);
     $placeFilter->setCity($city);
     $places = $elasticaManager->getRepository(Place::class)->facet($placeFilter);
     $filterFacet = $places->getAdapter()->getAggregations();
     $placeCategories = $em->getRepository(Category::class)->getCategoriesByType(CategoryType::PLACE);
     return ['placeCategories' => $placeCategories, 'filterFacet' => $filterFacet, 'city' => $city];
 }
Exemple #2
0
 /**
  * @FW\Route("{city_slug}/places/{category_slug}", name="places_list")     
  * @FW\ParamConverter("city", class="KromboxMainBundle:City", options={"mapping": {"city_slug": "slug"}})          
  * @FW\ParamConverter("category", class="KromboxMainBundle:Category", options={"mapping": {"category_slug": "slug"}})
  * @FW\Template        
  */
 public function listAction(Request $request, \Krombox\MainBundle\Entity\City $city, \Krombox\MainBundle\Entity\Category $category)
 {
     $placeFilter = new PlaceFilter();
     //$placeFilter = new PlaceFilter();
     $placeFilter->setCategory($category);
     $placeFilter->setCity($city);
     $elasticaManager = $this->container->get('fos_elastica.manager');
     $sort = 'membership';
     $page = '1';
     $filterForm = $this->get('form.factory')->createNamed('', 'place_filter', $placeFilter, array('action' => $this->generateUrl('places_list', ['city_slug' => $city->getSlug(), 'category_slug' => $category->getSlug()]), 'method' => 'GET'));
     $filterForm->handleRequest($request);
     if ($request->query->has('sort')) {
         $sortParam = $request->query->get('sort');
         if (in_array($sortParam, ['membership', 'rating', 'views'])) {
             $sort = $sortParam;
         }
     }
     if ($request->query->has('page')) {
         $page = $request->query->get('page');
     }
     //var_dump($sort);die();
     $places = $elasticaManager->getRepository(Place::class)->facet($placeFilter, $sort);
     $places->setMaxPerPage(3);
     $places->setCurrentPage($request->query->get('page', 1));
     $filterFacet = $places->getAdapter()->getAggregations();
     //var_dump($filterFacet);die();
     //$filterFacet['businessHours']['buckets'][] = ['key' => 'workingNow', 'doc_count' => 5];
     //var_dump($filterFacet);die();
     $helper = $this->container->get('krombox.business_hours_helper');
     //        if($placeFilter->getBusinessHours()){
     //            echo 'here';
     //            /*TODO make external helper*/
     //            foreach($places as $key => $place){
     //                if(!$helper->isWorkingNow($place)){
     //                    var_dump($places);die();
     //                    unset($places[$key]);
     //                }
     //            }
     //        }
     if ($request->isXmlHttpRequest()) {
         return $this->render('KromboxMainBundle:Place/partial:placesList.html.twig', array('places' => $places, 'filterForm' => $filterForm->createView(), 'filterFacet' => $filterFacet, 'sort' => $sort));
     }
     //var_dump($filterFacet);
     return $this->render('KromboxMainBundle:Place:list.html.twig', array('places' => $places, 'filterForm' => $filterForm->createView(), 'filterFacet' => $filterFacet, 'sort' => $sort));
 }