Initial commit
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace FluentCrm\App\Services\Funnel\Actions;
|
||||
|
||||
use FluentCrm\App\Models\Subscriber;
|
||||
use FluentCrm\App\Services\Funnel\BaseAction;
|
||||
use FluentCrm\App\Services\Funnel\FunnelHelper;
|
||||
|
||||
class ApplyCompanyAction extends BaseAction
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->actionName = 'add_contact_to_company';
|
||||
$this->priority = 20;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getBlock()
|
||||
{
|
||||
return [
|
||||
'category' => __('CRM', 'fluent-crm'),
|
||||
'title' => __('Apply Company', 'fluent-crm'),
|
||||
'description' => __('Add contact to the selected company', 'fluent-crm'),
|
||||
'icon' => 'fc-icon-apply_list',//fluentCrmMix('images/funnel_icons/apply_list.svg'),
|
||||
'settings' => [
|
||||
'company' => null
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function getBlockFields()
|
||||
{
|
||||
return [
|
||||
'title' => __('Apply Company to the contact', 'fluent-crm'),
|
||||
'sub_title' => __('Select which list will be added to the contact', 'fluent-crm'),
|
||||
'fields' => [
|
||||
'company' => [
|
||||
'type' => 'option_selectors',
|
||||
'option_key' => 'companies',
|
||||
'label' => __('Select Company', 'fluent-crm'),
|
||||
'placeholder' => __('Select Company', 'fluent-crm')
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function handle($subscriber, $sequence, $funnelSubscriberId, $funnelMetric)
|
||||
{
|
||||
if (empty($sequence->settings['company'])) {
|
||||
FunnelHelper::changeFunnelSubSequenceStatus($funnelSubscriberId, $sequence->id, 'skipped');
|
||||
return;
|
||||
}
|
||||
|
||||
$company = $sequence->settings['company'];
|
||||
|
||||
$renewedSubscriber = Subscriber::where('id', $subscriber->id)->first();
|
||||
if (!$renewedSubscriber) {
|
||||
FunnelHelper::changeFunnelSubSequenceStatus($funnelSubscriberId, $sequence->id, 'skipped');
|
||||
return;
|
||||
}
|
||||
$renewedSubscriber->attachCompanies([$company]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace FluentCrm\App\Services\Funnel\Actions;
|
||||
|
||||
use FluentCrm\App\Models\Subscriber;
|
||||
use FluentCrm\App\Services\Funnel\BaseAction;
|
||||
use FluentCrm\App\Services\Funnel\FunnelHelper;
|
||||
|
||||
class ApplyListAction extends BaseAction
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->actionName = 'add_contact_to_list';
|
||||
$this->priority = 20;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getBlock()
|
||||
{
|
||||
return [
|
||||
'category' => __('CRM', 'fluent-crm'),
|
||||
'title' => __('Apply List', 'fluent-crm'),
|
||||
'description' => __('Add contact to the selected lists', 'fluent-crm'),
|
||||
'icon' => 'fc-icon-apply_list',//fluentCrmMix('images/funnel_icons/apply_list.svg'),
|
||||
'settings' => [
|
||||
'lists' => []
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function getBlockFields()
|
||||
{
|
||||
return [
|
||||
'title' => __('Apply List to the contact', 'fluent-crm'),
|
||||
'sub_title' => __('Select which list will be added to the 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
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function handle($subscriber, $sequence, $funnelSubscriberId, $funnelMetric)
|
||||
{
|
||||
if (empty($sequence->settings['lists']) || !is_array($sequence->settings['lists'])) {
|
||||
FunnelHelper::changeFunnelSubSequenceStatus($funnelSubscriberId, $sequence->id, 'skipped');
|
||||
return;
|
||||
}
|
||||
|
||||
$lists = $sequence->settings['lists'];
|
||||
|
||||
$renewedSubscriber = Subscriber::where('id', $subscriber->id)->first();
|
||||
if (!$renewedSubscriber) {
|
||||
FunnelHelper::changeFunnelSubSequenceStatus($funnelSubscriberId, $sequence->id, 'skipped');
|
||||
return;
|
||||
}
|
||||
$renewedSubscriber->attachLists($lists);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace FluentCrm\App\Services\Funnel\Actions;
|
||||
|
||||
use FluentCrm\App\Models\Subscriber;
|
||||
use FluentCrm\App\Services\Funnel\BaseAction;
|
||||
use FluentCrm\App\Services\Funnel\FunnelHelper;
|
||||
|
||||
class ApplyTagAction extends BaseAction
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->actionName = 'add_contact_to_tag';
|
||||
$this->priority = 21;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getBlock()
|
||||
{
|
||||
return [
|
||||
'category' => __('CRM', 'fluent-crm'),
|
||||
'title' => __('Apply Tag', 'fluent-crm'),
|
||||
'description' => __('Add this contact to the selected Tags', 'fluent-crm'),
|
||||
'icon' => 'fc-icon-apply_tag',//fluentCrmMix('images/funnel_icons/apply_tag.svg'),
|
||||
'settings' => [
|
||||
'tags' => []
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function getBlockFields()
|
||||
{
|
||||
return [
|
||||
'title' => __('Apply Tag to the contact', 'fluent-crm'),
|
||||
'sub_title' => __('Select which tag will be added to the contact', 'fluent-crm'),
|
||||
'fields' => [
|
||||
'tags' => [
|
||||
'type' => 'option_selectors',
|
||||
'option_key' => 'tags',
|
||||
'is_multiple' => true,
|
||||
'creatable' => true,
|
||||
'label' => __('Select Tags', 'fluent-crm'),
|
||||
'placeholder' => __('Select Tag', 'fluent-crm')
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function handle($subscriber, $sequence, $funnelSubscriberId, $funnelMetric)
|
||||
{
|
||||
if (empty($sequence->settings['tags']) || !is_array($sequence->settings['tags'])) {
|
||||
FunnelHelper::changeFunnelSubSequenceStatus($funnelSubscriberId, $sequence->id, 'skipped');
|
||||
return;
|
||||
}
|
||||
|
||||
$tags = $sequence->settings['tags'];
|
||||
$renewedSubscriber = Subscriber::where('id', $subscriber->id)->first();
|
||||
if (!$renewedSubscriber) {
|
||||
FunnelHelper::changeFunnelSubSequenceStatus($funnelSubscriberId, $sequence->id, 'skipped');
|
||||
return;
|
||||
}
|
||||
$renewedSubscriber->attachTags($tags);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace FluentCrm\App\Services\Funnel\Actions;
|
||||
|
||||
use FluentCrm\App\Models\Subscriber;
|
||||
use FluentCrm\App\Services\Funnel\BaseAction;
|
||||
use FluentCrm\App\Services\Funnel\FunnelHelper;
|
||||
|
||||
class DetachCompanyAction extends BaseAction
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->actionName = 'detach_contact_from_company';
|
||||
$this->priority = 22;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getBlock()
|
||||
{
|
||||
return [
|
||||
'category' => __('CRM', 'fluent-crm'),
|
||||
'title' => __('Remove From Company', 'fluent-crm'),
|
||||
'description' => __('Remove this contact from the selected company', 'fluent-crm'),
|
||||
'icon' => 'fc-icon-removed_list',//fluentCrmMix('images/funnel_icons/list_remove.svg'),
|
||||
'settings' => [
|
||||
'company' => null
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function getBlockFields()
|
||||
{
|
||||
return [
|
||||
'title' => __('Remove Contact from the Selected Company', 'fluent-crm'),
|
||||
'sub_title' => __('Select Company that you want to remove from targeted Contact', 'fluent-crm'),
|
||||
'fields' => [
|
||||
'company' => [
|
||||
'type' => 'option_selectors',
|
||||
'option_key' => 'companies',
|
||||
'label' => __('Select Company', 'fluent-crm'),
|
||||
'placeholder' => __('Select Company', 'fluent-crm'),
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function handle($subscriber, $sequence, $funnelSubscriberId, $funnelMetric)
|
||||
{
|
||||
if (empty($sequence->settings['company'])) {
|
||||
FunnelHelper::changeFunnelSubSequenceStatus($funnelSubscriberId, $sequence->id, 'skipped');
|
||||
return;
|
||||
}
|
||||
|
||||
$company = $sequence->settings['company'];
|
||||
|
||||
$renewedSubscriber = Subscriber::where('id', $subscriber->id)->first();
|
||||
if (!$renewedSubscriber) {
|
||||
FunnelHelper::changeFunnelSubSequenceStatus($funnelSubscriberId, $sequence->id, 'skipped');
|
||||
return;
|
||||
}
|
||||
$renewedSubscriber->detachCompanies([$company]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace FluentCrm\App\Services\Funnel\Actions;
|
||||
|
||||
use FluentCrm\App\Models\Subscriber;
|
||||
use FluentCrm\App\Services\Funnel\BaseAction;
|
||||
use FluentCrm\App\Services\Funnel\FunnelHelper;
|
||||
|
||||
class DetachListAction extends BaseAction
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->actionName = 'detach_contact_from_list';
|
||||
$this->priority = 22;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getBlock()
|
||||
{
|
||||
return [
|
||||
'category' => __('CRM', 'fluent-crm'),
|
||||
'title' => __('Remove From List', 'fluent-crm'),
|
||||
'description' => __('Remove this contact from the selected lists', 'fluent-crm'),
|
||||
'icon' => 'fc-icon-removed_list',//fluentCrmMix('images/funnel_icons/list_remove.svg'),
|
||||
'settings' => [
|
||||
'lists' => []
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function getBlockFields()
|
||||
{
|
||||
return [
|
||||
'title' => __('Remove Contact from the Selected Lists', 'fluent-crm'),
|
||||
'sub_title' => __('Select Lists that you want to remove from targeted 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
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function handle($subscriber, $sequence, $funnelSubscriberId, $funnelMetric)
|
||||
{
|
||||
if (empty($sequence->settings['lists']) || !is_array($sequence->settings['lists'])) {
|
||||
FunnelHelper::changeFunnelSubSequenceStatus($funnelSubscriberId, $sequence->id, 'skipped');
|
||||
return;
|
||||
}
|
||||
|
||||
$lists = $sequence->settings['lists'];
|
||||
|
||||
$renewedSubscriber = Subscriber::where('id', $subscriber->id)->first();
|
||||
if (!$renewedSubscriber) {
|
||||
FunnelHelper::changeFunnelSubSequenceStatus($funnelSubscriberId, $sequence->id, 'skipped');
|
||||
return;
|
||||
}
|
||||
$renewedSubscriber->detachLists($lists);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace FluentCrm\App\Services\Funnel\Actions;
|
||||
|
||||
use FluentCrm\App\Models\Subscriber;
|
||||
use FluentCrm\App\Services\Funnel\BaseAction;
|
||||
use FluentCrm\App\Services\Funnel\FunnelHelper;
|
||||
|
||||
class DetachTagAction extends BaseAction
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->actionName = 'detach_contact_from_tag';
|
||||
$this->priority = 23;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getBlock()
|
||||
{
|
||||
return [
|
||||
'category' => __('CRM', 'fluent-crm'),
|
||||
'title' => __('Remove From Tag', 'fluent-crm'),
|
||||
'description' => __('Remove this contact from the selected Tags', 'fluent-crm'),
|
||||
'icon' => 'fc-icon-tag_removed',//fluentCrmMix('images/funnel_icons/tag_remove.svg'),
|
||||
'settings' => [
|
||||
'tags' => []
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function getBlockFields()
|
||||
{
|
||||
return [
|
||||
'title' => __('Remove Contact from the Selected Tags', 'fluent-crm'),
|
||||
'sub_title' => __('Select Tags that you want to remove from targeted Contact', 'fluent-crm'),
|
||||
'fields' => [
|
||||
'tags' => [
|
||||
'type' => 'option_selectors',
|
||||
'option_key' => 'tags',
|
||||
'is_multiple' => true,
|
||||
'label' => __('Select Tags', 'fluent-crm'),
|
||||
'placeholder' => __('Select Tag', 'fluent-crm'),
|
||||
'creatable' => true
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function handle($subscriber, $sequence, $funnelSubscriberId, $funnelMetric)
|
||||
{
|
||||
if (empty($sequence->settings['tags']) || !is_array($sequence->settings['tags'])) {
|
||||
FunnelHelper::changeFunnelSubSequenceStatus($funnelSubscriberId, $sequence->id, 'skipped');
|
||||
return;
|
||||
}
|
||||
|
||||
$tags = $sequence->settings['tags'];
|
||||
|
||||
$renewedSubscriber = Subscriber::where('id', $subscriber->id)->first();
|
||||
if (!$renewedSubscriber) {
|
||||
FunnelHelper::changeFunnelSubSequenceStatus($funnelSubscriberId, $sequence->id, 'skipped');
|
||||
return;
|
||||
}
|
||||
$renewedSubscriber->detachTags($tags);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,279 @@
|
||||
<?php
|
||||
|
||||
namespace FluentCrm\App\Services\Funnel\Actions;
|
||||
|
||||
use FluentCrm\App\Models\CampaignEmail;
|
||||
use FluentCrm\App\Models\CampaignUrlMetric;
|
||||
use FluentCrm\App\Models\FunnelCampaign;
|
||||
use FluentCrm\App\Services\Funnel\BaseAction;
|
||||
use FluentCrm\App\Services\Funnel\FunnelHelper;
|
||||
use FluentCrm\Framework\Support\Arr;
|
||||
|
||||
class SendEmailAction extends BaseAction
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->actionName = 'send_custom_email';
|
||||
$this->priority = 10;
|
||||
parent::__construct();
|
||||
add_filter('fluentcrm_funnel_sequence_saving_' . $this->actionName, array($this, 'savingAction'), 10, 2);
|
||||
add_filter('fluentcrm_funnel_sequence_deleting_' . $this->actionName, array($this, 'deleteAction'), 10, 2);
|
||||
add_filter('fluentcrm_funnel_sequence_filtered_' . $this->actionName, array($this, 'gettingAction'), 10, 2);
|
||||
}
|
||||
|
||||
public function getBlock()
|
||||
{
|
||||
return [
|
||||
'category' => __('Email', 'fluent-crm'),
|
||||
'title' => __('Send Custom Email', 'fluent-crm'),
|
||||
'description' => __('Send a custom Email to your subscriber or custom email address', 'fluent-crm'),
|
||||
'icon' => 'fc-icon-send_campaign',//fluentCrmMix('images/funnel_icons/custom_email.svg'),
|
||||
'settings' => [
|
||||
'reference_campaign' => '',
|
||||
'send_email_to_type' => 'contact',
|
||||
'send_email_custom' => '',
|
||||
'campaign' => FunnelCampaign::getMock(),
|
||||
'is_scheduled' => 'no',
|
||||
'scheduled_at' => '',
|
||||
'skip_if_overdue' => 'no',
|
||||
'mailer_settings' => [
|
||||
'from_name' => '',
|
||||
'from_email' => '',
|
||||
'reply_to_name' => '',
|
||||
'reply_to_email' => '',
|
||||
'is_custom' => 'no'
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function getBlockFields()
|
||||
{
|
||||
return [
|
||||
'title' => __('Send Custom Email', 'fluent-crm'),
|
||||
'sub_title' => __('Please provide email details that you want to send', 'fluent-crm'),
|
||||
'fields' => [
|
||||
'send_email_to_type' => [
|
||||
'type' => 'radio',
|
||||
'wrapper_class' => 'fc_half_field',
|
||||
'label' => __('Send Email to', 'fluent-crm'),
|
||||
'options' => [
|
||||
[
|
||||
'id' => 'contact',
|
||||
'title' => __('Send To the contact', 'fluent-crm')
|
||||
],
|
||||
[
|
||||
'id' => 'custom',
|
||||
'title' => __('Send to Custom Email Address', 'fluent-crm')
|
||||
]
|
||||
]
|
||||
],
|
||||
'send_email_custom' => [
|
||||
'wrapper_class' => 'fcrm_send_custom_email_form_wrap',
|
||||
'type' => 'input-text',
|
||||
'label' => __('Send To Email Addresses (If Custom)', 'fluent-crm'),
|
||||
'placeholder' => __('Custom Email Addresses', 'fluent-crm'),
|
||||
'inline_help' => __('Use comma separated values for multiple', 'fluent-crm'),
|
||||
'dependency' => [
|
||||
'depends_on' => 'send_email_to_type',
|
||||
'operator' => '=',
|
||||
'value' => 'custom'
|
||||
]
|
||||
],
|
||||
'campaign' => [
|
||||
'label' => '',
|
||||
'wrapper_class' => 'fc_email_writer',
|
||||
'type' => 'email_campaign_composer'
|
||||
],
|
||||
'is_scheduled' => [
|
||||
'type' => 'yes_no_check',
|
||||
'check_label' => __('Schedule this email to a specific date', 'fluent-crm'),
|
||||
'wrapper_class' => 'fc_no_pad_l',
|
||||
],
|
||||
'skip_if_overdue' => [
|
||||
'type' => 'yes_no_check',
|
||||
'wrapper_class' => 'fcrm_child_field',
|
||||
'check_label' => __('Skip sending email if date is overdued', 'fluent-crm'),
|
||||
'dependency' => [
|
||||
'depends_on' => 'is_scheduled',
|
||||
'operator' => '=',
|
||||
'value' => 'yes'
|
||||
]
|
||||
],
|
||||
'scheduled_at' => [
|
||||
'label' => __('Schedule Date and Time', 'fluent-crm'),
|
||||
'type' => 'date_time',
|
||||
'wrapper_class' => 'fcrm_child_field fcrm_schedule_date_time fc_no_marg_b',
|
||||
'placeholder' => __('Select Date and Time', 'fluent-crm'),
|
||||
'inline_help' => __('If schedule date is past in the runtime then email will be sent immediately', 'fluent-crm'),
|
||||
'dependency' => [
|
||||
'depends_on' => 'is_scheduled',
|
||||
'operator' => '=',
|
||||
'value' => 'yes'
|
||||
]
|
||||
],
|
||||
'mailer_settings' => [
|
||||
'type' => 'custom_sender_config',
|
||||
'check_label' => __('Set Custom From Name and Email', 'fluent-crm')
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function savingAction($sequence, $funnel)
|
||||
{
|
||||
$funnelCampaign = Arr::get($sequence, 'settings.campaign', []);
|
||||
$funnelCampaignId = Arr::get($funnelCampaign, 'id');
|
||||
|
||||
$isStripped = Arr::get($sequence, 'is_stripped');
|
||||
if ($isStripped && $funnelCampaignId) {
|
||||
$refCampaign = FunnelCampaign::find($funnelCampaignId);
|
||||
if (!$refCampaign) {
|
||||
return $sequence;
|
||||
}
|
||||
$data = Arr::only($refCampaign->toArray(), array_keys(FunnelCampaign::getMock()));
|
||||
} else {
|
||||
$data = Arr::only($funnelCampaign, array_keys(FunnelCampaign::getMock()));
|
||||
}
|
||||
|
||||
$sequenceId = Arr::get($sequence, 'id');
|
||||
$data['settings']['mailer_settings'] = Arr::get($sequence, 'settings.mailer_settings', []);
|
||||
|
||||
if ($funnelCampaignId && $funnel->id == Arr::get($data, 'parent_id')) {
|
||||
// We have this campaign
|
||||
$data['settings'] = \maybe_serialize($data['settings']);
|
||||
$data['type'] = 'funnel_email_campaign';
|
||||
$data['title'] = $funnel->title . ' (' . $funnel->id . ' - ' . $sequenceId . ')';
|
||||
FunnelCampaign::where('id', $funnelCampaignId)->update($data);
|
||||
} else {
|
||||
$data['parent_id'] = $funnel->id;
|
||||
$data['type'] = 'funnel_email_campaign';
|
||||
$data['title'] = $funnel->title . ' (' . $funnel->id . ' - ' . $sequenceId . ')';
|
||||
$campaign = FunnelCampaign::create($data);
|
||||
$funnelCampaignId = $campaign->id;
|
||||
|
||||
if ($data['design_template'] == 'visual_builder' && !empty($funnelCampaign['_visual_builder_design'])) {
|
||||
fluentcrm_update_campaign_meta($funnelCampaignId, '_visual_builder_design', $funnelCampaign['_visual_builder_design']);
|
||||
}
|
||||
}
|
||||
|
||||
$sequence['settings']['reference_campaign'] = $funnelCampaignId;
|
||||
$sequence['settings']['campaign'] = [];
|
||||
return $sequence;
|
||||
}
|
||||
|
||||
public function gettingAction($sequence, $funnel)
|
||||
{
|
||||
$refCampaignData = FunnelCampaign::getMock();
|
||||
if ($refCampaignId = Arr::get($sequence, 'settings.reference_campaign')) {
|
||||
$refCampaign = FunnelCampaign::find($refCampaignId);
|
||||
if ($refCampaign) {
|
||||
$refCampaignData = Arr::only($refCampaign->toArray(), array_keys(FunnelCampaign::getMock()));
|
||||
|
||||
if ($refCampaignData['design_template'] == 'visual_builder') {
|
||||
$refCampaignData['_visual_builder_design'] = fluentcrm_get_campaign_meta($refCampaignData['id'], '_visual_builder_design', true);
|
||||
} else {
|
||||
$refCampaignData['__fcrm_block_type'] = 'email_body_in_funnel';
|
||||
}
|
||||
$sequence['settings']['campaign'] = $refCampaignData;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($sequence['settings']['mailer_settings'])) {
|
||||
$sequence['settings']['mailer_settings'] = [
|
||||
'from_name' => '',
|
||||
'from_email' => '',
|
||||
'reply_to_name' => '',
|
||||
'reply_to_email' => '',
|
||||
'is_custom' => 'no'
|
||||
];
|
||||
}
|
||||
|
||||
return $sequence;
|
||||
}
|
||||
|
||||
public function deleteAction($sequence, $funnel)
|
||||
{
|
||||
$refCampaign = Arr::get($sequence->settings, 'reference_campaign');
|
||||
if ($refCampaign) {
|
||||
FunnelCampaign::where('id', $refCampaign)->delete();
|
||||
CampaignEmail::where('campaign_id', $refCampaign)->delete();
|
||||
CampaignUrlMetric::where('campaign_id', $refCampaign)->delete();
|
||||
fluentcrm_delete_campaign_meta($refCampaign, '');
|
||||
}
|
||||
}
|
||||
|
||||
public function handle($subscriber, $sequence, $funnelSubscriberId, $funnelMetric)
|
||||
{
|
||||
$settings = $sequence->settings;
|
||||
$refCampaign = Arr::get($settings, 'reference_campaign');
|
||||
|
||||
if (!$refCampaign) {
|
||||
FunnelHelper::changeFunnelSubSequenceStatus($funnelSubscriberId, $sequence->id, 'skipped');
|
||||
return;
|
||||
}
|
||||
|
||||
if ($funnelMetric) {
|
||||
// We are making sure, this action will run only once per funnel subscriber
|
||||
if (did_action('fluent_crm/did_run_funnel_email_action_' . $funnelMetric->id)) {
|
||||
FunnelHelper::changeFunnelSubSequenceStatus($funnelSubscriberId, $sequence->id, 'skipped');
|
||||
return;
|
||||
}
|
||||
|
||||
do_action('fluent_crm/did_run_funnel_email_action_' . $funnelMetric->id);
|
||||
}
|
||||
|
||||
$campaign = FunnelCampaign::find($refCampaign);
|
||||
if (!$campaign) {
|
||||
FunnelHelper::changeFunnelSubSequenceStatus($funnelSubscriberId, $sequence->id, 'skipped');
|
||||
return;
|
||||
}
|
||||
|
||||
$scheduledAt = current_time('mysql');
|
||||
if (Arr::get($settings, 'is_scheduled') == 'yes') {
|
||||
$providedDate = Arr::get($settings, 'scheduled_at');
|
||||
|
||||
if ($providedDate && Arr::get($settings, 'skip_if_overdue') == 'yes') {
|
||||
if (strtotime($scheduledAt) > strtotime($providedDate)) {
|
||||
FunnelHelper::changeFunnelSubSequenceStatus($funnelSubscriberId, $sequence->id, 'skipped');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ($providedDate && strtotime($providedDate) > strtotime($scheduledAt)) {
|
||||
$scheduledAt = $providedDate;
|
||||
}
|
||||
}
|
||||
|
||||
$args = [
|
||||
'status' => 'scheduled',
|
||||
'scheduled_at' => $scheduledAt,
|
||||
'email_type' => 'funnel_email_campaign',
|
||||
'note' => __('Email Sent From Funnel: ', 'fluent-crm') . $campaign->title
|
||||
];
|
||||
|
||||
if (Arr::get($settings, 'send_email_to_type') == 'contact') {
|
||||
$campaign->processAndSubscribe($subscriber, [
|
||||
'funnel_subscriber_id' => $funnelSubscriberId
|
||||
], $args);
|
||||
|
||||
do_action('fluentcrm_process_contact_jobs', $subscriber);
|
||||
} else if ($customAddresses = Arr::get($settings, 'send_email_custom')) {
|
||||
/**
|
||||
* Filters and parses custom email addresses for a campaign email text.
|
||||
*
|
||||
* This code applies the 'fluent_crm/parse_campaign_email_text' filter to process
|
||||
* the custom email addresses for a given subscriber.
|
||||
*
|
||||
* @param string $customAddresses The custom email addresses string to be parsed.
|
||||
* @param object $subscriber The subscriber object containing subscriber details.
|
||||
*
|
||||
* @return string The filtered and parsed custom email addresses string.
|
||||
*/
|
||||
|
||||
$customAddresses = apply_filters('fluent_crm/parse_campaign_email_text', $customAddresses, $subscriber);
|
||||
$customAddresses = array_filter(array_map('sanitize_email', explode(',', $customAddresses)));
|
||||
$campaign->sendToCustomAddresses($customAddresses, $args, $subscriber);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
<?php
|
||||
|
||||
namespace FluentCrm\App\Services\Funnel\Actions;
|
||||
|
||||
use FluentCrm\App\Services\Funnel\BaseAction;
|
||||
use FluentCrm\Framework\Support\Arr;
|
||||
|
||||
class WaitTimeAction extends BaseAction
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->actionName = 'fluentcrm_wait_times';
|
||||
$this->priority = 10;
|
||||
parent::__construct();
|
||||
|
||||
add_filter('fluentcrm_funnel_sequence_filtered_' . $this->actionName, array($this, 'gettingAction'), 10, 2);
|
||||
}
|
||||
|
||||
public function getBlock()
|
||||
{
|
||||
return [
|
||||
'category' => __('CRM', 'fluent-crm'),
|
||||
'title' => __('Wait X Days/Hours', 'fluent-crm'),
|
||||
'description' => __('Wait defined timespan before execute the next action', 'fluent-crm'),
|
||||
'icon' => 'fc-icon-wait_time',
|
||||
'settings' => [
|
||||
'wait_type' => 'unit_wait',
|
||||
'wait_time_amount' => '',
|
||||
'wait_time_unit' => 'days',
|
||||
'is_timestamp_wait' => '',
|
||||
'wait_date_time' => '',
|
||||
'to_day' => [],
|
||||
'to_day_time' => ''
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function gettingAction($sequence, $funnel)
|
||||
{
|
||||
if (empty($sequence['settings']['wait_type'])) {
|
||||
if (Arr::get($sequence, 'settings.is_timestamp_wait') == 'yes') {
|
||||
$sequence['settings']['wait_type'] = 'timestamp_wait';
|
||||
} else {
|
||||
$sequence['settings']['wait_type'] = 'unit_wait';
|
||||
}
|
||||
|
||||
$sequence['settings']['to_day'] = [];
|
||||
$sequence['settings']['to_day_time'] = '';
|
||||
}
|
||||
|
||||
if (!empty($sequence['settings']['to_day'])) {
|
||||
$sequence['settings']['to_day'] = array_map(function ($day) {
|
||||
return substr($day, 0, 3);
|
||||
}, $sequence['settings']['to_day']);
|
||||
}
|
||||
|
||||
return $sequence;
|
||||
}
|
||||
|
||||
public function getBlockFields()
|
||||
{
|
||||
|
||||
$customFields = FluentCrmApi('contacts')->getCustomFields(['date_time', 'date'], true);
|
||||
|
||||
// add date of birth field at the beginning
|
||||
array_unshift($customFields, [
|
||||
'id' => '__date_of_birth__',
|
||||
'title' => __('Contact\'s Next Date of Birth', 'fluent-crm')
|
||||
]);
|
||||
|
||||
return [
|
||||
'title' => __('Wait X Days/Hours', 'fluent-crm'),
|
||||
'sub_title' => __('Wait defined timespan before execute the next action', 'fluent-crm'),
|
||||
'fields' => [
|
||||
'wait_type' => [
|
||||
'type' => 'radio_buttons',
|
||||
'label' => __('Waiting Type', 'fluent-crm'),
|
||||
'options' => [
|
||||
[
|
||||
'id' => 'unit_wait',
|
||||
'title' => __('Wait by period', 'fluent-crm')
|
||||
],
|
||||
[
|
||||
'id' => 'timestamp_wait',
|
||||
'title' => __('Wait Until Date', 'fluent-crm')
|
||||
],
|
||||
[
|
||||
'id' => 'to_day',
|
||||
'title' => __('Wait by Weekday', 'fluent-crm')
|
||||
],
|
||||
[
|
||||
'id' => 'by_custom_field',
|
||||
'title' => __('Wait by Custom Field', 'fluent-crm')
|
||||
]
|
||||
]
|
||||
],
|
||||
'wait_time_amount' => [
|
||||
'label' => __('Wait Time', 'fluent-crm'),
|
||||
'type' => 'input-number',
|
||||
'wrapper_class' => 'fc_2col_inline pad-r-20',
|
||||
'dependency' => [
|
||||
'depends_on' => 'wait_type',
|
||||
'value' => 'unit_wait',
|
||||
'operator' => '=',
|
||||
],
|
||||
],
|
||||
'wait_time_unit' => [
|
||||
'label' => __('Wait Time Unit', 'fluent-crm'),
|
||||
'type' => 'select',
|
||||
'wrapper_class' => 'fc_2col_inline',
|
||||
'options' => [
|
||||
[
|
||||
'id' => 'months',
|
||||
'title' => __('Months', 'fluent-crm')
|
||||
],
|
||||
[
|
||||
'id' => 'days',
|
||||
'title' => __('Days', 'fluent-crm')
|
||||
],
|
||||
[
|
||||
'id' => 'hours',
|
||||
'title' => __('Hours', 'fluent-crm')
|
||||
],
|
||||
[
|
||||
'id' => 'minutes',
|
||||
'title' => __('Minutes', 'fluent-crm')
|
||||
]
|
||||
],
|
||||
'dependency' => [
|
||||
'depends_on' => 'wait_type',
|
||||
'value' => 'unit_wait',
|
||||
'operator' => '=',
|
||||
],
|
||||
],
|
||||
'wait_date_time' => [
|
||||
'label' => __('Specify Date and Time', 'fluent-crm'),
|
||||
'type' => 'date_time',
|
||||
'placeholder' => __('Select Date & Time', 'fluent-crm'),
|
||||
'inline_help' => __('Please input date and time and this step will be executed after that time (TimeZone will be as per your WordPress Date Time Zone)', 'fluent-crm'),
|
||||
'dependency' => [
|
||||
'depends_on' => 'wait_type',
|
||||
'value' => 'timestamp_wait',
|
||||
'operator' => '=',
|
||||
]
|
||||
],
|
||||
'to_day' => [
|
||||
'type' => 'checkboxes',
|
||||
'label' => __('Wait until next day(s) of the week', 'fluent-crm'),
|
||||
'wrapper_class' => 'fc_2col_inline pad-r-20',
|
||||
'options' => [
|
||||
[
|
||||
'id' => 'Mon',
|
||||
'title' => __('Mon', 'fluent-crm')
|
||||
],
|
||||
[
|
||||
'id' => 'Tue',
|
||||
'title' => __('Tue', 'fluent-crm')
|
||||
],
|
||||
[
|
||||
'id' => 'Wed',
|
||||
'title' => __('Wed', 'fluent-crm')
|
||||
],
|
||||
[
|
||||
'id' => 'Thu',
|
||||
'title' => __('Thu', 'fluent-crm')
|
||||
],
|
||||
[
|
||||
'id' => 'Fri',
|
||||
'title' => __('Fri', 'fluent-crm')
|
||||
],
|
||||
[
|
||||
'id' => 'Sat',
|
||||
'title' => __('Sat', 'fluent-crm')
|
||||
],
|
||||
[
|
||||
'id' => 'Sun',
|
||||
'title' => __('Sun', 'fluent-crm')
|
||||
]
|
||||
],
|
||||
'dependency' => [
|
||||
'depends_on' => 'wait_type',
|
||||
'value' => 'to_day',
|
||||
'operator' => '=',
|
||||
]
|
||||
],
|
||||
'to_day_time' => [
|
||||
'label' => __('Time of the day', 'fluent-crm'),
|
||||
'type' => 'time_selector',
|
||||
'placeholder' => __('Select Time', 'fluent-crm'),
|
||||
'wrapper_class' => 'fc_2col_inline',
|
||||
'picker_options' => [
|
||||
'start' => '00:00',
|
||||
'step' => '00:10',
|
||||
'end' => '23:59'
|
||||
],
|
||||
'dependency' => [
|
||||
'depends_on' => 'wait_type',
|
||||
'value' => 'to_day',
|
||||
'operator' => '=',
|
||||
]
|
||||
],
|
||||
'by_custom_field' => [
|
||||
'label' => __('Select Contact\'s Custom Field', 'fluent-crm'),
|
||||
'type' => 'select',
|
||||
'inline_help' => __('If no value is found in the contact\'s custom field or past date then it will wait only 1 minute by default', 'fluent-crm'),
|
||||
'options' => $customFields,
|
||||
'dependency' => [
|
||||
'depends_on' => 'wait_type',
|
||||
'value' => 'by_custom_field',
|
||||
'operator' => '=',
|
||||
]
|
||||
],
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function handle($subscriber, $sequence, $funnelSubscriberId, $funnelMetric)
|
||||
{
|
||||
// No-op: delay is handled by the processor via sequence delay settings
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user