/**
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function indexAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $params = $request->get('search');
     $vertical = NULL;
     /* SEO */
     $url_parsed = parse_url($request->getUri());
     $url_path = $url_parsed['path'];
     if (isset($url_parsed['query'])) {
         $url_path .= '?' . $url_parsed['query'];
     }
     $post_parameters = $this->getPostParameters($request);
     $adSearchUrl = $this->get('rmc_core.ad_search_url_service');
     $adSearchUrl->parseUrl($url_path, $post_parameters);
     $urlFilters = $adSearchUrl->getFilters();
     $niceUrl = $adSearchUrl->getNiceUrlByFilters($urlFilters);
     $filters = $adSearchUrl->getNiceFilters();
     // redirect to smart url
     if ($adSearchUrl->is302 && $niceUrl != '/') {
         return $this->redirect($this->container->get('kernel')->getEnvironment() == 'dev' ? '/app_dev.php' . $niceUrl : $niceUrl);
     }
     //print_r($filters);exit;
     //echo 'NICE URL '.$adSearchUrl->getNiceUrlAdding(array('category1' => 2), $filters);
     if (isset($filters['vertical'])) {
         $vertical = $em->getRepository('Entity:Vertical')->find($filters['vertical']);
     }
     $searchManager = AdSearchFactory::getSearchManager($this->container, $vertical ? $vertical->getCode() : '');
     // choose based on search parameter otherwise use 'Ad'
     $filters['select'] = array('id');
     $filters['facet'] = true;
     // display the total number of documents found by solr
     $query = $searchManager->getSolrSearchService()->getQueryByCriteria($filters, NULL, true);
     $solrRegistry = $this->get('solarium.client_registry');
     $client = $solrRegistry->getClient('rmcslave');
     $pager = array($client, $query);
     $paginator = $this->get('knp_paginator');
     $resultset = $paginator->paginate($pager, $request->get('page', 1), $request->get('page_range', 10));
     $resultsetFacet = $resultset->getCustomParameter('result');
     $documents = $resultset->getItems();
     $data = $resultset->getPaginationData();
     $facets = $searchManager->getSolrSearchService()->getFacetFields($resultsetFacet);
     $facetBuilder = new AdSearchFacetBulderService($this->getDoctrine()->getManager(), $facets, $adSearchUrl);
     $niceFacets = $facetBuilder->getNiceFacets();
     //print_r($niceFacets);exit;
     //echo $documents->getTotalItemCount();exit;
     //echo 'NumFound: '.$resultset->getNumFound();exit;
     /*
             foreach ($documents as $doc)
             {
                 echo 'ID '.$doc->id."<br />";
             }*/
     $ids = RmcHelpers::getPrimaryKeys($documents);
     $ads = $em->getRepository('Entity:Ad')->findById($ids);
     $noLayout = $request->headers->get('X-PJAX') ? true : false;
     if ($noLayout) {
         return $this->render('RmcCoreAdSearchBundle:Default:pjaxIndex.html.twig', array('ads' => $ads, 'documents' => $documents, 'paginator' => $resultset, 'facetFields' => $niceFacets, 'noLayout' => $noLayout));
     } else {
         return $this->render('RmcCoreAdSearchBundle:Default:index.html.twig', array('ads' => $ads, 'documents' => $documents, 'paginator' => $resultset, 'facetFields' => $niceFacets, 'noLayout' => $noLayout));
     }
 }
 /**
  * Action used to create existing user page
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function adListAction(Request $request)
 {
     $container = $this->container;
     $userManager = $container->get('rmc_core_user.user_manager');
     $user = $userManager->findOneById($request->get('id'));
     $searchManager = AdSearchFactory::getSearchManager($this->container, '');
     $filters['userId'] = $user;
     $query = $searchManager->getSqlSearchService()->getQueryByCriteria($filters, NULL, true);
     $page = $request->query->get('page', 1);
     $paginator = $this->get('knp_paginator');
     $pagination = $paginator->paginate($query, $page, $this->get('request')->query->get('page_range', $container->getParameter('page_range')));
     $htmlOpt = array('title' => array('title' => $this->get('translator')->trans('Sort list by user titles.')), 'created_at' => array('create' => $this->get('translator')->trans('Sort list by creation date of the page.')), 'updated_at' => array('update' => $this->get('translator')->trans('Sort list by update date of the page.')));
     $sortCol = $request->get('sort', \Entity\Ad::ALIAS . '.publishedAt');
     $sortOrder = $request->get('direction', 'desc');
     return $this->render('RmcCoreUserBundle:Admin:adlist.html.twig', array('ad' => $pagination, 'htmlOpt' => $htmlOpt, 'adAlias' => \Entity\Ad::ALIAS, 'sortCol' => $sortCol, 'sortOrder' => $sortOrder));
 }