PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.8.0
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.8.0
2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 1.1.0 All 77 releases
fluent-community / Modules / Integrations / FluentCRM / SpaceJoinTrigger.php

SpaceJoinTrigger.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 2.8.0, at Modules/Integrations/FluentCRM/SpaceJoinTrigger.php

157 lines 6.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCommunity\Modules\Integrations\FluentCRM;
4
5 use FluentCommunity\App\Models\Space;
6 use FluentCrm\App\Services\Funnel\BaseTrigger;
7 use FluentCrm\App\Services\Funnel\FunnelHelper;
8 use FluentCrm\App\Services\Funnel\FunnelProcessor;
9 use FluentCrm\Framework\Support\Arr;
10
11 class SpaceJoinTrigger extends BaseTrigger
12 {
13 public function __construct()
14 {
15 $this->triggerName = 'fluent_community/space/joined';
16 $this->priority = 20;
17 $this->actionArgNum = 2;
18 parent::__construct();
19 }
20
21 public function getTrigger()
22 {
23 return [
24 'category' => __('Community', 'fluent-community'),
25 'label' => __('Joined in a Space', 'fluent-community'),
26 'description' => __('This automation will be initiated when a user joins a space.', 'fluent-community'),
27 'icon' => 'fc-icon-wp_new_user_signup',
28 'svg_icon' => '<svg version="1.1" viewBox="0 0 128 128" xml:space="preserve"><g><path d="M64,42c-13.2,0-24,10.8-24,24s10.8,24,24,24s24-10.8,24-24S77.2,42,64,42z M64,82c-8.8,0-16-7.2-16-16s7.2-16,16-16 s16,7.2,16,16S72.8,82,64,82z"></path><path d="M64,100.8c-14.9,0-29.2,6.2-39.4,17.1l-2.7,2.9l5.8,5.5l2.7-2.9c8.8-9.4,20.7-14.6,33.6-14.6s24.8,5.2,33.6,14.6l2.7,2.9 l5.8-5.5l-2.7-2.9C93.2,107.1,78.9,100.8,64,100.8z"></path><path d="M97,47.9v8c9.4,0,18.1,3.8,24.6,10.7l5.8-5.5C119.6,52.7,108.5,47.9,97,47.9z"></path><path d="M116.1,20c0-10.5-8.6-19.1-19.1-19.1S77.9,9.5,77.9,20S86.5,39.1,97,39.1S116.1,30.5,116.1,20z M85.9,20 c0-6.1,5-11.1,11.1-11.1s11.1,5,11.1,11.1s-5,11.1-11.1,11.1S85.9,26.1,85.9,20z"></path><path d="M31,47.9c-11.5,0-22.6,4.8-30.4,13.2l5.8,5.5c6.4-6.9,15.2-10.7,24.6-10.7V47.9z"></path><path d="M50.1,20C50.1,9.5,41.5,0.9,31,0.9S11.9,9.5,11.9,20S20.5,39.1,31,39.1S50.1,30.5,50.1,20z M31,31.1 c-6.1,0-11.1-5-11.1-11.1S24.9,8.9,31,8.9s11.1,5,11.1,11.1S37.1,31.1,31,31.1z"></path></g></svg>'
29 ];
30 }
31
32 public function getSettingsFields($funnel)
33 {
34 return [
35 'title' => __('Joined in a Space', 'fluent-community'),
36 'sub_title' => __('This automation will be initiated when a user joins a space', 'fluent-community'),
37 'fields' => [
38 'subscription_status' => [
39 'type' => 'option_selectors',
40 'option_key' => 'editable_statuses',
41 'is_multiple' => false,
42 'label' => __('Subscription Status', 'fluent-community'),
43 'placeholder' => __('Select Status', 'fluent-community')
44 ],
45 'subscription_status_info' => [
46 'type' => 'html',
47 'info' => '<b>' . __('An Automated double-opt-in email will be sent for new subscribers', 'fluent-community') . '</b>',
48 'dependency' => [
49 'depends_on' => 'subscription_status',
50 'operator' => '=',
51 'value' => 'pending'
52 ]
53 ]
54 ]
55 ];
56 }
57
58 public function getFunnelSettingsDefaults()
59 {
60 return [
61 'subscription_status' => 'subscribed'
62 ];
63 }
64
65 public function getConditionFields($funnel)
66 {
67 $communities = Space::orderBy('title', 'ASC')->select(['id', 'title'])->get();
68
69 return [
70 'update_type' => [
71 'type' => 'radio',
72 'label' => __('If Contact Already Exists?', 'fluent-community'),
73 'help' => __('Please specify what will happen if the subscriber already exists in the database', 'fluent-community'),
74 'options' => FunnelHelper::getUpdateOptions()
75 ],
76 'community_ids' => [
77 'type' => 'multi-select',
78 'is_multiple' => true,
79 'label' => __('Targeted Spaces', 'fluent-community'),
80 'help' => __('Select which spaces this automation funnel is for.', 'fluent-community'),
81 'placeholder' => __('Select Spaces', 'fluent-community'),
82 'options' => $communities,
83 'inline_help' => __('Leave blank to run for all Spaces', 'fluent-community')
84 ],
85 'run_multiple' => [
86 'type' => 'yes_no_check',
87 'label' => '',
88 'check_label' => __('Restart automation multiple times for a contact for this event. (Enable only if you want to restart automation for the same contact.)', 'fluent-community'),
89 'inline_help' => __('If you enable this, it will restart the automation for a contact even if they are already in the automation. Otherwise, it will skip if the contact already exists.', 'fluent-community')
90 ]
91 ];
92 }
93
94 public function getFunnelConditionDefaults($funnel)
95 {
96 return [
97 'update_type' => 'update', // skip_all_actions, skip_update_if_exist
98 'community_ids' => [],
99 'run_multiple' => 'yes'
100 ];
101 }
102
103 public function handle($funnel, $originalArgs)
104 {
105 $space = $originalArgs[0];
106 $userId = $originalArgs[1];
107
108 $user = get_user_by('ID', $userId);
109
110 if (!$user || !$this->isProcessable($funnel, $user, $space)) {
111 return false;
112 }
113
114 $subscriberData = FunnelHelper::prepareUserData($user);
115
116 $subscriberData = wp_parse_args($subscriberData, $funnel->settings);
117 $subscriberData['status'] = $subscriberData['subscription_status'];
118 unset($subscriberData['subscription_status']);
119
120 (new FunnelProcessor())->startFunnelSequence($funnel, $subscriberData, [
121 'source_trigger_name' => $this->triggerName,
122 'source_ref_id' => $space->id
123 ]);
124 }
125
126 private function isProcessable($funnel, $user, $space)
127 {
128 $conditions = $funnel->conditions;
129 // check update_type
130 $updateType = Arr::get($conditions, 'update_type');
131
132 $subscriber = FunnelHelper::getSubscriber($user->user_email);
133 if ($updateType == 'skip_all_if_exist' && $subscriber) {
134 return false;
135 }
136
137 // check user roles
138 if ($checkIds = Arr::get($conditions, 'community_ids', [])) {
139 $checkIds = (array) $checkIds;
140 if (!in_array($space->id, $checkIds)) {
141 return false;
142 }
143 }
144
145 // check run_only_one
146 if ($subscriber && FunnelHelper::ifAlreadyInFunnel($funnel->id, $subscriber->id)) {
147 $multipleRun = Arr::get($conditions, 'run_multiple') == 'yes';
148 if ($multipleRun) {
149 FunnelHelper::removeSubscribersFromFunnel($funnel->id, [$subscriber->id]);
150 }
151 return $multipleRun;
152 }
153
154 return true;
155 }
156 }
157