/**
  * Builds a profile array from person information
  * @param $infos
  * @return array
  */
 public function buildProfile($infos, $mergeWithDefaults = true)
 {
     $struct = $this->profileSkeleton;
     if ($mergeWithDefaults) {
         $struct = Util::array_merge_recursive_distinct($struct, $this->defaultProfile);
     }
     return Util::array_merge_recursive_distinct($struct, $infos);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $container = $this->getContainer();
     $config = $this->getContainer()->getParameter(CorporateVCardsBundle::$conf_prefix . '.config');
     if (!$config['favicons']['enabled']) {
         $output->writeln('Favicons are disabled in app config.');
         return;
     }
     // Check API key
     $this->relFaviconGeneratorApiKey = $config['favicons']['real_favicon_generator_api_key'];
     if (!$this->relFaviconGeneratorApiKey) {
         $output->writeln('Missing RealFaviconGenerator API key, aborting.');
         $output->writeln('Read documentation at https://github.com/AtlanteGroup/CorporateVCardsBundle to learn how to generate one.');
         return;
     }
     // Generate destination path
     $destination_logicalPath = $config['favicons']['dir'];
     $destination = $container->get('file_locator')->locate($destination_logicalPath);
     // Get profiles
     $vCardService = $this->getContainer()->get('corporate_v_cards.vcard');
     $profiles = $vCardService->getProfiles();
     // Let's go!
     $output->writeln('Generating favicons for ' . implode(', ', array_keys($profiles)) . ':');
     foreach ($profiles as $person => $profile) {
         // Don't generate it if it doesn't have any photo
         if (!$profile['photo']) {
             $output->writeln('    [INFO] ' . $person . ' does not have any photo, skipping');
             continue;
         }
         $dir = $destination . $person;
         // Create a directory for this person if doesn't exists
         if (!file_exists($dir)) {
             mkdir($dir);
         }
         // Check if there are favicons
         $files = array_diff(scandir($dir), ['..', '.']);
         if (!empty($files)) {
             $output->writeln('    [INFO] Favicons found for ' . $person . ', skipping');
             continue;
         }
         // Call API to generate favicons
         $output->writeln(' -> Calling API for ' . $person);
         $publicPath = '/' . Util::getPublicDir($destination_logicalPath . $person);
         $res = $this->getFavicons($profile, $dir, $publicPath);
         if (!$res) {
             $output->writeln(' -> Failed while generating favicons for ' . $person);
         } else {
             $output->writeln(' -> Finished downloading favicons for ' . $person);
         }
     }
 }
 public function vCardAction($person, Request $request)
 {
     /** @var VCardService $vCardService */
     $vCardService = $this->get('corporate_v_cards.vcard');
     // Get person profile
     $profile = $vCardService->getProfile($person);
     if (!$profile) {
         throw new NotFoundHttpException();
     }
     $config = $this->getParameter(CorporateVCardsBundle::$conf_prefix . '.config');
     // Get random background
     $backgrounds = $config['backgrounds'];
     $background = $backgrounds[rand(0, count($backgrounds) - 1)];
     // Check if mails are enabled
     $formView = null;
     $mailSent = false;
     $recipientVcardLink = null;
     $mailsServiceName = $config['mails_service'];
     if (!!$mailsServiceName) {
         // Send by mail form
         $formBuilder = $this->createFormBuilder()->add('email', EmailType::class, ['attr' => ['placeholder' => 'Adresse e-mail'], 'required' => true])->add('submit', SubmitType::class, ['label' => 'Envoyer']);
         $form = $formBuilder->getForm();
         $form->handleRequest($request);
         $formView = $form->createView();
         if ($form->isSubmitted() && $form->isValid()) {
             // Send e-mail
             /** @var MailsServiceInterface $mailsService */
             $mailsService = $this->get(substr($mailsServiceName, 1));
             $email = $form->get('email')->getData();
             $mailsService->sendVcard($email, $profile, $person);
             // Generate vcard download link from user e-mail address
             $infos = Util::getContactInformationFromEmailAddress($email);
             $recipientVcardLink = $this->get('router')->generate('vcard_download_frominfos', array_merge(['person' => $person], $infos));
             $mailSent = true;
         }
     }
     // Generate favicons public path base
     $faviconsPath = $config['favicons']['enabled'] ? Util::getPublicDir($config['favicons']['dir']) : null;
     return $this->render('@CorporateVCards/vcard.html.twig', ['person' => $person, 'profile' => $profile, 'background' => $background, 'mailsEnabled' => $mailsServiceName != null, 'mailSent' => $mailSent, 'recipientVcardLink' => $recipientVcardLink, 'form' => $formView, 'config' => $config, 'favicons_path_base' => $faviconsPath]);
 }