operation in the segment field's value

chriphil

Member
Hi,
I try to send a mail to subscribers who didn't login to thier interface since 20 days.
I can see that we can specify [DATE] in the value of a field in a segment.
Is there any way to do something like :

LASTVISIT < [DATE] - 20D

and then attach this segment to a recurring campaign.

Regards,
JC
 
Hi,

I reply to myself just for those who are interested by this kind of feature.

in /apps/common/models/ListSegmentCondition.php line 181
Code:
    public static function _parseDateValueTag($data, $value, $condition)
    {
        $switch_time = array(
            'D' => 'day',
            'W' => 'week',
            'M' => 'month',
            'Y' => 'year'
        );

        if (preg_match("/\[DATE\]\s*(?P<operator>[-+])\s*(?P<nb>[0-9]+)(?P<switch_time>[DMWY])$/", $value, $matches)) {
            $timestamp = strtotime($matches['operator'].$matches['nb']." ".$switch_time[$matches['switch_time']]);
            return date('Y-m-d', $timestamp);
        } elseif ($data['tag'] != $value) {
            return $value;
        }
        return str_replace($data['tag'], date('Y-m-d'), $value);
    }

To improve, $switch_time should go in the head of the class as a private var in order to be used also in _parseDatetimeValueTag.

You can now specify a value such as '[DATE] + 1W' or '[DATE] - 2Y'.
Only one operator is allowed.

Regards,
JC
 
Back
Top