Skip to content

Commit

Permalink
Merge branch 'staging' of github.com:mautic/mautic into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhartless committed Jan 2, 2017
2 parents 086e9d1 + 0f5c4b5 commit 7d9ab1b
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 15 deletions.
4 changes: 4 additions & 0 deletions app/bundles/CampaignBundle/Translations/en_US/messages.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ public function onCampaignTriggerAction(CampaignExecutionEvent $event)
$content = $tokenEvent->getContent();
$content = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $content);


$event->stopPropagation();

$result = $event->setResult($content);
Expand Down
7 changes: 6 additions & 1 deletion app/bundles/LeadBundle/Controller/AjaxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 : [];
}
Expand Down
59 changes: 59 additions & 0 deletions app/bundles/LeadBundle/Entity/LeadFieldRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}
6 changes: 6 additions & 0 deletions app/bundles/LeadBundle/Entity/OperatorListTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
54 changes: 47 additions & 7 deletions app/bundles/LeadBundle/EventListener/CampaignSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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']]);
Expand Down Expand Up @@ -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;
Expand Down
31 changes: 31 additions & 0 deletions app/bundles/LeadBundle/Helper/FormFieldHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions app/bundles/LeadBundle/Translations/en_US/messages.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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%"
Expand Down
1 change: 0 additions & 1 deletion app/bundles/NotificationBundle/Form/Type/ConfigType.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public function buildForm(FormBuilderInterface $builder, array $options)
]
);


$builder->add(
'notification_landing_page_enabled',
'yesno_button_group',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

?>
Expand Down
5 changes: 2 additions & 3 deletions plugins/MauticFocusBundle/Helper/TokenHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@
use MauticPlugin\MauticFocusBundle\Model\FocusModel;
use Symfony\Component\Routing\RouterInterface;


/**
* Class TokenHelper.
*/
class TokenHelper
{

private $regex = '{focus=(.*?)}';

/**
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -78,6 +76,7 @@ public function findFocusTokens($content)
}
}
}

return $tokens;
}
}

0 comments on commit 7d9ab1b

Please sign in to comment.