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'));
 }
 /**
  * 
  * @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;
 }
 /**
  * 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;
 }
 /**
  * Ajax handler for updating institution coordinates field.
  *
  * @param Request $request
  * @author Adelbert D. Silla
  */
 public function ajaxUpdateCoordinatesAction(Request $request)
 {
     if ($request->isMethod('POST')) {
         $this->institution->setCoordinates($request->get('coordinates'));
         $em = $this->getDoctrine()->getEntityManager();
         $em->persist($this->institution);
         $em->flush($this->institution);
         // Invalidate InstitutionProfile memcache
         $this->get('services.memcache')->delete(FrontendMemcacheKeysHelper::generateInsitutionProfileKey($this->institution->getId()));
         return new Response(\json_encode(true), 200, array('content-type' => 'application/json'));
     }
 }
 /**
  * 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 addInstitutionLanguageSpokenAction(Request $request)
 {
     $form = $this->get('services.institution_property.formFactory')->buildFormByInstitutionPropertyTypeName($this->institution, 'language_id');
     $formActionUrl = $this->generateUrl('admin_institution_addLanguageSpoken', array('institutionId' => $this->institution->getId()));
     if ($request->isMethod('POST')) {
         $form->bind($request);
         if ($form->isValid()) {
             $this->get('services.institution_property')->save($form->getData());
             // Invalidate Institution Profile cache
             $this->get('services.memcache')->delete(FrontendMemcacheKeysHelper::generateInsitutionProfileKey($this->institution->getId()));
             return $this->redirect($formActionUrl);
         }
     }
     $params = array('formAction' => $formActionUrl, 'form' => $form->createView());
     return $this->render('AdminBundle:InstitutionProperties:common.form.html.twig', $params);
 }