PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 2.1.0
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v2.1.0
2.1.0 2.0.15 2.0.12 2.0.10 2.0.4 2.0.1 2.0.0 1.95.3 1.95.2 1.95 1.91.6 trunk 1.11 1.12 1.13 1.20 1.21 1.22 1.23 1.30 1.31 1.32 1.35 1.40 1.41 All 42 releases
fluent-boards / app / Services / Intergrations / FluentCRM / Automations / ContactAddedBoardTrigger.php

ContactAddedBoardTrigger.php in FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration 2.1.0, at app/Services/Intergrations/FluentCRM/Automations/ContactAddedBoardTrigger.php

133 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBoards\App\Services\Intergrations\FluentCRM\Automations;
4
5 use FluentBoards\App\Services\Helper;
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 ContactAddedBoardTrigger extends BaseTrigger
12 {
13 public function __construct()
14 {
15 $this->triggerName = 'fluent_boards/contact_added_to_board';
16 $this->actionArgNum = 2;
17 $this->priority = 20;
18
19 parent::__construct();
20 }
21
22 public function getTrigger()
23 {
24 return [
25 'category' => __('FluentBoards', 'fluent-boards'),
26 'label' => __('Contact Added to Board', 'fluent-boards'),
27 'description' => __('This will run when a contact will be added to a board', 'fluent-boards'),
28 'icon' => 'fc-icon-list_applied_2'
29 ];
30 }
31
32 public function getFunnelSettingsDefaults()
33 {
34 return [
35 'boards' => [],
36 'select_type' => 'any'
37 ];
38 }
39
40 public function getSettingsFields($funnel)
41 {
42 return [
43 'title' => __('Contact Added to Board', 'fluent-boards'),
44 'sub_title' => __('This will run when a contact will be added to a board', 'fluent-boards'),
45 'fields' => [
46 'boards' => [
47 'type' => 'rest_selector',
48 'option_key' => 'boards',
49 'is_multiple' => true,
50 'label' => __('Select Board', 'fluent-boards'),
51 'placeholder' => __('Select Board', 'fluent-boards'),
52 ],
53 'select_type' => [
54 'label' => __('Run When', 'fluent-boards'),
55 'type' => 'radio',
56 'options' => [
57 [
58 'id' => 'any',
59 'title' => __('Contact added to any of the selected boards', 'fluent-boards')
60 ]
61 ],
62 'dependency' => [
63 'depends_on' => 'boards',
64 'operator' => '!=',
65 'value' => []
66 ]
67 ]
68 ]
69 ];
70 }
71
72 public function getFunnelConditionDefaults($funnel)
73 {
74 return [
75 'run_multiple' => 'no'
76 ];
77 }
78
79 public function getConditionFields($funnel)
80 {
81 return [
82 'run_multiple' => [
83 'type' => 'yes_no_check',
84 'label' => '',
85 'check_label' => __('Restart the Automation Multiple times for a contact for this event. (Only enable if you want to restart automation for the same contact)', 'fluent-boards'),
86 'inline_help' => __('If you enable, then it will restart the automation for a contact if the contact already in the automation. Otherwise, It will just skip if already exist', 'fluent-boards')
87 ]
88 ];
89 }
90
91 public function handle($funnel, $originalArgs)
92 {
93 $board = $originalArgs[0];
94 $contactId = $originalArgs[1];
95
96 $subscriber = Helper::crm_contact($contactId);
97
98
99 $willProcess = $this->isProcessable($funnel, $board, $subscriber);
100
101 if (!$willProcess) {
102 return;
103 }
104
105 (new FunnelProcessor())->startFunnelSequence($funnel, $subscriber, [
106 'source_trigger_name' => $this->triggerName
107 ]);
108 }
109
110 private function isProcessable($funnel, $board, $subscriber)
111 {
112 $boards = $funnel->settings['boards'];
113
114 if($boards){
115 $attachIntersection = array_intersect($boards, [$board->id]);
116 if(!$attachIntersection) {
117 return false;
118 }
119 }
120
121 //check run_only_one
122 if ($subscriber && FunnelHelper::ifAlreadyInFunnel($funnel->id, $subscriber->id)) {
123 $multipleRun = Arr::get($funnel->conditions, 'run_multiple') == 'yes';
124 if ($multipleRun) {
125 FunnelHelper::removeSubscribersFromFunnel($funnel->id, [$subscriber->id]);
126 } else {
127 return false;
128 }
129 }
130
131 return true;
132 }
133 }