diff --git a/app/bundles/CampaignBundle/Translations/en_US/messages.ini b/app/bundles/CampaignBundle/Translations/en_US/messages.ini index 6d5208bcec0..39f59802c86 100644 --- a/app/bundles/CampaignBundle/Translations/en_US/messages.ini +++ b/app/bundles/CampaignBundle/Translations/en_US/messages.ini @@ -32,6 +32,10 @@ mautic.campaign.event.intervalunit.h="{0} hours|{1} hour|[2,Inf] hours" mautic.campaign.event.intervalunit.i="{0} minutes|{1} minute|[2,Inf] minutes" mautic.campaign.event.intervalunit.m="{0} months|{1} month|[2,Inf] months" mautic.campaign.event.intervalunit.y="{0} years|{1} year|[2,Inf] years" +mautic.campaign.event.timed.choice.today="Is Today" +mautic.campaign.event.timed.choice.yesterday="Is Yesterday" +mautic.campaign.event.timed.choice.tomorrow="Is Tomorrow" +mautic.campaign.event.timed.choice.anniversary="Anniversary" mautic.campaign.event.leadchange="contact changed campaigns" mautic.campaign.event.leadchange_descr="Trigger actions when a contact is added/removed from a campaign." mautic.campaign.event.systemchanges.header="System Changes" diff --git a/app/bundles/DynamicContentBundle/EventListener/CampaignSubscriber.php b/app/bundles/DynamicContentBundle/EventListener/CampaignSubscriber.php index 2e924f188e6..1fc13c7f215 100644 --- a/app/bundles/DynamicContentBundle/EventListener/CampaignSubscriber.php +++ b/app/bundles/DynamicContentBundle/EventListener/CampaignSubscriber.php @@ -151,7 +151,6 @@ public function onCampaignTriggerAction(CampaignExecutionEvent $event) $content = $tokenEvent->getContent(); $content = preg_replace('#(.*?)#is', '', $content); - $event->stopPropagation(); $result = $event->setResult($content); diff --git a/app/bundles/LeadBundle/Controller/AjaxController.php b/app/bundles/LeadBundle/Controller/AjaxController.php index 328c1db3f02..4833e8b11fb 100644 --- a/app/bundles/LeadBundle/Controller/AjaxController.php +++ b/app/bundles/LeadBundle/Controller/AjaxController.php @@ -763,7 +763,7 @@ protected function updateLeadFieldValuesAction(Request $request) $alias = InputHelper::clean($request->request->get('alias')); $dataArray = ['success' => 0, 'options' => null]; $leadField = $this->getModel('lead.field')->getRepository()->findOneBy(['alias' => $alias]); - $choiceTypes = ['boolean', 'locale', 'country', 'region', 'lookup', 'timezone', 'select', 'radio']; + $choiceTypes = ['boolean', 'locale', 'country', 'region', 'lookup', 'timezone', 'select', 'radio', 'date']; if ($leadField && in_array($leadField->getType(), $choiceTypes)) { $properties = $leadField->getProperties(); @@ -791,6 +791,11 @@ protected function updateLeadFieldValuesAction(Request $request) case 'locale': $options = FormFieldHelper::getLocaleChoices(); break; + case 'date': + $fieldHelper = new FormFieldHelper(); + $fieldHelper->setTranslator($this->get('translator')); + $options = $fieldHelper->getDateChoices(); + break; default: $options = (!empty($properties)) ? $properties : []; } diff --git a/app/bundles/LeadBundle/Entity/LeadFieldRepository.php b/app/bundles/LeadBundle/Entity/LeadFieldRepository.php index 22aab5133a5..235af4912db 100644 --- a/app/bundles/LeadBundle/Entity/LeadFieldRepository.php +++ b/app/bundles/LeadBundle/Entity/LeadFieldRepository.php @@ -207,4 +207,63 @@ public function compareValue($lead, $field, $value, $operatorExpr) return !empty($result['id']); } } + + /** + * Compare a form result value with defined date value for defined lead. + * + * @param int $lead ID + * @param int $field alias + * @param string $value to compare with + * + * @return bool + */ + public function compareDateValue($lead, $field, $value) + { + $q = $this->_em->getConnection()->createQueryBuilder(); + $q->select('l.id') + ->from(MAUTIC_TABLE_PREFIX.'leads', 'l') + ->where( + $q->expr()->andX( + $q->expr()->eq('l.id', ':lead'), + $q->expr()->eq('l.'.$field, ':value') + ) + ) + ->setParameter('lead', (int) $lead) + ->setParameter('value', $value); + + $result = $q->execute()->fetch(); + + return !empty($result['id']); + } + + /** + * Compare a form result value with defined date value ( only day and month compare for + * events such as anniversary) for defined lead. + * + * @param int $lead ID + * @param int $field alias + * @param object $value Date object to compare with + * + * @return bool + */ + public function compareDateMonthValue($lead, $field, $value) + { + $q = $this->_em->getConnection()->createQueryBuilder(); + $q->select('l.id') + ->from(MAUTIC_TABLE_PREFIX.'leads', 'l') + ->where( + $q->expr()->andX( + $q->expr()->eq('l.id', ':lead'), + $q->expr()->eq("MONTH(l. $field)", ':month'), + $q->expr()->eq("DAY(l. $field)", ':day') + ) + ) + ->setParameter('lead', (int) $lead) + ->setParameter('month', $value->format('m')) + ->setParameter('day', $value->format('d')); + + $result = $q->execute()->fetch(); + + return !empty($result['id']); + } } diff --git a/app/bundles/LeadBundle/Entity/OperatorListTrait.php b/app/bundles/LeadBundle/Entity/OperatorListTrait.php index d8e61228025..b5d6444e060 100644 --- a/app/bundles/LeadBundle/Entity/OperatorListTrait.php +++ b/app/bundles/LeadBundle/Entity/OperatorListTrait.php @@ -105,6 +105,12 @@ public function getFilterExpressionFunctions($operator = null) 'expr' => 'notRegexp', //special case 'negate_expr' => 'regexp', ], + 'date' => [ + 'label' => 'mautic.lead.list.form.operator.date', + 'expr' => 'date', //special case + 'negate_expr' => 'date', + 'hide' => true, + ], ]; return ($operator === null) ? $operatorOptions : $operatorOptions[$operator]; diff --git a/app/bundles/LeadBundle/EventListener/CampaignSubscriber.php b/app/bundles/LeadBundle/EventListener/CampaignSubscriber.php index 5f399871031..274e8d76e3e 100644 --- a/app/bundles/LeadBundle/EventListener/CampaignSubscriber.php +++ b/app/bundles/LeadBundle/EventListener/CampaignSubscriber.php @@ -292,15 +292,55 @@ public function onCampaignTriggerCondition(CampaignExecutionEvent $event) return $event->setResult(false); } - $operators = $this->leadModel->getFilterExpressionFunctions(); + if ($event->getConfig()['operator'] === 'date') { + $triggerDate = new \DateTime(); + $interval = substr($event->getConfig()['value'], 1); // remove 1st character + or - + + if (strpos($event->getConfig()['value'], '+P') !== FALSE) { //add date + $triggerDate->add(new \DateInterval($interval)); //add the today date with interval + $result = $this->compareDateValue($lead, $event, $triggerDate); + } else if (strpos($event->getConfig()['value'], '-P') !== FALSE) { //subtract date + $triggerDate->sub(new \DateInterval($interval)); //subtract the today date with interval + $result = $this->compareDateValue($lead, $event, $triggerDate); + } else if ($event->getConfig()['value'] === 'anniversary') { + /** + * note: currently mautic campaign only one time execution + * ( to integrate with: recursive campaign (future)) + */ + $result = $this->leadFieldModel->getRepository()->compareDateMonthValue( + $lead->getId(), $event->getConfig()['field'], $triggerDate); + } + } else { + $operators = $this->leadModel->getFilterExpressionFunctions(); + + $result = $this->leadFieldModel->getRepository()->compareValue( + $lead->getId(), + $event->getConfig()['field'], + $event->getConfig()['value'], + $operators[$event->getConfig()['operator']]['expr'] + ); + } - $result = $this->leadFieldModel->getRepository()->compareValue( - $lead->getId(), - $event->getConfig()['field'], - $event->getConfig()['value'], - $operators[$event->getConfig()['operator']]['expr'] + return $event->setResult($result); + } + + /** + * Function to compare date value. + * + * @param obj $lead + * @param obj $event + * @param obj $triggerDate + * + * @return type + */ + private function compareDateValue($lead, $event, $triggerDate) + { + $result = $this->leadFieldModel->getRepository()->compareDateValue( + $lead->getId(), + $event->getConfig()['field'], + $triggerDate->format('Y-m-d') ); - return $event->setResult($result); + return $result; } } diff --git a/app/bundles/LeadBundle/Form/Type/CampaignEventLeadFieldValueType.php b/app/bundles/LeadBundle/Form/Type/CampaignEventLeadFieldValueType.php index ddb79c70fd9..90c3c2ee6ac 100755 --- a/app/bundles/LeadBundle/Form/Type/CampaignEventLeadFieldValueType.php +++ b/app/bundles/LeadBundle/Form/Type/CampaignEventLeadFieldValueType.php @@ -85,7 +85,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $fieldValues = null; $fieldType = null; - $choiceTypes = ['boolean', 'locale', 'country', 'region', 'lookup', 'timezone', 'select', 'radio']; + $choiceTypes = ['boolean', 'locale', 'country', 'region', 'lookup', 'timezone', 'select', 'radio', 'date']; if (isset($data['field'])) { $field = $fieldModel->getRepository()->findOneBy(['alias' => $data['field']]); @@ -116,6 +116,11 @@ public function buildForm(FormBuilderInterface $builder, array $options) case 'locale': $fieldValues = FormFieldHelper::getLocaleChoices(); break; + case 'date': + $fieldHelper = new FormFieldHelper(); + $fieldHelper->setTranslator($this->factory->getTranslator()); + $fieldValues = $fieldHelper->getDateChoices(); + break; default: if (!empty($properties)) { $fieldValues = $properties; diff --git a/app/bundles/LeadBundle/Helper/FormFieldHelper.php b/app/bundles/LeadBundle/Helper/FormFieldHelper.php index e2a16019477..9342de83525 100644 --- a/app/bundles/LeadBundle/Helper/FormFieldHelper.php +++ b/app/bundles/LeadBundle/Helper/FormFieldHelper.php @@ -228,4 +228,35 @@ public static function getLocaleChoices() { return Intl::getLocaleBundle()->getLocaleNames(); } + + /** + * Get date field choices. + * + * @return array + */ + public function getDateChoices() + { + $options = [ + 'anniversary' => $this->translator->trans('mautic.campaign.event.timed.choice.anniversary'), + '+P0D' => $this->translator->trans('mautic.campaign.event.timed.choice.today'), + '-P1D' => $this->translator->trans('mautic.campaign.event.timed.choice.yesterday'), + '+P1D' => $this->translator->trans('mautic.campaign.event.timed.choice.tomorrow'), + ]; + + $daysOptions = []; + for ($dayInterval = 2; $dayInterval <= 31; ++$dayInterval) { + $daysOptions['+P'.$dayInterval.'D'] = '+ '.$dayInterval.' days'; + } + + $options = array_merge($options, $daysOptions); + + $beforeDaysOptions = []; + for ($dayInterval = 2; $dayInterval <= 31; ++$dayInterval) { + $beforeDaysOptions['-P'.$dayInterval.'D'] = $dayInterval.' days before'; + } + + $options = array_merge($options, $beforeDaysOptions); + + return $options; + } } diff --git a/app/bundles/LeadBundle/Translations/en_US/messages.ini b/app/bundles/LeadBundle/Translations/en_US/messages.ini index 04a11fa6307..83e285f358a 100755 --- a/app/bundles/LeadBundle/Translations/en_US/messages.ini +++ b/app/bundles/LeadBundle/Translations/en_US/messages.ini @@ -291,6 +291,7 @@ mautic.lead.list.form.operator.notbetween="not between" mautic.lead.list.form.operator.notequals="not equal" mautic.lead.list.form.operator.notin="excluding" mautic.lead.list.frequency.number="Do not contact more than" +mautic.lead.list.form.operator.date="date" mautic.lead.list.frequency.rules.msg="Frequency Rules have changed" mautic.lead.list.frequency.times="each" mautic.lead.list.header.edit="Edit Segment - %name%" diff --git a/app/bundles/NotificationBundle/Form/Type/ConfigType.php b/app/bundles/NotificationBundle/Form/Type/ConfigType.php index 9f1ffcfe3c8..0f1f9582f99 100644 --- a/app/bundles/NotificationBundle/Form/Type/ConfigType.php +++ b/app/bundles/NotificationBundle/Form/Type/ConfigType.php @@ -37,7 +37,6 @@ public function buildForm(FormBuilderInterface $builder, array $options) ] ); - $builder->add( 'notification_landing_page_enabled', 'yesno_button_group', diff --git a/app/bundles/NotificationBundle/Views/Notification/preview.html.php b/app/bundles/NotificationBundle/Views/Notification/preview.html.php index 3fa711fea02..f29204e1333 100644 --- a/app/bundles/NotificationBundle/Views/Notification/preview.html.php +++ b/app/bundles/NotificationBundle/Views/Notification/preview.html.php @@ -8,7 +8,7 @@ * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html */ /* @var \Mautic\NotificationBundle\Entity\Notification $notification */ -$url = $notification->getUrl(); +$url = $notification->getUrl(); $button = $notification->getButton(); ?> diff --git a/plugins/MauticFocusBundle/Helper/TokenHelper.php b/plugins/MauticFocusBundle/Helper/TokenHelper.php index 9f7efc4497b..c98a61aa654 100644 --- a/plugins/MauticFocusBundle/Helper/TokenHelper.php +++ b/plugins/MauticFocusBundle/Helper/TokenHelper.php @@ -14,13 +14,11 @@ use MauticPlugin\MauticFocusBundle\Model\FocusModel; use Symfony\Component\Routing\RouterInterface; - /** * Class TokenHelper. */ class TokenHelper { - private $regex = '{focus=(.*?)}'; /** @@ -50,7 +48,7 @@ public function __construct(FocusModel $model, RouterInterface $router) */ public function findFocusTokens($content) { - $regex = '/'.$this->regex.'/i'; + $regex = '/'.$this->regex.'/i'; preg_match_all($regex, $content, $matches); @@ -78,6 +76,7 @@ public function findFocusTokens($content) } } } + return $tokens; } }