Initial commit
This commit is contained in:
+145
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
namespace FluentCrm\App\Services\Funnel\Benchmarks;
|
||||
|
||||
use FluentCrm\App\Services\Funnel\BaseBenchMark;
|
||||
use FluentCrm\App\Services\Funnel\FunnelProcessor;
|
||||
use FluentCrm\Framework\Support\Arr;
|
||||
|
||||
class ListAppliedBenchmark extends BaseBenchMark
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->triggerName = 'fluentcrm_contact_added_to_lists';
|
||||
$this->actionArgNum = 2;
|
||||
$this->priority = 20;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getBlock()
|
||||
{
|
||||
return [
|
||||
'title' => __('List Applied', 'fluent-crm'),
|
||||
'description' => __('This will run when selected lists have been applied to a contact', 'fluent-crm'),
|
||||
'icon' => 'fc-icon-list_applied_2',//fluentCrmMix('images/funnel_icons/list_applied.svg'),
|
||||
'settings' => [
|
||||
'lists' => [],
|
||||
'select_type' => 'any',
|
||||
'type' => 'optional',
|
||||
'can_enter' => 'yes'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function getDefaultSettings()
|
||||
{
|
||||
return [
|
||||
'lists' => [],
|
||||
'select_type' => 'any',
|
||||
'type' => 'optional',
|
||||
'can_enter' => 'yes'
|
||||
];
|
||||
}
|
||||
|
||||
public function getBlockFields($funnel)
|
||||
{
|
||||
return [
|
||||
'title' => __('List Applied', 'fluent-crm'),
|
||||
'sub_title' => __('This will run when selected lists have been applied to a contact', 'fluent-crm'),
|
||||
'fields' => [
|
||||
'lists' => [
|
||||
'type' => 'option_selectors',
|
||||
'option_key' => 'lists',
|
||||
'is_multiple' => true,
|
||||
'label' => __('Select Lists', 'fluent-crm'),
|
||||
'placeholder' => __('Select List', 'fluent-crm'),
|
||||
'creatable' => true
|
||||
],
|
||||
'select_type' => [
|
||||
'label' => __('Run When', 'fluent-crm'),
|
||||
'type' => 'radio',
|
||||
'options' => [
|
||||
[
|
||||
'id' => 'any',
|
||||
'title' => __('contact added in any of the selected Lists', 'fluent-crm')
|
||||
],
|
||||
[
|
||||
'id' => 'all',
|
||||
'title' => __('contact added in all of the selected lists', 'fluent-crm')
|
||||
]
|
||||
],
|
||||
'dependency' => [
|
||||
'depends_on' => 'lists',
|
||||
'operator' => '!=',
|
||||
'value' => []
|
||||
]
|
||||
],
|
||||
'type' => $this->benchmarkTypeField(),
|
||||
'can_enter' => $this->canEnterField()
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function handle($benchMark, $originalArgs)
|
||||
{
|
||||
$listIds = $originalArgs[0];
|
||||
$subscriber = $originalArgs[1];
|
||||
$settings = $benchMark->settings;
|
||||
|
||||
$benchmarkLists = Arr::get($settings, 'lists', []);
|
||||
|
||||
// Gate on the lists actually applied in this event. Without this a contact
|
||||
// who already belongs to the benchmark list would advance past the benchmark
|
||||
// on any unrelated list-add event.
|
||||
if (!$benchmarkLists || !array_intersect((array) $listIds, $benchmarkLists)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$subscriberLists = $subscriber->lists->pluck('id')->toArray();
|
||||
|
||||
if (!$this->isListMatched($subscriberLists, $benchmarkLists, $settings)) {
|
||||
return; // not matched based on condition
|
||||
}
|
||||
|
||||
$funnelProcessor = new FunnelProcessor();
|
||||
$funnelProcessor->startFunnelFromSequencePoint($benchMark, $subscriber);
|
||||
}
|
||||
|
||||
private function isListMatched($subscriberLists, $benchmarkLists, $settings)
|
||||
{
|
||||
$matchType = Arr::get($settings, 'select_type');
|
||||
|
||||
if (empty($benchmarkLists)) {
|
||||
return false;
|
||||
}
|
||||
// find common elements between the two arrays
|
||||
$intersection = array_intersect($benchmarkLists, $subscriberLists);
|
||||
|
||||
if ($matchType === 'any') {
|
||||
// At least one funnel list id is available.
|
||||
$isMatched = !empty($intersection);
|
||||
} else {
|
||||
// All of the funnel list ids are present.
|
||||
$isMatched = count($intersection) === count($settings['lists']);
|
||||
}
|
||||
|
||||
return $isMatched;
|
||||
}
|
||||
|
||||
public function assertCurrentGoalState($asserted, $benchmark, $funnelSubscriber)
|
||||
{
|
||||
if (!$funnelSubscriber || !$funnelSubscriber->subscriber) {
|
||||
return $asserted;
|
||||
}
|
||||
|
||||
$subscriberLists = $funnelSubscriber->subscriber->lists->pluck('id')->toArray();
|
||||
$benchamrkLists = Arr::get($benchmark->settings, 'lists', []);
|
||||
|
||||
|
||||
$benchmarkSettings= $benchmark->settings;
|
||||
|
||||
return $this->isListMatched($subscriberLists, $benchamrkLists, $benchmarkSettings);
|
||||
}
|
||||
|
||||
}
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace FluentCrm\App\Services\Funnel\Benchmarks;
|
||||
|
||||
use FluentCrm\App\Services\Funnel\BaseBenchMark;
|
||||
use FluentCrm\App\Services\Funnel\FunnelProcessor;
|
||||
use FluentCrm\Framework\Support\Arr;
|
||||
|
||||
class RemoveFromListBenchmark extends BaseBenchMark
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->triggerName = 'fluentcrm_contact_removed_from_lists';
|
||||
$this->actionArgNum = 2;
|
||||
$this->priority = 40;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getBlock()
|
||||
{
|
||||
return [
|
||||
'title' => __('List Removed', 'fluent-crm'),
|
||||
'description' => __('This will run when selected lists have been removed from a contact', 'fluent-crm'),
|
||||
'icon' => 'fc-icon-list_removed',//fluentCrmMix('images/funnel_icons/list_removed.svg'),
|
||||
'settings' => [
|
||||
'lists' => [],
|
||||
'select_type' => 'any',
|
||||
'type' => 'optional',
|
||||
'can_enter' => 'yes'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function getDefaultSettings()
|
||||
{
|
||||
return [
|
||||
'lists' => [],
|
||||
'select_type' => 'any',
|
||||
'type' => 'optional',
|
||||
'can_enter' => 'yes'
|
||||
];
|
||||
}
|
||||
|
||||
public function getBlockFields($funnel)
|
||||
{
|
||||
return [
|
||||
'title' => __('List Removed From Contact', 'fluent-crm'),
|
||||
'sub_title' => __('This will run when selected lists have been removed from a contact', 'fluent-crm'),
|
||||
'fields' => [
|
||||
'lists' => [
|
||||
'type' => 'option_selectors',
|
||||
'option_key' => 'lists',
|
||||
'is_multiple' => true,
|
||||
'label' => __('Select Lists', 'fluent-crm'),
|
||||
'placeholder' => __('Select List', 'fluent-crm'),
|
||||
'creatable' => true
|
||||
],
|
||||
'select_type' => [
|
||||
'label' => __('Run When', 'fluent-crm'),
|
||||
'type' => 'radio',
|
||||
'options' => [
|
||||
[
|
||||
'id' => 'any',
|
||||
'title' => __('contact removed from any of the selected Lists', 'fluent-crm')
|
||||
],
|
||||
[
|
||||
'id' => 'all',
|
||||
'title' => __('contact removed from all of the selected lists', 'fluent-crm')
|
||||
]
|
||||
],
|
||||
'dependency' => [
|
||||
'depends_on' => 'lists',
|
||||
'operator' => '!=',
|
||||
'value' => []
|
||||
]
|
||||
],
|
||||
'type' => $this->benchmarkTypeField(),
|
||||
'can_enter' => $this->canEnterField()
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function handle($benchMark, $originalArgs)
|
||||
{
|
||||
$listIds = $originalArgs[0];
|
||||
$subscriber = $originalArgs[1];
|
||||
$settings = $benchMark->settings;
|
||||
|
||||
if (!$this->isListMatched($listIds, $subscriber, $settings)) {
|
||||
return; // not matched based on condition
|
||||
}
|
||||
|
||||
$funnelProcessor = new FunnelProcessor();
|
||||
$funnelProcessor->startFunnelFromSequencePoint($benchMark, $subscriber);
|
||||
}
|
||||
|
||||
private function isListMatched($listIds, $subscriber, $settings)
|
||||
{
|
||||
$benchmarkLists = Arr::get($settings, 'lists', []);
|
||||
if (empty($benchmarkLists)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$isMatched = array_intersect($benchmarkLists, $listIds);
|
||||
if (!$isMatched) {
|
||||
return false; // not in our scope
|
||||
}
|
||||
|
||||
$matchType = Arr::get($settings, 'select_type');
|
||||
|
||||
if ($matchType == 'all') {
|
||||
// Check that ALL benchmark lists have been removed (none remain on subscriber)
|
||||
$attachedListIds = $subscriber->lists->pluck('id')->toArray();
|
||||
return empty(array_intersect($benchmarkLists, $attachedListIds));
|
||||
}
|
||||
|
||||
return $isMatched;
|
||||
}
|
||||
|
||||
public function assertCurrentGoalState($asserted, $benchmark, $funnelSubscriber)
|
||||
{
|
||||
if (!$funnelSubscriber || !$funnelSubscriber->subscriber) {
|
||||
return $asserted;
|
||||
}
|
||||
|
||||
$subscriber = $funnelSubscriber->subscriber;
|
||||
$settings = $benchmark->settings;
|
||||
$benchmarkLists = Arr::get($settings, 'lists', []);
|
||||
|
||||
if (empty($benchmarkLists)) {
|
||||
return $asserted;
|
||||
}
|
||||
|
||||
$attachedListIds = $subscriber->lists->pluck('id')->toArray();
|
||||
$matchType = Arr::get($settings, 'select_type');
|
||||
|
||||
if ($matchType == 'all') {
|
||||
return empty(array_intersect($benchmarkLists, $attachedListIds));
|
||||
}
|
||||
|
||||
// 'any' — at least one benchmark list is NOT in subscriber's lists
|
||||
$removed = array_diff($benchmarkLists, $attachedListIds);
|
||||
return !empty($removed);
|
||||
}
|
||||
|
||||
}
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace FluentCrm\App\Services\Funnel\Benchmarks;
|
||||
|
||||
use FluentCrm\App\Services\Funnel\BaseBenchMark;
|
||||
use FluentCrm\App\Services\Funnel\FunnelProcessor;
|
||||
use FluentCrm\Framework\Support\Arr;
|
||||
|
||||
class RemoveFromTagBenchmark extends BaseBenchMark
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->triggerName = 'fluentcrm_contact_removed_from_tags';
|
||||
$this->actionArgNum = 2;
|
||||
$this->priority = 20;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getBlock()
|
||||
{
|
||||
return [
|
||||
'title' => __('Tag Removed', 'fluent-crm'),
|
||||
'description' => __('This will run when selected Tags have been removed from a contact', 'fluent-crm'),
|
||||
'icon' => 'fc-icon-tag_removed',//fluentCrmMix('images/funnel_icons/tag_removed.svg'),
|
||||
'settings' => [
|
||||
'tags' => [],
|
||||
'select_type' => 'any',
|
||||
'type' => 'optional',
|
||||
'can_enter' => 'yes'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function getDefaultSettings()
|
||||
{
|
||||
return [
|
||||
'tags' => [],
|
||||
'select_type' => 'any',
|
||||
'type' => 'optional',
|
||||
'can_enter' => 'yes'
|
||||
];
|
||||
}
|
||||
|
||||
public function getBlockFields($funnel)
|
||||
{
|
||||
return [
|
||||
'title' => __('Tag Removed From Contact', 'fluent-crm'),
|
||||
'sub_title' => __('This will run when selected Tags have been removed from a contact', 'fluent-crm'),
|
||||
'fields' => [
|
||||
'tags' => [
|
||||
'type' => 'option_selectors',
|
||||
'option_key' => 'tags',
|
||||
'is_multiple' => true,
|
||||
'label' => __('Select Tags', 'fluent-crm'),
|
||||
'placeholder' => __('Select a Tag', 'fluent-crm'),
|
||||
'creatable' => true
|
||||
],
|
||||
'select_type' => [
|
||||
'label' => __('Run When', 'fluent-crm'),
|
||||
'type' => 'radio',
|
||||
'options' => [
|
||||
[
|
||||
'id' => 'any',
|
||||
'title' => __('Run if any selected tag removed from a contact', 'fluent-crm')
|
||||
],
|
||||
[
|
||||
'id' => 'all',
|
||||
'title' => __('Need all selected tags removed from the contact', 'fluent-crm')
|
||||
]
|
||||
],
|
||||
'dependency' => [
|
||||
'depends_on' => 'tags',
|
||||
'operator' => '!=',
|
||||
'value' => []
|
||||
]
|
||||
],
|
||||
'type' => $this->benchmarkTypeField(),
|
||||
'can_enter' => $this->canEnterField()
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function handle($benchMark, $originalArgs)
|
||||
{
|
||||
$listIds = $originalArgs[0];
|
||||
$subscriber = $originalArgs[1];
|
||||
$settings = $benchMark->settings;
|
||||
|
||||
if (!$this->isTagMatched($listIds, $subscriber, $settings)) {
|
||||
return; // not matched based on condition
|
||||
}
|
||||
|
||||
$funnelProcessor = new FunnelProcessor();
|
||||
$funnelProcessor->startFunnelFromSequencePoint($benchMark, $subscriber);
|
||||
}
|
||||
|
||||
private function isTagMatched($tagIds, $subscriber, $settings)
|
||||
{
|
||||
$benchmarkTags = Arr::get($settings, 'tags', []);
|
||||
if (empty($benchmarkTags)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$isMatched = array_intersect($benchmarkTags, $tagIds);
|
||||
if (!$isMatched) {
|
||||
return false; // not in our scope
|
||||
}
|
||||
|
||||
$matchType = Arr::get($settings, 'select_type');
|
||||
|
||||
if ($matchType == 'all') {
|
||||
// Check that ALL benchmark tags have been removed (none remain on subscriber)
|
||||
$attachedTagIds = $subscriber->tags->pluck('id')->toArray();
|
||||
return empty(array_intersect($benchmarkTags, $attachedTagIds));
|
||||
}
|
||||
|
||||
return $isMatched;
|
||||
}
|
||||
|
||||
public function assertCurrentGoalState($asserted, $benchmark, $funnelSubscriber)
|
||||
{
|
||||
if (!$funnelSubscriber || !$funnelSubscriber->subscriber) {
|
||||
return $asserted;
|
||||
}
|
||||
|
||||
$subscriber = $funnelSubscriber->subscriber;
|
||||
$settings = $benchmark->settings;
|
||||
$benchmarkTags = Arr::get($settings, 'tags', []);
|
||||
|
||||
if (empty($benchmarkTags)) {
|
||||
return $asserted;
|
||||
}
|
||||
|
||||
$attachedTagIds = $subscriber->tags->pluck('id')->toArray();
|
||||
$matchType = Arr::get($settings, 'select_type');
|
||||
|
||||
if ($matchType == 'all') {
|
||||
return empty(array_intersect($benchmarkTags, $attachedTagIds));
|
||||
}
|
||||
|
||||
// 'any' — at least one benchmark tag is NOT in subscriber's tags
|
||||
$removed = array_diff($benchmarkTags, $attachedTagIds);
|
||||
return !empty($removed);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
namespace FluentCrm\App\Services\Funnel\Benchmarks;
|
||||
|
||||
use FluentCrm\App\Services\Funnel\BaseBenchMark;
|
||||
use FluentCrm\App\Services\Funnel\FunnelProcessor;
|
||||
use FluentCrm\Framework\Support\Arr;
|
||||
|
||||
class TagAppliedBenchmark extends BaseBenchMark
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->triggerName = 'fluentcrm_contact_added_to_tags';
|
||||
$this->actionArgNum = 2;
|
||||
$this->priority = 20;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getBlock()
|
||||
{
|
||||
return [
|
||||
'title' => __('Tag Applied', 'fluent-crm'),
|
||||
'description' => __('This will run when selected Tags have been applied to a contact', 'fluent-crm'),
|
||||
'icon' => 'fc-icon-tag_applied',//fluentCrmMix('images/funnel_icons/tag-applied.svg'),
|
||||
'settings' => [
|
||||
'tags' => [],
|
||||
'select_type' => 'any',
|
||||
'type' => 'optional',
|
||||
'can_enter' => 'yes'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function getDefaultSettings()
|
||||
{
|
||||
return [
|
||||
'tags' => [],
|
||||
'select_type' => 'any',
|
||||
'type' => 'optional',
|
||||
'can_enter' => 'yes'
|
||||
];
|
||||
}
|
||||
|
||||
public function getBlockFields($funnel)
|
||||
{
|
||||
return [
|
||||
'title' => __('Tag Applied', 'fluent-crm'),
|
||||
'sub_title' => __('This will run when selected Tags have been applied to a contact', 'fluent-crm'),
|
||||
'fields' => [
|
||||
'tags' => [
|
||||
'type' => 'option_selectors',
|
||||
'option_key' => 'tags',
|
||||
'creatable' => true,
|
||||
'is_multiple' => true,
|
||||
'label' => __('Select Tags', 'fluent-crm'),
|
||||
'placeholder' => __('Select Tags', 'fluent-crm'),
|
||||
],
|
||||
'select_type' => [
|
||||
'label' => __('Run When', 'fluent-crm'),
|
||||
'type' => 'radio',
|
||||
'options' => [
|
||||
[
|
||||
'id' => 'any',
|
||||
'title' => __('contact added in any of the selected Tags', 'fluent-crm')
|
||||
],
|
||||
[
|
||||
'id' => 'all',
|
||||
'title' => __('contact added in all of the selected Tags', 'fluent-crm')
|
||||
]
|
||||
],
|
||||
'dependency' => [
|
||||
'depends_on' => 'tags',
|
||||
'operator' => '!=',
|
||||
'value' => []
|
||||
]
|
||||
],
|
||||
'type' => $this->benchmarkTypeField(),
|
||||
'can_enter' => $this->canEnterField()
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function handle($benchMark, $originalArgs)
|
||||
{
|
||||
$tagIds = $originalArgs[0];
|
||||
$subscriber = $originalArgs[1];
|
||||
$settings = $benchMark->settings;
|
||||
|
||||
$benchmarkTags = Arr::get($settings, 'tags', []);
|
||||
|
||||
// Gate on the tags actually applied in this event. Without this a contact
|
||||
// who already holds the benchmark tag would advance past the benchmark
|
||||
// on any unrelated tag-add event.
|
||||
if (!$benchmarkTags || !array_intersect((array) $tagIds, $benchmarkTags)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$subscriberTags = $subscriber->tags->pluck('id')->toArray();
|
||||
|
||||
if (!$this->isTagMatched($subscriberTags, $benchmarkTags, $settings)) {
|
||||
return; // not matched based on condition
|
||||
}
|
||||
|
||||
$funnelProcessor = new FunnelProcessor();
|
||||
$funnelProcessor->startFunnelFromSequencePoint($benchMark, $subscriber);
|
||||
}
|
||||
|
||||
private function isTagMatched($subscriberTags, $benchmarkTags, $settings)
|
||||
{
|
||||
$matchType = Arr::get($settings, 'select_type');
|
||||
|
||||
if (empty($benchmarkTags)) {
|
||||
return false;
|
||||
}
|
||||
// find common elements between the two arrays
|
||||
$intersection = array_intersect($benchmarkTags, $subscriberTags);
|
||||
|
||||
if ($matchType === 'any') {
|
||||
// At least one funnel list id is available.
|
||||
$isMatched = !empty($intersection);
|
||||
} else {
|
||||
// All of the funnel list ids are present.
|
||||
$isMatched = count($intersection) === count($settings['tags']);
|
||||
}
|
||||
|
||||
return $isMatched;
|
||||
}
|
||||
|
||||
|
||||
public function assertCurrentGoalState($asserted, $benchmark, $funnelSubscriber)
|
||||
{
|
||||
if (!$funnelSubscriber || !$funnelSubscriber->subscriber) {
|
||||
return $asserted;
|
||||
}
|
||||
|
||||
$subscriberTags = $funnelSubscriber->subscriber->tags->pluck('id')->toArray();
|
||||
$benchmarkTags = Arr::get($benchmark->settings, 'tags', []);
|
||||
|
||||
$benchmarkSettings= $benchmark->settings;
|
||||
|
||||
return $this->isTagMatched($subscriberTags, $benchmarkTags, $benchmarkSettings);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user