public function reverseTransform($value)
 {
     if (!\is_array($value) || empty($value)) {
         $value = SocialMediaSites::getDefaultValues();
     }
     return \json_encode($value);
 }
 protected function reformatSocialMediaSites($results, $objectType)
 {
     $em = $this->getContainer()->get('doctrine')->getEntityManager();
     foreach ($results as $each) {
         $hasFormattedSites = false;
         $socialMediaSitesArr = \json_decode($each->getSocialMediaSites(), true);
         $this->output->writeln("{$objectType} ID: " . $each->getId());
         // IF not valid data or empty.
         if (!$socialMediaSitesArr || !is_array($socialMediaSitesArr)) {
             $each->setSocialMediaSites(\json_encode(SocialMediaSites::getDefaultValues()));
             $em->persist($each);
             continue;
         }
         foreach ($socialMediaSitesArr as $type => $value) {
             if ($value && !filter_var($value, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED)) {
                 $hasFormattedSites = true;
                 $this->output->write("Reformat: {$value}");
                 if (trim($value) == 'http://') {
                     $socialMediaSitesArr[$type] = '';
                 } else {
                     $socialMediaSitesArr[$type] = $this->getSocialMediaSitesUrlByType($type) . $value;
                 }
                 $this->output->writeln(" => " . $socialMediaSitesArr[$type] . " ({$type})");
             }
             // else { $this->output->writeln("Ignored url: " . $socialMediaSitesArr[$type] . " ($type)"); }
         }
         if ($hasFormattedSites) {
             $each->setSocialMediaSites(\json_encode($socialMediaSitesArr));
             $em->persist($each);
         }
     }
     $em->flush();
 }
 /**
  * Build the main website url and social media sites
  * 
  * @param array $institution
  * @param int $context
  * @return \HealthCareAbroad\ApiBundle\Services\InstitutionApiService
  */
 public function buildExternalSites(&$institution, $context = InstitutionApiService::CONTEXT_FULL_PAGE_VIEW)
 {
     $canDisplay = $institution['payingClient'] != 0;
     if (InstitutionApiService::CONTEXT_FULL_API != $context && !$canDisplay) {
         $institution['socialMediaSites'] = SocialMediaSites::getDefaultValues();
         $institution['websites'] = null;
     } else {
         $institution['socialMediaSites'] = \json_decode($institution['socialMediaSites'], true);
     }
     return $this;
 }
 public function getSocialMediaSiteLabel($type)
 {
     return SocialMediaSites::getLabelByType($type);
 }
 /**
  * Build website url and social media sites url
  * 
  * @param array $institutionMedicalCenter
  * @param int $context
  * @return \HealthCareAbroad\ApiBundle\Services\InstitutionMedicalCenterApiService
  */
 public function buildExternalSites(&$institutionMedicalCenter, $context = InstitutionMedicalCenterApiService::CONTEXT_FULL_PAGE_VIEW)
 {
     $institutionMedicalCenter['socialMediaSites'] = \json_decode($institutionMedicalCenter['socialMediaSites'], true);
     // api with restrictions
     if (self::CONTEXT_FULL_API != $context) {
         $canDisplayExternalSites = PayingStatus::FREE_LISTING != $institutionMedicalCenter['payingClient'];
         if (!$canDisplayExternalSites) {
             // build the Social Media Sites default values
             $institutionMedicalCenter['socialMediaSites'] = SocialMediaSites::getDefaultValues();
             $institutionMedicalCenter['websites'] = null;
         }
     }
     return $this;
 }