/**
  * Show edit history of an object
  * Required REQUEST parameters are:
  *     objectId - int
  *     objectClass - base64_encoded fully qualified class name
  *
  * @param Request $request
  * @return \HealthCareAbroad\AdminBundle\Controller\Response
  * @author Allejo Chris G. Velarde
  */
 public function showEditHistoryAction(Request $request)
 {
     $objectId = $request->get('objectId', null);
     $objectClass = $request->get('objectClass', null);
     if ($objectId === null || $objectClass === null) {
         return new Response("objectId and objectClass are required parameters", 400);
     }
     $objectClass = \base64_decode($objectClass);
     if (!\class_exists($objectClass)) {
         throw $this->createNotFoundException("Cannot view history of invalid class {$objectClass}");
     }
     $this->userService = $this->get('services.twig_user');
     $this->historyService = $this->get('services.log.entity_version');
     $filters = array('objectId' => $objectId, 'objectClass' => $objectClass);
     $qb = $this->getDoctrine()->getRepository('LogBundle:VersionEntry')->getQueryBuilderForFindAll($filters);
     $adapter = new DoctrineOrmAdapter($qb, Query::HYDRATE_ARRAY);
     $pager = new Pager($adapter);
     $pager->setLimit(50);
     $pager->setPage($request->get('page', 1));
     foreach ($pager->getResults() as $versionEntry) {
         $entries[] = $this->buildViewDataOfVersionEntry($versionEntry);
     }
     $response = $this->render('AdminBundle:EntityHistory:editHistory.html.twig', array('entries' => $entries, 'pager' => $pager, 'objectId' => $objectId, 'objectClass' => $objectClass));
     return $response;
 }
 public function indexAction(Request $request)
 {
     $searchTerm = \trim($request->get('q', ''));
     $page = $request->get('page', 1);
     $qb = $this->getDoctrine()->getEntityManager()->createQueryBuilder()->select('a, b')->from('TermBundle:Term', 'a')->innerJoin('a.termDocuments', 'b')->orderBy('a.name');
     if ('' != $searchTerm) {
         $qb->where('a.name LIKE :searchQuery')->setParameter('searchQuery', '%' . $searchTerm . '%');
     }
     $pager = new Pager(new DoctrineOrmAdapter($qb));
     $pager->setLimit('25');
     $pager->setPage($page);
     $data = array('pager' => $pager);
     return $this->render('AdminBundle:Terms:index.html.twig', $data);
 }
 /**
  * Mimic frontend search process and get results for ranking management
  * 
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  * @author acgvelarde
  */
 public function processSearchAction(Request $request)
 {
     $searchParameterService = $this->get('services.search.parameters');
     $compiledSearch = $searchParameterService->compileRequest($request);
     $searchStateLabel = SearchStates::getSearchStateFromValue($compiledSearch->getSearchState());
     $searchVariables = $compiledSearch->getVariables();
     $searchService = $this->get('services.search');
     // flag on what ranking point the search service is using
     $isUsingInstitutionRankingPoints = false;
     switch ($searchStateLabel) {
         // treatments only search
         case SearchStates::SPECIALIZATION_SEARCH:
             $specialization = $searchVariables[SearchParameterService::PARAMETER_KEY_SPECIALIZATION_ID];
             $results = $searchService->searchBySpecialization($specialization);
             $isUsingInstitutionRankingPoints = false;
             // uses clinic ranking points
             break;
         case SearchStates::SUB_SPECIALIZATION_SEARCH:
             $subSpecialization = $searchVariables[SearchParameterService::PARAMETER_KEY_SUB_SPECIALIZATION_ID];
             $results = $searchService->searchBySubSpecialization($subSpecialization);
             $isUsingInstitutionRankingPoints = false;
             // uses clinic ranking points
             break;
         case SearchStates::TREATMENT_SEARCH:
             $isUsingInstitutionRankingPoints = false;
             // uses clinic ranking points
             $treatment = $searchVariables[SearchParameterService::PARAMETER_KEY_TREATMENT_ID];
             $results = $searchService->searchByTreatment($treatment);
             break;
             // destinations only search
         // destinations only search
         case SearchStates::COUNTRY_SEARCH:
             $isUsingInstitutionRankingPoints = true;
             // uses hospital ranking points
             $country = $searchVariables[SearchParameterService::PARAMETER_KEY_COUNTRY_ID];
             $results = $searchService->searchByCountry($country);
             break;
         case SearchStates::CITY_SEARCH:
             $city = $searchVariables[SearchParameterService::PARAMETER_KEY_CITY_ID];
             $results = $searchService->searchByCity($city);
             $isUsingInstitutionRankingPoints = true;
             // uses hospital ranking points
             break;
             // combination search
         // combination search
         case SearchStates::COUNTRY_SPECIALIZATION_SEARCH:
             $isUsingInstitutionRankingPoints = false;
             $specialization = $searchVariables[SearchParameterService::PARAMETER_KEY_SPECIALIZATION_ID];
             $country = $searchVariables[SearchParameterService::PARAMETER_KEY_COUNTRY_ID];
             $results = $this->getDoctrine()->getManager()->getRepository('TermBundle:SearchTerm')->findByFilters(array($specialization, $country));
             break;
         case SearchStates::COUNTRY_SUB_SPECIALIZATION_SEARCH:
             $isUsingInstitutionRankingPoints = false;
             $subSpecialization = $searchVariables[SearchParameterService::PARAMETER_KEY_SUB_SPECIALIZATION_ID];
             $country = $searchVariables[SearchParameterService::PARAMETER_KEY_COUNTRY_ID];
             $results = $this->getDoctrine()->getManager()->getRepository('TermBundle:SearchTerm')->findByFilters(array($subSpecialization, $country));
             break;
         case SearchStates::COUNTRY_TREATMENT_SEARCH:
             $isUsingInstitutionRankingPoints = false;
             $treatment = $searchVariables[SearchParameterService::PARAMETER_KEY_TREATMENT_ID];
             $country = $searchVariables[SearchParameterService::PARAMETER_KEY_COUNTRY_ID];
             $results = $this->getDoctrine()->getManager()->getRepository('TermBundle:SearchTerm')->findByFilters(array($treatment, $country));
             break;
         case SearchStates::CITY_SPECIALIZATION_SEARCH:
             $isUsingInstitutionRankingPoints = false;
             $city = $searchVariables[SearchParameterService::PARAMETER_KEY_CITY_ID];
             $specialization = $searchVariables[SearchParameterService::PARAMETER_KEY_SPECIALIZATION_ID];
             $results = $this->getDoctrine()->getManager()->getRepository('TermBundle:SearchTerm')->findByFilters(array($specialization, $city));
             break;
         case SearchStates::CITY_SUB_SPECIALIZATION_SEARCH:
             $isUsingInstitutionRankingPoints = false;
             $subSpecialization = $searchVariables[SearchParameterService::PARAMETER_KEY_SUB_SPECIALIZATION_ID];
             $city = $searchVariables[SearchParameterService::PARAMETER_KEY_CITY_ID];
             $results = $this->getDoctrine()->getManager()->getRepository('TermBundle:SearchTerm')->findByFilters(array($subSpecialization, $city));
             break;
         case SearchStates::CITY_TREATMENT_SEARCH:
             $isUsingInstitutionRankingPoints = false;
             $city = $searchVariables[SearchParameterService::PARAMETER_KEY_CITY_ID];
             $treatment = $searchVariables[SearchParameterService::PARAMETER_KEY_TREATMENT_ID];
             $results = $this->getDoctrine()->getManager()->getRepository('TermBundle:SearchTerm')->findByFilters(array($treatment, $city));
             break;
     }
     //TODO: for now, we only need the first page for ranking purposes
     $pagerAdapter = new ArrayAdapter($results);
     $pager = new Pager($pagerAdapter, array('page' => 1, 'limit' => 20));
     // we compose the response data
     $responseData = array('results' => array(), 'totalNumberOfResults' => \count($results), 'searchState' => $searchStateLabel);
     foreach ($pager->getResults() as $searchTerm) {
         if ($searchTerm instanceof SearchTerm) {
             $institution = $searchTerm->getInstitution();
             $institutionMedicalCenter = $searchTerm->getInstitutionMedicalCenter();
             $arr = array('institution' => array('id' => $institution->getId(), 'name' => $institution->getName(), 'totalClinicRankingPoints' => $institution->getTotalClinicRankingPoints() ? $institution->getTotalClinicRankingPoints() : 0), 'institutionMedicalCenter' => array('id' => $institutionMedicalCenter->getId(), 'name' => $institutionMedicalCenter->getName(), 'rankingPoints' => $institutionMedicalCenter->getRankingPoints() ? $institutionMedicalCenter->getRankingPoints() : 0));
             $arr['isUsingInstitutionRankingPoints'] = $isUsingInstitutionRankingPoints;
             $arr['rankingPoints'] = $isUsingInstitutionRankingPoints ? $arr['institution']['totalClinicRankingPoints'] : $arr['institutionMedicalCenter']['rankingPoints'];
             $responseData['results'][] = $arr;
         }
     }
     return new Response(\json_encode($responseData), 200, array('content-type' => 'application/json'));
 }
 public function listCityTreatmentAction(Request $request)
 {
     $parameters = $request->attributes->get('_route_params');
     $em = $this->getDoctrine()->getManager();
     if (!($city = $em->getRepository('HelperBundle:City')->find(isset($parameters['cityId']) ? $parameters['cityId'] : $parameters['city']))) {
         throw new NotFoundHttpException();
     }
     if (!($treatment = $em->getRepository('TreatmentBundle:Treatment')->find(isset($parameters['treatmentId']) ? $parameters['treatmentId'] : $parameters['treatment']))) {
         throw new NotFoundHttpException();
     }
     //$pagerAdapter = new ArrayAdapter($em->getRepository('InstitutionBundle:InstitutionMedicalCenter')->getMedicalCentersByTreatmentAndCity($treatment, $city));
     $pagerAdapter = new ArrayAdapter($em->getRepository('TermBundle:SearchTerm')->findByFilters(array($treatment, $city)));
     $pager = new Pager($pagerAdapter, array('page' => $request->get('page'), 'limit' => $this->resultsPerPage));
     // set total results for page metas
     $request->attributes->set('pageMetaVariables', array(PageMetaConfigurationService::CLINIC_RESULTS_COUNT_VARIABLE => $pager->getTotalResults()));
     $request->attributes->set('searchObjects', array(SearchUrlGenerator::SEARCH_URL_PARAMETER_SPECIALIZATION => $treatment->getSpecialization(), SearchUrlGenerator::SEARCH_URL_PARAMETER_TREATMENT => $treatment, SearchUrlGenerator::SEARCH_URL_PARAMETER_COUNTRY => $city->getCountry(), SearchUrlGenerator::SEARCH_URL_PARAMETER_CITY => $city));
     $this->setBreadcrumbRequestAttributes($request, array('country' => $city->getCountry(), 'city' => $city, 'specialization' => $treatment->getSpecialization(), 'treatment' => $treatment));
     $response = $this->render('SearchBundle:Frontend:resultsCombination.html.twig', array('searchResults' => $pager, 'searchLabel' => array('treatment' => $treatment->getName(), 'destination' => $city->getName() . ', ' . $city->getCountry()->getName()), 'treatment' => $treatment, 'city' => $city, 'includedNarrowSearchWidgets' => array(), 'featuredClinicParams' => array('cityId' => $city->getId(), 'treatmentId' => $treatment->getId())));
     $response->headers->setCookie($this->buildCookie(array('countryId' => $city->getCountry()->getId(), 'cityId' => $city->getId(), 'specializationId' => $treatment->getSpecialization()->getId(), 'treatmentId' => $treatment->getId())));
     return $this->setResponseHeaders($response);
 }
 /**
  * @author Chaztine Blance
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function viewInstitutionDoctorsAction(Request $request)
 {
     $pagerAdapter = new DoctrineOrmAdapter($this->getDoctrine()->getRepository('DoctorBundle:Doctor')->getAllDoctorsByInstitution($this->institution));
     $pagerParams = array('page' => $request->get('page', 1), 'limit' => 20);
     $pager = new Pager($pagerAdapter, $pagerParams);
     return $this->render('AdminBundle:Institution:viewInstitutionDoctors.html.twig', array('institutionDoctors' => $pager->getResults(), 'pager' => $pager, 'institution' => $this->institution));
 }
 public function testIsNotPaginable()
 {
     $this->pager->setLimit(100);
     $this->assertEquals(false, $this->pager->isPaginable());
 }
 public function searchResultsRelatedAction(Request $request)
 {
     $searchTerms = json_decode($request->getSession()->remove('search_terms'), true);
     $paginationParameters = array('tag' => $request->get('tag', ''));
     $context = SearchParameterBag::SEARCH_TYPE_TREATMENTS;
     if ($request->get('country', '')) {
         $paginationParameters['country'] = $request->get('country', '');
         $context = SearchParameterBag::SEARCH_TYPE_COMBINATION;
     }
     if ($request->get('city', '')) {
         $paginationParameters['city'] = $request->get('city', '');
         $context = SearchParameterBag::SEARCH_TYPE_COMBINATION;
     }
     if (empty($searchTerms)) {
         // If session does not exist the tag can either be a partially or fully formed slug
         $filters = array('treatmentSlug' => $request->get('tag', ''));
         // We can be sure that the slugs for destination are the fully-formed one
         // as we are only allowing destination searches if the id is used.
         if ($countrySlug = $request->get('country', '')) {
             if (!($country = $this->getDoctrine()->getRepository('HelperBundle:Country')->getCountry($countrySlug))) {
                 throw new NotFoundHttpException();
             }
             $filters['countryId'] = $country->getId();
         }
         if ($citySlug = $request->get('city', '')) {
             if (!($city = $this->getDoctrine()->getRepository('HelperBundle:City')->getCity($citySlug))) {
                 throw new NotFoundHttpException();
             }
             $filters['countryId'] = $city->getCountry()->getId();
             $filters['cityId'] = $city->getId();
         }
         $searchTerms = $this->get('services.search')->getSearchTermsWithUniqueDocumentsFilteredOn($filters);
         if (empty($searchTerms)) {
             return $this->render('SearchBundle:Frontend:noResults.html.twig', array('searchLabel' => $request->get('tag', ''), 'specializations' => $this->getDoctrine()->getRepository('TermBundle:SearchTerm')->findAllActiveTermsGroupedBySpecialization()));
         }
         $termIds = array();
         foreach ($searchTerms as $term) {
             $termIds[] = (int) $term['term_id'];
         }
         $uniqueTermIds = array_flip(array_flip($termIds));
         $routeConfig = $this->get('services.search')->getRouteConfigFromFilters($filters, $this->getDoctrine(), $uniqueTermIds);
         //$paginationParameters = $routeConfig['routeParameters'];
         $searchTerms = $routeConfig['sessionParameters'];
         //$request->getSession()->set('search_terms', json_encode($searchTerms));
     }
     //FIXME: we just show Home -> Related Search for now
     //$this->setBreadcrumbRequestAttributesForRelatedSearch($request, $searchTerms);
     //TODO: This is temporary; use OrmAdapter
     $adapter = new ArrayAdapter($this->get('services.search')->searchByTerms($searchTerms));
     $searchResults = new Pager($adapter, array('page' => $request->get('page'), 'limit' => $this->resultsPerPage));
     if ($searchResults->count()) {
         $response = $this->render('SearchBundle:Frontend:resultsSectioned.html.twig', array('searchResults' => $searchResults, 'searchLabel' => $request->get('tag', ''), 'routeName' => $request->attributes->get('_route'), 'paginationParameters' => $paginationParameters, 'relatedTreatments' => $this->get('services.search')->getRelatedTreatments($searchTerms)));
         $response = $this->setResponseHeaders($response);
     } else {
         $response = $this->render('SearchBundle:Frontend:noResults.html.twig', array('searchResults' => $searchResults, 'searchLabel' => $request->get('tag', ''), 'specializations' => $this->getDoctrine()->getRepository('TermBundle:SearchTerm')->findAllActiveTermsGroupedBySpecialization()));
     }
     return $response;
 }