diff --git a/src/JotaworksDoiBundle/Config/config.php b/src/JotaworksDoiBundle/Config/config.php index 1fd029c..528f1ba 100644 --- a/src/JotaworksDoiBundle/Config/config.php +++ b/src/JotaworksDoiBundle/Config/config.php @@ -15,44 +15,94 @@ 'mautic.helper.encryption', 'mautic.email.model.email', 'mautic.lead.model.lead', - 'mautic.tracker.contact' + 'mautic.tracker.contact', + 'jw.doi.leadhelper', + 'jw.doi.actionhelper', + 'jotaworksdoi.config' ] ], 'jw.mautic.email.report.doi' => [ 'class' => \MauticPlugin\JotaworksDoiBundle\EventListener\DoiReportSubscriber::class, 'arguments' => [ 'mautic.lead.reportbundle.fields_builder', + 'jotaworksdoi.config' ], ], 'jw.mautic.webhook.subscriber' => [ 'class' => \MauticPlugin\JotaworksDoiBundle\EventListener\WebhookSubscriber::class, 'arguments' => [ 'mautic.webhook.model.webhook', + 'jotaworksdoi.config' ], ], 'jw.mautic.queue.subscriber' => [ 'class' => \MauticPlugin\JotaworksDoiBundle\EventListener\QueueSubscriber::class, 'arguments' => [ - 'monolog.logger.mautic','jw.doi.actionhelper','jw.doi.nothumanclickhelper' + 'monolog.logger.mautic', + 'jw.doi.actionhelper', + 'jw.doi.nothumanclickhelper' ], ] ], 'forms' => [ 'jw.mautic.form.type.jw_emailsend_list' => [ 'class' => \MauticPlugin\JotaworksDoiBundle\Form\Type\EmailSendType::class, - 'arguments' => ['mautic.factory','translator'] -, ], + 'arguments' => [ + 'mautic.factory', + 'translator' + ], + ] ], 'helpers' => [ 'jw.doi.actionhelper' => [ 'class' => \MauticPlugin\JotaworksDoiBundle\Helper\DoiActionHelper::class, - 'arguments' => ['event_dispatcher', 'mautic.helper.ip_lookup', 'mautic.page.model.page', 'mautic.email.model.email', 'mautic.core.model.auditlog', 'mautic.lead.model.lead', 'request_stack' ] + 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.ip_lookup', + 'mautic.page.model.page', + 'mautic.email.model.email', + 'mautic.core.model.auditlog', + 'mautic.lead.model.lead', + 'request_stack', + 'jw.doi.leadhelper', + 'jotaworksdoi.config' + ] + ], + 'jw.doi.leadhelper' => [ + 'class' => \MauticPlugin\JotaworksDoiBundle\Helper\LeadHelper::class, + 'arguments' => [ + 'doctrine.dbal.default_connection' + ] ], 'jw.doi.nothumanclickhelper' => [ 'class' => \MauticPlugin\JotaworksDoiBundle\Helper\NotHumanClickHelper::class, - 'arguments' => ['mautic.helper.paths' ] + 'arguments' => [ + 'mautic.helper.paths' + ] + ] + ], + 'integrations' => [ + 'mautic.integration.jotaworksdoi' => [ + 'class' => \MauticPlugin\JotaworksDoiBundle\Integration\JotaworksDoiIntegration::class, + 'tags' => [ + 'mautic.integration', + 'mautic.basic_integration' + ] + ], + 'jotaworksdoi.integration.configuration' => [ + 'class' => \MauticPlugin\JotaworksDoiBundle\Integration\Support\ConfigSupport::class, + 'tags' => [ + 'mautic.config_integration' + ] + ] + ], + 'others' => [ + 'jotaworksdoi.config' => [ + 'class' => \MauticPlugin\JotaworksDoiBundle\Integration\Config::class, + 'arguments' => [ + 'mautic.integrations.helper', + ] ] - ] ], 'routes' => [ diff --git a/src/JotaworksDoiBundle/EventListener/DoiReportSubscriber.php b/src/JotaworksDoiBundle/EventListener/DoiReportSubscriber.php index 8c1ca7d..ca10493 100644 --- a/src/JotaworksDoiBundle/EventListener/DoiReportSubscriber.php +++ b/src/JotaworksDoiBundle/EventListener/DoiReportSubscriber.php @@ -19,6 +19,7 @@ use Mautic\ReportBundle\ReportEvents; use MauticPlugin\MauticCustomReportBundle\Entity\CustomCreatedContactLog; use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use MauticPlugin\JotaworksDoiBundle\Integration\Config; class DoiReportSubscriber implements EventSubscriberInterface { @@ -29,12 +30,18 @@ class DoiReportSubscriber implements EventSubscriberInterface */ private $fieldsBuilder; + /** + * @var Config + */ + private $bundleConfig; + /** * @param FieldsBuilder $fieldsBuilder */ - public function __construct(FieldsBuilder $fieldsBuilder) + public function __construct(FieldsBuilder $fieldsBuilder, Config $bundleConfig) { $this->fieldsBuilder = $fieldsBuilder; + $this->bundleConfig = $bundleConfig; } /** @@ -56,6 +63,10 @@ public static function getSubscribedEvents() */ public function onReportBuilder(ReportBuilderEvent $event) { + if(!$this->bundleConfig->isPublished()) { + return; + } + if (!$event->checkContext([self::REPORT_NAME])) { return; } @@ -95,6 +106,10 @@ public function onReportBuilder(ReportBuilderEvent $event) */ public function onReportGenerate(ReportGeneratorEvent $event) { + if(!$this->bundleConfig->isPublished()) { + return; + } + if (!$event->checkContext([self::REPORT_NAME])) { return; } @@ -123,6 +138,10 @@ public function onReportGenerate(ReportGeneratorEvent $event) public function onReportDisplay(ReportDataEvent $event) { + if(!$this->bundleConfig->isPublished()) { + return; + } + if (!$event->checkContext([self::REPORT_NAME])) { return; } diff --git a/src/JotaworksDoiBundle/EventListener/FormSubscriber.php b/src/JotaworksDoiBundle/EventListener/FormSubscriber.php index 9c18ae5..4cc37b7 100644 --- a/src/JotaworksDoiBundle/EventListener/FormSubscriber.php +++ b/src/JotaworksDoiBundle/EventListener/FormSubscriber.php @@ -22,8 +22,10 @@ use MauticPlugin\JotaworksDoiBundle\Entity\DoNotContact as DNC; use MauticPlugin\JotaworksDoiBundle\Helper\LeadHelper; use MauticPlugin\JotaworksDoiBundle\Helper\Base64Helper; +use MauticPlugin\JotaworksDoiBundle\Helper\DoiActionHelper; use MauticPlugin\JotaworksDoiBundle\DoiEvents; use MauticPlugin\JotaworksDoiBundle\Event\DoiStarted; +use MauticPlugin\JotaworksDoiBundle\Integration\Config; /** * Class FormSubscriber. @@ -43,12 +45,27 @@ class FormSubscriber implements EventSubscriberInterface protected $contactTracker; + /** + * @var LeadHelper + */ + private $leadHelper; + + /** + * @var DoiActionHelper + */ + private $doiActionHelper; + + /** + * @var Config + */ + private $bundleConfig; + /** * FormSubscriber constructor. * */ - public function __construct($router, $eventDispatcher, $encryptionHelper, $emailModel, $leadModel, ContactTracker $contactTracker) + public function __construct($router, $eventDispatcher, $encryptionHelper, $emailModel, $leadModel, ContactTracker $contactTracker, LeadHelper $leadHelper, DoiActionHelper $doiActionHelper, Config $bundleConfig) { $this->router = $router; $this->eventDispatcher = $eventDispatcher; @@ -56,6 +73,9 @@ public function __construct($router, $eventDispatcher, $encryptionHelper, $email $this->emailModel = $emailModel; $this->leadModel = $leadModel; $this->contactTracker = $contactTracker; + $this->leadHelper = $leadHelper; + $this->doiActionHelper = $doiActionHelper; + $this->bundleConfig = $bundleConfig; } /** @@ -78,7 +98,10 @@ public static function getSubscribedEvents() */ public function onFormBuilder(Events\FormBuilderEvent $event) { - + if(!$this->bundleConfig->isPublished()) { + return; + } + // Send email to lead $action = [ 'group' => 'mautic.email.actions', @@ -101,7 +124,7 @@ private function leadFieldUpdate($config, $lead ) { return; } - LeadHelper::leadFieldUpdate($config['lead_field_update_before'], $this->leadModel, $lead ); + $this->leadHelper->leadFieldUpdate($config['lead_field_update_before'], $this->leadModel, $lead ); } /** @@ -110,33 +133,18 @@ private function leadFieldUpdate($config, $lead ) { * or * - if the do not contact is set by the user and not by a bounced mail or manually set */ - private function shouldEmailBeSended($lead) + private function shouldEmailBeSended($lead): bool { + $doNotContactStatus = $this->leadHelper->getDoNotContactStatus($lead->getId(), 'email'); - foreach ($lead->getDoNotContact() as $dnc) - { - $reason = $dnc->getReason(); - $channel = $dnc->getChannel(); - - //user unsubscribed from email - if( DNC::UNSUBSCRIBE === $reason && $channel=="email" ) - { - return true; - } - - if( DNC::BOUNCED === $reason && $channel=="email" ) - { + switch ($doNotContactStatus) { + case DNC::BOUNCED: return false; - } - - if( DNC::MANUAL === $reason && $channel=="email" ) - { + case DNC::MANUAL: return false; - } - - } - - return true; + default: + return true; + } } private function buildDoiConfirmUrl( $data ) @@ -196,7 +204,7 @@ private function sendDoiEmail($lead, $config, $doidata, $tokens, $submissionId) { return false; } - + $emailId = (int) $config['email']; $email = $this->emailModel->getEntity($emailId); if ($email === null || !$email->isPublished()) { @@ -247,7 +255,22 @@ protected function shouldDoiProcessStart($lead, $data, $submissionId) // - email address + form id + time reaches limit // // + make limits configurable in plugin settings - // OR: make this a generic anti form spam plugin! + // OR: make this a generic anti form spam plugin! + + // Check if feature 'no_email_to_confirmed' is enabled + if (in_array('no_email_to_confirmed', $this->bundleConfig->getSupportedFeatures())) { + // Check DNC status of the lead + $doNotContactStatus = $this->leadHelper->getDoNotContactStatus($lead->getId(), 'email'); + + if ($doNotContactStatus === DNC::IS_CONTACTABLE) { + // Check optin confirmation status of the lead + if (count($data['treatAsConfirmed']) > 0 && $this->isLeadConfirmed($lead, $data)) { + // Run optin success actions and stop further processing + $this->doiActionHelper->applyDoiActions($data, true); + return false; + } + } + } return true; } @@ -257,6 +280,10 @@ protected function shouldDoiProcessStart($lead, $data, $submissionId) */ public function onFormSubmitActionSendEmail(Events\SubmissionEvent $event) { + if(!$this->bundleConfig->isPublished()) { + return; + } + //only action if this is our form action if (!$event->checkContext('jw.email.send.lead')) { return; @@ -274,10 +301,13 @@ public function onFormSubmitActionSendEmail(Events\SubmissionEvent $event) $data = [ 'lead_id' => $lead->getId(), 'url' => $this->preparePostUrl($config['post_url'], $tokens ), + 'treatAsConfirmed' => $config['treat_as_confirmed'], 'add_tags' => $config['add_campaign_doi_success_tags'], 'remove_tags' => $config['remove_tags_doi_success_tags'], 'addToLists' => $config['add_campaign_doi_success_lists'], 'removeFromLists' => $config['remove_campaign_doi_success_lists'], + 'optinStatusField' => $config['optin_status_field'], + 'optinSuccessValue' => $config['optin_success_value'], 'leadFieldUpdate' => $config['lead_field_update'], 'form_id' => $formId, 'hash' => md5(uniqid()) @@ -300,4 +330,45 @@ public function onFormSubmitActionSendEmail(Events\SubmissionEvent $event) } + private function isLeadConfirmed($lead, $data): bool + { + $treatAsConfirmed = $data['treatAsConfirmed']; + $optinSuccessTags = $data['add_tags']; + $optinSuccessLists = $data['addToLists']; + $optinStatusField = $data['optinStatusField']; + $optinSuccessValue = $data['optinSuccessValue']; + $confirmedCriterias = 0; + + // Get tags assigned to the lead + $leadTags = []; + foreach ($lead->getTags() as $tag) { + $leadTags[] = $tag->getTag(); + } + + // Get lists (segments) assigned to the lead + $leadLists = $this->leadHelper->getLeadLists($lead->getId()); + + // Check if lead has all tags assigned + if (in_array('tags', $treatAsConfirmed)) { + $confirmedCriterias += (array_intersect($optinSuccessTags, $leadTags) === $optinSuccessTags) ? 1 : 0; + } + + // Check if lead is member of all lists + if (in_array('segments', $treatAsConfirmed)) { + $confirmedCriterias += (array_intersect($optinSuccessLists, $leadLists) === $optinSuccessLists) ? 1 : 0; + } + + // Check if opt-in status field of the lead has the correct value + if (in_array('status_field', $treatAsConfirmed)) { + if (!empty($optinStatusField)) { + $confirmedCriterias += ($lead->getProfileFields()[$optinStatusField] === $optinSuccessValue) ? 1 : 0; + } else { + $confirmedCriterias += 1; + } + } + + // Check if contact meets all criterias of a successful opt-in + return ($confirmedCriterias === count($treatAsConfirmed)) ? true : false; + } + } diff --git a/src/JotaworksDoiBundle/EventListener/QueueSubscriber.php b/src/JotaworksDoiBundle/EventListener/QueueSubscriber.php index 61094d4..f71a4b3 100644 --- a/src/JotaworksDoiBundle/EventListener/QueueSubscriber.php +++ b/src/JotaworksDoiBundle/EventListener/QueueSubscriber.php @@ -17,6 +17,7 @@ use Mautic\QueueBundle\Queue\QueueConsumerResults; use Symfony\Bridge\Monolog\Logger; use Mautic\QueueBundle\Event\QueueConsumerEvent; +use MauticPlugin\JotaworksDoiBundle\Integration\Config; /** * Class FormSubscriber. @@ -29,18 +30,23 @@ class QueueSubscriber implements EventSubscriberInterface */ private $logger; - protected $secondsToWait = 1*60; + /** + * @var Config + */ + private $bundleConfig; + /** * QueueSubscriber constructor. * */ - public function __construct(Logger $logger, DoiActionHelper $doiActionHelper, $notHumanClickHelper) + public function __construct(Logger $logger, DoiActionHelper $doiActionHelper, $notHumanClickHelper, Config $bundleConfig) { $this->logger = $logger; $this->doiActionHelper = $doiActionHelper; $this->notHumanClickHelper = $notHumanClickHelper; + $this->bundleConfig = $bundleConfig; } /** @@ -94,7 +100,10 @@ private function waitForProcessingTime($doiActivationTime) public function onDoiSuccessful(QueueConsumerEvent $event) { - + if(!$this->bundleConfig->isPublished()) { + return; + } + $payload = $event->getPayload(); $config = $payload['config']; $doiActivationTime = $payload['doiActivationTime']; diff --git a/src/JotaworksDoiBundle/EventListener/WebhookSubscriber.php b/src/JotaworksDoiBundle/EventListener/WebhookSubscriber.php index 0a3a848..8f10ea1 100644 --- a/src/JotaworksDoiBundle/EventListener/WebhookSubscriber.php +++ b/src/JotaworksDoiBundle/EventListener/WebhookSubscriber.php @@ -10,6 +10,7 @@ use MauticPlugin\JotaworksDoiBundle\DoiEvents; use MauticPlugin\JotaworksDoiBundle\Event\DoiStarted; use MauticPlugin\JotaworksDoiBundle\Event\DoiSuccessful; +use MauticPlugin\JotaworksDoiBundle\Integration\Config; class WebhookSubscriber implements EventSubscriberInterface { @@ -18,9 +19,15 @@ class WebhookSubscriber implements EventSubscriberInterface */ private $webhookModel; - public function __construct(WebhookModel $webhookModel) + /** + * @var Config + */ + private $bundleConfig; + + public function __construct(WebhookModel $webhookModel, Config $bundleConfig) { $this->webhookModel = $webhookModel; + $this->bundleConfig = $bundleConfig; } /** @@ -40,6 +47,10 @@ public static function getSubscribedEvents() */ public function onWebhookBuild(WebhookBuilderEvent $event) { + if(!$this->bundleConfig->isPublished()) { + return; + } + $doiStarted = [ 'label' => 'jw.doi.webhook.event.doi_started', 'description' => 'jw.doi.webhook.event.doi_started_desc', @@ -64,6 +75,10 @@ public function onWebhookBuild(WebhookBuilderEvent $event) */ public function onDoiStarted(DoiStarted $event): void { + if(!$this->bundleConfig->isPublished()) { + return; + } + $this->webhookModel->queueWebhooksByType( DoiEvents::DOI_STARTED, [ @@ -82,6 +97,10 @@ public function onDoiStarted(DoiStarted $event): void */ public function onDoiSuccessful(DoiSuccessful $event): void { + if(!$this->bundleConfig->isPublished()) { + return; + } + $this->webhookModel->queueWebhooksByType( DoiEvents::DOI_SUCCESSFUL, [ diff --git a/src/JotaworksDoiBundle/Form/Type/EmailSendType.php b/src/JotaworksDoiBundle/Form/Type/EmailSendType.php index 37a1046..195e1c6 100644 --- a/src/JotaworksDoiBundle/Form/Type/EmailSendType.php +++ b/src/JotaworksDoiBundle/Form/Type/EmailSendType.php @@ -17,6 +17,7 @@ use Mautic\CoreBundle\Form\Type\ButtonGroupType; use Mautic\EmailBundle\Form\Type\EmailListType; use Mautic\LeadBundle\Form\Type\TagType; +use Mautic\LeadBundle\Form\Type\LeadFieldsType; use Mautic\LeadBundle\Form\Type\LeadListType; use Symfony\Component\Form\Extension\Core\Type\ButtonType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; @@ -205,6 +206,25 @@ public function buildForm(FormBuilderInterface $builder, array $options) ); } + $builder->add( + 'treat_as_confirmed', + ChoiceType::class, + [ + 'choices' => [ + $this->translator->trans('jw.mautic.success_criteria.status_field') => 'status_field', + $this->translator->trans('jw.mautic.success_criteria.segments') => 'segments', + $this->translator->trans('jw.mautic.success_criteria.tags') => 'tags' + ], + 'label' => $this->translator->trans('jw.mautic.lead.treat_as_confirmed'), + 'multiple' => true, + 'required' => false, + 'attr' => [ + 'class' => 'form-control', + 'tooltip' => $this->translator->trans('jw.mautic.lead.treat_as_confirmed_desc') + ] + ] + ); + $builder->add( 'add_campaign_doi_success_tags', TagType::class, @@ -255,7 +275,40 @@ public function buildForm(FormBuilderInterface $builder, array $options) ], 'multiple' => true, 'expanded' => false, - ]); + ]); + + $builder->add( + 'optin_status_field', + LeadFieldsType::class, + [ + 'label' => $this->translator->trans('jw.mautic.lead.optin_status_field'), + 'label_attr' => ['class' => 'control-label'], + 'multiple' => false, + 'required' => false, + 'with_company_fields' => false, + 'with_tags' => false, + 'with_utm' => false, + 'placeholder' => 'mautic.core.select', + 'attr' => [ + 'class' => 'form-control', + 'tooltip' => $this->translator->trans('jw.mautic.lead.optin_status_field_desc') + ] + ] + ); + + $builder->add( + 'optin_success_value', + TextType::class, + [ + 'label' => $this->translator->trans('jw.mautic.lead.optin_success_value'), + 'label_attr' => ['class' => 'control-label'], + 'required' => false, + 'attr' => [ + 'class' => 'form-control', + 'tooltip' => $this->translator->trans('jw.mautic.lead.optin_success_value_desc') + ] + ] + ); $builder->add( 'post_url', @@ -280,7 +333,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ), ], ] - ); + ); $builder->add( 'lead_field_update', diff --git a/src/JotaworksDoiBundle/Helper/DoiActionHelper.php b/src/JotaworksDoiBundle/Helper/DoiActionHelper.php index a0150f2..d387827 100644 --- a/src/JotaworksDoiBundle/Helper/DoiActionHelper.php +++ b/src/JotaworksDoiBundle/Helper/DoiActionHelper.php @@ -7,6 +7,7 @@ use MauticPlugin\JotaworksDoiBundle\Event\DoiSuccessful; use MauticPlugin\JotaworksDoiBundle\Helper\LeadHelper; use MauticPlugin\JotaworksDoiBundle\DoiEvents; +use MauticPlugin\JotaworksDoiBundle\Integration\Config; class DoiActionHelper { @@ -23,10 +24,19 @@ class DoiActionHelper { protected $leadModel; - protected $request; + protected $request; + /** + * @var LeadHelper + */ + private $leadHelper; - public function __construct($eventDispatcher, $ipLookupHelper, $pageModel, $emailModel, $auditLogModel, $leadModel, $request ) + /** + * @var Config + */ + private $bundleConfig; + + public function __construct($eventDispatcher, $ipLookupHelper, $pageModel, $emailModel, $auditLogModel, $leadModel, $request, LeadHelper $leadHelper, Config $bundleConfig) { $this->eventDispatcher = $eventDispatcher; $this->ipLookupHelper = $ipLookupHelper; @@ -35,6 +45,8 @@ public function __construct($eventDispatcher, $ipLookupHelper, $pageModel, $emai $this->auditLogModel = $auditLogModel; $this->leadModel = $leadModel; $this->request = $request->getCurrentRequest(); + $this->leadHelper = $leadHelper; + $this->bundleConfig = $bundleConfig; } public function setRequest($request) @@ -42,14 +54,17 @@ public function setRequest($request) $this->request = $request; } - public function applyDoiActions($config) + public function applyDoiActions($config, $confirmed = false) { - $this->logDoiSuccess($config); $this->updateLead($config); - $this->removeDNC($config['leadEmail']); - $this->identifyLead($config['lead_id']); + $this->identifyLead($config['lead_id']); $this->trackPageHit($config); $this->fireWebhook($config); + + if (!$confirmed) { + $this->logDoiSuccess($config); + $this->removeDNC($config['leadEmail']); + } } public function fireWebhook($config) @@ -143,8 +158,23 @@ public function updateLead($config) { //Update lead value (if any) if( !empty($leadFieldUpdate) ) { - $ip = $this->ipLookupHelper->getIpAddressFromRequest(); - LeadHelper::leadFieldUpdate($leadFieldUpdate, $this->leadModel, $lead, $ip ); + $ip = $this->ipLookupHelper->getIpAddressFromRequest(); + $this->leadHelper->leadFieldUpdate($leadFieldUpdate, $this->leadModel, $lead, $ip); + } + + // Confirm the opt-in status + $this->setSuccessStatus($lead, $config); + } + + public function setSuccessStatus($lead, $config): void + { + $optinStatusField = $config['optinStatusField']; + $optinSuccessValue = $config['optinSuccessValue']; + + // Update opt-in status field + if (!empty($optinStatusField) && !empty($optinSuccessValue)) { + $this->leadModel->setFieldValues($lead, [$optinStatusField => $optinSuccessValue], false); + $this->leadModel->saveEntity($lead); } } diff --git a/src/JotaworksDoiBundle/Helper/LeadHelper.php b/src/JotaworksDoiBundle/Helper/LeadHelper.php index 4513acf..bfaa8a1 100644 --- a/src/JotaworksDoiBundle/Helper/LeadHelper.php +++ b/src/JotaworksDoiBundle/Helper/LeadHelper.php @@ -1,11 +1,24 @@ connection = $connection; + } + + public function leadFieldUpdate($leadFieldUpdate, $leadModel, $lead, $ip = null ) { if(empty($leadFieldUpdate)) { @@ -56,5 +69,50 @@ public static function leadFieldUpdate($leadFieldUpdate, $leadModel, $lead, $ip } } + + public function getDoNotContactStatus(int $contactId, string $channel): int + { + $q = $this->connection->createQueryBuilder(); + + $q->select('dnc.reason') + ->from(MAUTIC_TABLE_PREFIX.'lead_donotcontact', 'dnc') + ->where( + $q->expr()->andX( + $q->expr()->eq('dnc.lead_id', ':contactId'), + $q->expr()->eq('dnc.channel', ':channel') + ) + ) + ->setParameter('contactId', $contactId) + ->setParameter('channel', $channel) + ->setMaxResults(1); + + $status = $q->execute()->fetchColumn(); + + if (false === $status) { + return DoNotContact::IS_CONTACTABLE; + } + + return (int) $status; + } + + public function getLeadLists(int $contactId): array + { + $q = $this->connection->createQueryBuilder(); + + $q->select('lead_lists_leads.leadlist_id') + ->from(MAUTIC_TABLE_PREFIX.'lead_lists_leads') + ->where( + $q->expr()->eq('lead_lists_leads.lead_id', ':contactId') + ) + ->setParameter('contactId', $contactId); + + $leadLists = $q->execute()->fetchFirstColumn(); + + if (!is_array($leadLists)) { + return []; + } + + return $leadLists; + } -} +} \ No newline at end of file diff --git a/src/JotaworksDoiBundle/Integration/Config.php b/src/JotaworksDoiBundle/Integration/Config.php new file mode 100644 index 0000000..d62fc51 --- /dev/null +++ b/src/JotaworksDoiBundle/Integration/Config.php @@ -0,0 +1,79 @@ + + */ + private array $fieldDirections = []; + + /** + * @var array + */ + private $mappedFields = []; + + public function __construct(IntegrationsHelper $integrationsHelper) + { + $this->integrationsHelper = $integrationsHelper; + } + + public function isPublished(): bool + { + try { + $integration = $this->getIntegrationEntity(); + + return (bool) $integration->getIsPublished() ?: false; + } catch (IntegrationNotFoundException $e) { + return false; + } + } + + /** + * @return mixed[] + */ + public function getSupportedFeatures(): array + { + try { + $integration = $this->getIntegrationEntity(); + + return $integration->getSupportedFeatures() ?: []; + } catch (IntegrationNotFoundException $e) { + return []; + } + } + + /** + * @return mixed[] + */ + public function getFeatureSettings(): array + { + try { + $integration = $this->getIntegrationEntity(); + + return $integration->getFeatureSettings() ?: []; + } catch (IntegrationNotFoundException $e) { + return []; + } + } + + /** + * @throws IntegrationNotFoundException + */ + public function getIntegrationEntity(): Integration + { + $integrationObject = $this->integrationsHelper->getIntegration(JotaworksDoiIntegration::NAME); + + return $integrationObject->getIntegrationConfiguration(); + } +} diff --git a/src/JotaworksDoiBundle/Integration/JotaworksDoiIntegration.php b/src/JotaworksDoiBundle/Integration/JotaworksDoiIntegration.php new file mode 100644 index 0000000..3184777 --- /dev/null +++ b/src/JotaworksDoiBundle/Integration/JotaworksDoiIntegration.php @@ -0,0 +1,33 @@ + + */ + public function getSupportedFeatures(): array + { + return [ + "no_email_to_confirmed" => 'jw.doi.feature.no_email_to_confirmed', + ]; + } +} \ No newline at end of file diff --git a/src/JotaworksDoiBundle/Translations/de_DE/messages.ini b/src/JotaworksDoiBundle/Translations/de_DE/messages.ini index b32efb1..964e009 100644 --- a/src/JotaworksDoiBundle/Translations/de_DE/messages.ini +++ b/src/JotaworksDoiBundle/Translations/de_DE/messages.ini @@ -16,3 +16,13 @@ jw.doi.webhook.event.doi_started_desc="Sendet bei gestartetem DOI den Kontakt un jw.doi.webhook.event.doi_successful="DOI erfolgreich" jw.doi.webhook.event.doi_successful_desc="Sendet bei erfolgreichem DOI den Lead und die Formularkonfiguration." jw.mautic.form.action.alternative_email_field="Lead Feld Alias für E-Mail Adresse (Optional)" +jw.doi.feature.no_email_to_confirmed="Keine E-Mails an bereits bestätigte Kontakte senden." +jw.mautic.lead.optin_status_field="Kontaktfeld für den Opt-in-Status" +jw.mautic.lead.optin_status_field_desc="Wählen Sie das Kontaktfeld aus, in dem der Opt-in-Status gespeichert werden soll." +jw.mautic.lead.optin_success_value="Wert nach erfolgreichem Opt-in" +jw.mautic.lead.optin_success_value_desc="Geben Sie den Wert ein, der nach erfolgreichem Opt-In gesetzt werden soll." +jw.mautic.lead.treat_as_confirmed="Kriterien zur Überprüfung, ob der Kontakt bereits bestätigt wurde" +jw.mautic.lead.treat_as_confirmed_desc="Wenn ein Lead die Erfolgskriterien erfüllt, erhält er keine weitere Double-Opt-In-E-Mail." +jw.mautic.success_criteria.status_field="Statusfeld" +jw.mautic.success_criteria.segments="Segmente" +jw.mautic.success_criteria.tags="Tags" diff --git a/src/JotaworksDoiBundle/Translations/en_US/messages.ini b/src/JotaworksDoiBundle/Translations/en_US/messages.ini index 8f71e0e..f5ecea4 100644 --- a/src/JotaworksDoiBundle/Translations/en_US/messages.ini +++ b/src/JotaworksDoiBundle/Translations/en_US/messages.ini @@ -16,3 +16,13 @@ jw.doi.webhook.event.doi_started_desc="Sends the lead and form config after DOI jw.doi.webhook.event.doi_successful="DOI Successful Event" jw.doi.webhook.event.doi_successful_desc="Sends the lead and form config after the DOI was successfully completed." jw.mautic.form.action.alternative_email_field="Lead field alias for email (optional)" +jw.doi.feature.no_email_to_confirmed="Do not send emails to already confirmed leads." +jw.mautic.lead.optin_status_field="Opt-in status field" +jw.mautic.lead.optin_status_field_desc="Select the lead field where the opt-in status will be saved." +jw.mautic.lead.optin_success_value="Opt-in success value" +jw.mautic.lead.optin_success_value_desc="Enter the value to be set after a successful opt-in." +jw.mautic.lead.treat_as_confirmed="Criteria for checking if the contact has already been confirmed" +jw.mautic.lead.treat_as_confirmed_desc="If a lead meets the success criteria, they will not receive another double opt-in email." +jw.mautic.success_criteria.status_field="Status field" +jw.mautic.success_criteria.segments="Segments" +jw.mautic.success_criteria.tags="Tags"