/**
  * @param RecipientInterface $recipient
  * @param Salutation         $salutation
  *
  * @return bool
  */
 public function accept(RecipientInterface $recipient, Salutation $salutation)
 {
     global $container;
     $fieldValue = $salutation->getGenderFilter();
     if (!$salutation->getEnableGenderFilter() || empty($fieldValue)) {
         return true;
     }
     $details = $recipient->getDetails();
     $fieldName = 'gender';
     if (isset($details[$fieldName]) && $fieldValue == $details[$fieldName]) {
         return true;
     }
     /** @var SynonymizerService $synonymizer */
     $synonymizer = $container['avisota.recipient.synonymizer'];
     $synonyms = $synonymizer->findSynonyms('gender');
     // try synonyms
     if ($synonyms) {
         foreach ($synonyms as $synonym) {
             if (isset($details[$synonym]) && $fieldValue == $details[$synonym]) {
                 return true;
             }
         }
     }
     return false;
 }
 /**
  * @param RecipientInterface $recipient
  * @param Salutation         $salutation
  *
  * @return bool
  */
 public function accept(RecipientInterface $recipient, Salutation $salutation)
 {
     global $container;
     $requiredFields = $salutation->getRequiredFieldsFilter();
     if (!$salutation->getEnableRequiredFieldsFilter() || empty($requiredFields)) {
         return true;
     }
     $details = $recipient->getDetails();
     foreach ($requiredFields as $requiredField) {
         if (empty($details[$requiredField])) {
             /** @var SynonymizerService $synonymizer */
             $synonymizer = $container['avisota.recipient.synonymizer'];
             $synonyms = $synonymizer->findSynonyms($requiredField);
             $stillEmpty = true;
             if ($synonyms) {
                 foreach ($synonyms as $synonym) {
                     if (!empty($details[$synonym])) {
                         $stillEmpty = false;
                         break;
                     }
                 }
             }
             if ($stillEmpty) {
                 return false;
             }
         }
     }
     return true;
 }
 /**
  * @param RecipientInterface $recipient
  * @param Message|null       $message
  * @SuppressWarnings(PHPMD.LongVariable)
  */
 protected function addSalutationToRecipient(RecipientInterface $recipient, Message $message = null)
 {
     global $container;
     if ($recipient->get('salutation') || !$message) {
         return;
     }
     $salutationGroupId = $message->getCategory()->getSalutation();
     if (!$salutationGroupId) {
         return;
     }
     $salutationGroupRepository = EntityHelper::getRepository('Avisota\\Contao:SalutationGroup');
     $salutationGroup = $salutationGroupRepository->find($salutationGroupId);
     if (!$salutationGroup) {
         return;
     }
     /** @var Selector $selector */
     $selector = $container['avisota.salutation.selector'];
     /** @var TagReplacementService $tagReplacer */
     $tagReplacer = $container['avisota.message.tagReplacementEngine'];
     if (!$recipient instanceof MutableRecipient) {
         $recipient = new MutableRecipient($recipient->getEmail(), $recipient->getDetails());
     }
     $salutation = $selector->selectSalutation($recipient, $salutationGroup);
     if (!$salutation) {
         return;
     }
     $pattern = $salutation->getSalutation();
     $buffer = $tagReplacer->parse($pattern, $recipient->getDetails());
     $recipient->set('salutation', $buffer);
 }