public function testResults()
 {
     $this->assertEquals(true, $this->pager->hasResults());
     $this->adapter->expects($this->any())->method('getResults')->with($this->equalTo(40), $this->equalTo(40));
     $this->pager->setPage(2)->setLimit(40);
     $this->pager->getResults();
 }
 /**
  * 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;
 }
 /**
  * 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'));
 }
 /**
  * @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));
 }