public function uploadFeaturedImageAction() { $data = array('status' => false); if ($this->getRequest()->files->get('featuredImage')) { $file = $this->getRequest()->files->get('featuredImage'); $media = $this->get('services.institution.media')->uploadFeaturedImage($file, $this->institution); if ($media->getName()) { $imageSize = ImageSizes::LARGE_BANNER; if ($this->getRequest()->get('logoSize') == ImageSizes::SMALL) { $imageSize = ImageSizes::SMALL; } $src = $this->get('services.institution')->mediaTwigExtension->getInstitutionMediaSrc($media->getName(), $imageSize); $data['mediaSrc'] = $src; // Invalidate InstitutionProfile memcache $this->get('services.memcache')->delete(FrontendMemcacheKeysHelper::generateInsitutionProfileKey($this->institution->getId())); // Check if institution is paying client if ($this->institution->getPayingClient()) { // Invalidate all InstitutionMedicalCenterProfile memcache foreach ($this->institution->getInstitutionMedicalCenters() as $each) { $this->get('services.memcache')->delete(FrontendMemcacheKeysHelper::generateInsitutionMedicalCenterProfileKey($each->getId())); } } } $data['status'] = true; } return new Response(\json_encode($data), 200, array('content-type' => 'application/json')); }
public function ajaxEditGlobalAwardAction() { $globalAward = $this->getDoctrine()->getRepository('HelperBundle:GlobalAward')->find($this->request->get('globalAwardId', 0)); if (!$globalAward) { throw $this->createNotFoundException('Invalid global award'); } $propertyType = $this->get('services.institution_property')->getAvailablePropertyType(InstitutionPropertyType::TYPE_GLOBAL_AWARD); $imcProperty = $this->imcService->getPropertyValue($this->institutionMedicalCenter, $propertyType, $globalAward->getId(), $this->request->get('propertyId', 0)); $imcProperty->setValueObject($globalAward); $editGlobalAwardForm = $this->createForm(new InstitutionGlobalAwardFormType(), $imcProperty); if ($this->request->isMethod('POST')) { $editGlobalAwardForm->bind($this->request); if ($editGlobalAwardForm->isValid()) { $imcProperty = $editGlobalAwardForm->getData(); $em = $this->getDoctrine()->getEntityManager(); $em->persist($imcProperty); $em->flush(); // Invalidate InstitutionMedicalCenterProfile memcache $this->get('services.memcache')->delete(FrontendMemcacheKeysHelper::generateInsitutionMedicalCenterProfileKey($this->institutionMedicalCenter->getId())); $output = array('status' => true, 'extraValue' => $imcProperty->getExtraValue()); $response = new Response(\json_encode($output), 200, array('content-type' => 'application/json')); } else { $response = new Response('Form error', 400); } } return $response; }
/** * * @param Request $request * @return Response * @author acgvelarde */ public function profileAction(Request $request) { $start = \microtime(true); $slug = $request->get('institutionSlug', null); $institutionId = $this->getDoctrine()->getRepository('InstitutionBundle:Institution')->getInstitutionIdBySlug($slug); if (!$institutionId) { throw $this->createNotFoundException('Invalid institution'); } $this->apiInstitutionService = $this->get('services.api.institution'); $this->apiInstitutionMedicalCenterService = $this->get('services.api.institutionMedicalCenter'); $memcacheService = $this->get('services.memcache'); $memcacheKey = FrontendMemcacheKeysHelper::generateInsitutionProfileKey($institutionId); $cachedData = $memcacheService->get($memcacheKey); if (!$cachedData) { $mediaExtensionService = $this->apiInstitutionService->getMediaExtension(); $this->institution = $this->apiInstitutionService->getInstitutionPublicDataById($institutionId); // process common data for both single and multiple center $this->apiInstitutionService->buildGlobalAwards($this->institution)->buildOfferedServices($this->institution)->buildFeaturedMediaSource($this->institution)->buildLogoSource($this->institution)->buildContactDetails($this->institution)->buildExternalSites($this->institution); $isSingleCenterInstitution = $this->apiInstitutionService->isSingleCenterInstitutionType($this->institution['type']); if ($isSingleCenterInstitution) { // build view data for single center institution $this->processSingleCenterInstitution(); } else { // build view data for multiple center institution $this->processMultipleCenterInstitution(); } $this->institution['specializationsList'] = $this->apiInstitutionService->listActiveSpecializations($this->institution['id']); // cache this processed data $memcacheService->set($memcacheKey, $this->institution); } else { $this->institution = $cachedData; $isSingleCenterInstitution = $this->apiInstitutionService->isSingleCenterInstitutionType($this->institution['type']); } $firstMedicalCenter = isset($this->institution['institutionMedicalCenters'][0]) ? $this->institution['institutionMedicalCenters'][0] : null; // set request variables to be used by page meta components $this->getRequest()->attributes->add(array('institution' => $this->institution, 'pageMetaContext' => PageMetaConfiguration::PAGE_TYPE_INSTITUTION, 'pageMetaVariables' => array(PageMetaConfigurationService::ACTIVE_CLINICS_COUNT_VARIABLE => \count($this->institution['institutionMedicalCenters']), PageMetaConfigurationService::SPECIALIZATIONS_COUNT_VARIABLE => \count($this->institution['specializationsList']), PageMetaConfigurationService::SPECIALIZATIONS_LIST_VARIABLE => \implode(', ', \array_slice($this->institution['specializationsList'], 0, 10, true))))); $params = array('institution' => $this->institution, 'isSingleCenterInstitution' => $isSingleCenterInstitution, 'institutionDoctors' => $this->institution['doctors'], 'institutionMedicalCenter' => $firstMedicalCenter, 'form' => $this->createForm(new InstitutionInquiryFormType(), new InstitutionInquiry())->createView(), 'institutionAwards' => $this->institution['globalAwards'], 'institutionServices' => $this->institution['offeredServices'], 'awardTypes' => GlobalAwardTypes::getTypes(), 'photos' => $this->get('services.institution.gallery')->getInstitutionPhotos($this->institution['id'])); $content = $this->render('FrontendBundle:Institution:profile.html.twig', $params); $end = \microtime(true); $diff = $end - $start; //echo "{$diff}s"; exit; $response = $this->setResponseHeaders($content); return $response; }
public function profileAction(Request $request) { $start = \microtime(true); $this->apiInstitutionMedicalCenterService = $this->get('services.api.institutionMedicalCenter'); $slug = $request->get('imcSlug', null); $institutionMedicalCenterId = $this->getDoctrine()->getRepository('InstitutionBundle:InstitutionMedicalCenter')->getInstitutionMedicalCenterIdBySlug($slug); if (!$institutionMedicalCenterId) { throw $this->createNotFoundException('Invalid clinic.'); } $memcacheKey = FrontendMemcacheKeysHelper::generateInsitutionMedicalCenterProfileKey($institutionMedicalCenterId); $memcacheService = $this->get('services.memcache'); $cachedData = $memcacheService->get($memcacheKey); if (!$cachedData) { $this->institutionMedicalCenter = $this->apiInstitutionMedicalCenterService->getInstitutionMedicalCenterPublicDataById($institutionMedicalCenterId); if (!$this->institutionMedicalCenter) { throw $this->createNotFoundException('Invalid medical center'); } $this->institution = $this->institutionMedicalCenter['institution']; if ($this->get('services.api.institution')->isSingleCenterInstitutionType($this->institution)) { // redirect to hospital page } // build optional data, according to paying client rules $this->apiInstitutionMedicalCenterService->buildBusinessHours($this->institutionMedicalCenter)->buildDoctors($this->institutionMedicalCenter)->buildGlobalAwards($this->institutionMedicalCenter)->buildOfferedServices($this->institutionMedicalCenter)->buildInstitutionSpecializations($this->institutionMedicalCenter)->buildLogoSource($this->institutionMedicalCenter, ImageSizes::MEDIUM)->buildFeaturedMediaSource($this->institutionMedicalCenter)->buildMediaGallery($this->institutionMedicalCenter)->buildContactDetails($this->institutionMedicalCenter)->buildExternalSites($this->institutionMedicalCenter); $specializationsList = $this->apiInstitutionMedicalCenterService->listActiveSpecializations($this->institutionMedicalCenter); $this->institutionMedicalCenter['specializationsList'] = $specializationsList; // cache this processed data $memcacheService->set($memcacheKey, $this->institutionMedicalCenter); } else { $this->institutionMedicalCenter = $cachedData; $this->institution = $this->institutionMedicalCenter['institution']; $specializationsList = $this->institutionMedicalCenter['specializationsList']; } $params = array('awards' => $this->institutionMedicalCenter['globalAwards'], 'services' => $this->institutionMedicalCenter['offeredServices'], 'institutionMedicalCenter' => $this->institutionMedicalCenter, 'institution' => $this->institution, 'form' => $this->createForm(new InstitutionInquiryFormType(), new InstitutionInquiry())->createView(), 'formId' => 'imc_inquiry_form'); // set request variables to be used by page meta components $this->getRequest()->attributes->add(array('institutionMedicalCenter' => $this->institutionMedicalCenter, 'pageMetaContext' => PageMetaConfiguration::PAGE_TYPE_INSTITUTION_MEDICAL_CENTER, 'pageMetaVariables' => array(PageMetaConfigurationService::SPECIALIZATIONS_COUNT_VARIABLE => \count($specializationsList), PageMetaConfigurationService::SPECIALIZATIONS_LIST_VARIABLE => \implode(', ', \array_slice($specializationsList, 0, 10, true))))); $content = $this->render('FrontendBundle:InstitutionMedicalCenter:profile.html.twig', $params); //$end = \microtime(true); $diff = $end-$start; echo "{$diff}s"; exit; return $this->setResponseHeaders($content); }
/** * * @param Advertisement or AdvertisementDenormalizedProperty $advertisement */ private function invalidateAdsCache($advertisement) { $advertisementType = $advertisement->getAdvertisementType()->getId(); $memcacheKey = FrontendMemcacheKeysHelper::getAdvertisementKeyByType($advertisementType); if (!$memcacheKey) { $denormalizedAd = $advertisement instanceof AdvertisementDenormalizedProperty ? $advertisement : $this->get('services.advertisement')->getDenomralizedPropertyById($advertisement->getId()); switch ($advertisementType) { case AdvertisementTypes::SEARCH_RESULTS_SPECIALIZATION_FEATURE: $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsSpecializationFeaturedAdsKey($denormalizedAd->getSpecializationId()); break; case AdvertisementTypes::SEARCH_RESULTS_SUBSPECIALIZATION_FEATURE: $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsSubSpecializationFeaturedAdsKey($denormalizedAd->getSubSpecializationId()); break; case AdvertisementTypes::SEARCH_RESULTS_TREATMENT_FEATURE: $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsTreatmentFeaturedAdsKey($denormalizedAd->getTreatmentId()); break; case AdvertisementTypes::SEARCH_RESULTS_CITY_FEATURE: $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsCityFeaturedAdsKey($denormalizedAd->getCityId()); break; case AdvertisementTypes::SEARCH_RESULTS_CITY_SPECIALIZATION_FEATURE: $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsCitySpecializationFeaturedAdsKey($denormalizedAd->getCityId(), $denormalizedAd->getSpecializationId()); break; case AdvertisementTypes::SEARCH_RESULTS_CITY_SUBSPECIALIZATION_FEATURE: $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsCitySubSpecializationFeaturedAdsKey($denormalizedAd->getCityId(), $denormalizedAd->getSubSpecializationId()); break; case AdvertisementTypes::SEARCH_RESULTS_CITY_TREATMENT_FEATURE: $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsCityTreatmentFeaturedAdsKey($denormalizedAd->getCityId(), $denormalizedAd->getTreatmentId()); break; case AdvertisementTypes::SEARCH_RESULTS_COUNTRY_FEATURE: $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsCountryFeaturedAdsKey($denormalizedAd->getCountryId()); break; case AdvertisementTypes::SEARCH_RESULTS_COUNTRY_SPECIALIZATION_FEATURE: $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsCountrySpecializationFeaturedAdsKey($denormalizedAd->getCountryId(), $denormalizedAd->getSpecializationId()); break; case AdvertisementTypes::SEARCH_RESULTS_COUNTRY_SUBSPECIALIZATION_FEATURE: $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsCountrySubSpecializationFeaturedAdsKey($denormalizedAd->getCountryId(), $denormalizedAd->getSubSpecializationId()); break; case AdvertisementTypes::SEARCH_RESULTS_COUNTRY_TREATMENT_FEATURE: $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsCountryTreatmentFeaturedAdsKey($denormalizedAd->getCountryId(), $denormalizedAd->getTreatmentId()); break; } } $this->get('services.memcache')->delete($memcacheKey); }
public function renderSearchResultsFeaturedClinicAd($params) { if (isset($params['treatmentId'])) { if (isset($params['cityId'])) { $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsCityTreatmentFeaturedAdsKey($params['cityId'], $params['treatmentId']); } elseif (isset($params['countryId'])) { $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsCountryTreatmentFeaturedAdsKey($params['countryId'], $params['treatmentId']); } else { $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsTreatmentFeaturedAdsKey($params['treatmentId']); } } else { if (isset($params['subSpecializationId'])) { if (isset($params['cityId'])) { $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsCitySubSpecializationFeaturedAdsKey($params['cityId'], $params['subSpecializationId']); } elseif (isset($params['countryId'])) { $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsCountrySubSpecializationFeaturedAdsKey($params['countryId'], $params['subSpecializationId']); } else { $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsSubSpecializationFeaturedAdsKey($params['subSpecializationId']); } } else { if (isset($params['specializationId'])) { if (isset($params['cityId'])) { $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsCitySpecializationFeaturedAdsKey($params['cityId'], $params['specializationId']); } elseif (isset($params['countryId'])) { $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsCountrySpecializationFeaturedAdsKey($params['countryId'], $params['specializationId']); } else { $memcacheKey = FrontendMemcacheKeysHelper::generateSearchResultsSpecializationFeaturedAdsKey($params['specializationId']); } } } } $searchResultsFeaturedClinics = $this->memcacheService->get($memcacheKey); if (!$searchResultsFeaturedClinics) { if ($ads = $this->retrieverService->getSearchResultsFeaturedClinicByCriteria($params)) { // https://github.com/chromedia/healthcareabroad/issues/510 $featuredClinicIds = array(); foreach ($ads as $ad) { $featuredClinicIds[] = $ad->getInstitutionMedicalCenter()->getId(); } $inSession = $this->session->get($this->getFeaturedClinicsSessionKey()); $inSession[$this->generateSearchResultsParametersSessionKey($params)] = $featuredClinicIds; $this->session->set($this->getFeaturedClinicsSessionKey(), $inSession); $searchResultsFeaturedClinics = $this->twig->render('AdvertisementBundle:Frontend:searchResultsFeaturedAds.html.twig', array('featuredAds' => $ads)); $this->memcacheService->set($memcacheKey, $searchResultsFeaturedClinics); } } return $searchResultsFeaturedClinics; }
/** * Remove institution specialization * * @param Request $request */ public function ajaxRemoveSpecializationAction(Request $request) { $institutionSpecialization = $this->getDoctrine()->getRepository('InstitutionBundle:InstitutionSpecialization')->find($request->get('isId', 0)); if (!$institutionSpecialization) { throw $this->createNotFoundException('Invalid instituiton specialization'); } if ($institutionSpecialization->getInstitutionMedicalCenter()->getId() != $this->institutionMedicalCenter->getId()) { return new Response("Cannot remove specialization that does not belong to this institution", 401); } $form = $this->createForm(new CommonDeleteFormType(), $institutionSpecialization); if ($request->isMethod('POST')) { $form->bind($request); if ($form->isValid()) { $_id = $institutionSpecialization->getId(); $em = $this->getDoctrine()->getEntityManager(); $em->remove($institutionSpecialization); $em->flush(); // Invalidate InstitutionMedicalCenterProfile memcache $this->get('services.memcache')->delete(FrontendMemcacheKeysHelper::generateInsitutionMedicalCenterProfileKey($this->institutionMedicalCenter->getId())); // Invalidate InstitutionProfile memcache $this->get('services.memcache')->delete(FrontendMemcacheKeysHelper::generateInsitutionProfileKey($this->institutionMedicalCenter->getInstitution()->getId())); $responseContent = array('id' => $_id); $response = new Response(\json_encode($responseContent), 200, array('content-type' => 'application/json')); } else { $response = new Response("Invalid form", 400); } } return $response; }
public function deleteAction(Request $request) { $em = $this->getDoctrine()->getEntityManagerForClass('MediaBundle:Media'); $media = $em->getRepository('MediaBundle:Media')->find($request->get('mediaId')); $stringCenterIds = $request->get('institutionMedicalCenterIds', ''); $em->remove($media); $em->flush(); // Invalidate InstitutionProfile memcache $this->get('services.memcache')->delete(FrontendMemcacheKeysHelper::generateInsitutionProfileKey($this->institution->getId())); // Invalidate InstitutionMedicalCenterProfile memcache if any if ($stringCenterIds) { $centerIds = explode(',', $stringCenterIds); foreach ($centerIds as $centerId) { $this->get('services.memcache')->delete(FrontendMemcacheKeysHelper::generateInsitutionMedicalCenterProfileKey($centerId)); } } $result['status'] = true; $result['message'] = 'Photo has been deleted!'; return new Response(json_encode($result), 200, array('Content-Type' => 'application/json')); }
/** * Remove an ancillary service to institution * Required parameters: * - institutionId * - asId ancillary service id * * @param Request $request * @return \Symfony\Component\HttpFoundation\Response * @author alniejacobe */ public function ajaxRemoveAncillaryServiceAction(Request $request) { $property = $this->getDoctrine()->getRepository('InstitutionBundle:InstitutionProperty')->find($request->get('id', 0)); if (!$property) { throw $this->createNotFoundException('Invalid property.'); } $ancillaryService = $this->getDoctrine()->getRepository('AdminBundle:OfferedService')->find($property->getValue()); try { $em = $this->getDoctrine()->getEntityManager(); $em->remove($property); $em->flush(); // Invalidate InstitutionProfile memcache $this->get('services.memcache')->delete(FrontendMemcacheKeysHelper::generateInsitutionProfileKey($this->institution->getId())); $output = array('label' => 'Add Service', 'href' => $this->generateUrl('institution_ajaxAddAncillaryService', array('institutionId' => $this->institution->getId(), 'id' => $ancillaryService->getId())), '_isSelected' => false); $response = new Response(\json_encode($output), 200, array('content-type' => 'application/json')); } catch (\Exception $e) { $response = new Response($e->getMessage(), 500); } return $response; }
/** * Synchronized Institution Data to Clinic Data * @param Institution $institution */ private function syncInstitutionDataToClinicData(Institution $institution) { $center = $this->get('services.institution')->getFirstMedicalCenter($institution); $center->setName($institution->getName()); $center->setDescription($institution->getDescription()); $center->setAddress($institution->getAddress1()); $center->setContactEmail($institution->getContactEmail()); $center->setWebsites($institution->getWebsites()); $center->setDateUpdated($institution->getDateModified()); $this->get('services.institution_medical_center')->save($center); // Invalidate InstitutionMedicalCenterProfile memcache $this->get('services.memcache')->delete(FrontendMemcacheKeysHelper::generateInsitutionMedicalCenterProfileKey($center->getId())); }
/** * Upload Institution Media for Gallery * @param Request $request */ public function uploadMediaAction(Request $request) { $response = new Response(json_encode(true)); $response->headers->set('Content-Type', 'application/json'); if (($fileBag = $request->files) && $fileBag->has('file')) { $media = $this->get('services.institution.media')->uploadToGallery($fileBag->get('file'), $this->institution); if (!$media) { $response = new Response('Error', 500); } // Invalidate Institution Profile cache $this->get('services.memcache')->delete(FrontendMemcacheKeysHelper::generateInsitutionProfileKey($this->institution->getId())); } return $response; }
/** * Upload logo for Institution Medical Center * @param Request $request */ public function uploadAction(Request $request) { if ($request->files->get('logo')) { $file = $request->files->get('logo'); $media = $this->get('services.institution.media')->medicalCenterUploadLogo($file, $this->institutionMedicalCenter); if ($media->getName()) { $src = $this->get('services.institution')->mediaTwigExtension->getInstitutionMediaSrc($media->getName(), ImageSizes::MEDIUM); $data['mediaSrc'] = $src; } $data['status'] = true; // Invalidate InstitutionMedicalCenterProfile memcache $this->get('services.memcache')->delete(FrontendMemcacheKeysHelper::generateInsitutionMedicalCenterProfileKey($this->institutionMedicalCenter->getId())); // Invalidate InstitutionProfile memcache $this->get('services.memcache')->delete(FrontendMemcacheKeysHelper::generateInsitutionProfileKey($this->institutionMedicalCenter->getInstitution()->getId())); } return new Response(\json_encode($data), 200, array('content-type' => 'application/json')); }
public function ajaxAddInstitutionMedicalCenterGlobalAwardAction(Request $request) { $award = $this->getDoctrine()->getRepository('HelperBundle:GlobalAward')->find($request->get('id')); if (!$award) { throw $this->createNotFoundException(); } $propertyService = $this->get('services.institution_medical_center_property'); $propertyType = $propertyService->getAvailablePropertyType(InstitutionPropertyType::TYPE_GLOBAL_AWARD); // check if this medical center already have this property if ($this->get('services.institution_medical_center')->hasPropertyValue($this->institutionMedicalCenter, $propertyType, $award->getId())) { $response = new Response("Award {$award->getId()} already exists.", 500); } else { $property = $propertyService->createInstitutionMedicalCenterPropertyByName($propertyType->getName(), $this->institution, $this->institutionMedicalCenter); $property->setValue($award->getId()); try { $em = $this->getDoctrine()->getEntityManager(); $em->persist($property); $em->flush(); // Invalidate InstitutionMedicalCenter Profile cache $this->get('services.memcache')->delete(FrontendMemcacheKeysHelper::generateInsitutionMedicalCenterProfileKey($request->get('imcId'))); $html = $this->renderView('AdminBundle:InstitutionMedicalCenterProperties/Partials:row.globalAward.html.twig', array('award' => $award, 'property' => $property, 'institution' => $this->institution, 'institutionMedicalCenter' => $this->institutionMedicalCenter, 'commonDeleteForm' => $this->createForm(new CommonDeleteFormType())->createView())); $response = new Response(\json_encode(array('html' => $html)), 200, array('content-type' => 'application/json')); } catch (\Exception $e) { $response = new Response($e->getMessage(), 500); } } return $response; }