| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentBoards\App\Services\Intergrations\FluentCRM\Automations; |
| 4 |
|
| 5 |
use FluentBoards\App\Models\Task; |
| 6 |
use FluentBoards\App\Services\TaskService; |
| 7 |
use FluentCrm\App\Services\Funnel\BaseAction; |
| 8 |
use FluentCrm\App\Services\Funnel\FunnelHelper; |
| 9 |
use FluentCrm\Framework\Support\Arr; |
| 10 |
use FluentBoards\App\Services\Helper; |
| 11 |
|
| 12 |
class TaskCreateAction extends BaseAction |
| 13 |
{ |
| 14 |
public function __construct() |
| 15 |
{ |
| 16 |
$this->actionName = 'add_task_to_board'; |
| 17 |
$this->priority = 20; |
| 18 |
parent::__construct(); |
| 19 |
} |
| 20 |
|
| 21 |
public function getBlock() |
| 22 |
{ |
| 23 |
return [ |
| 24 |
'category' => __('FluentBoards', 'fluent-boards'), |
| 25 |
'title' => __('Create Task', 'fluent-boards'), |
| 26 |
'description' => __('Create Task to the selected Board', 'fluent-boards'), |
| 27 |
'icon' => 'fc-icon-apply_list', |
| 28 |
'settings' => [ |
| 29 |
'stage' => [], |
| 30 |
'title' => 'Task from automation of {{contact.email}}' |
| 31 |
] |
| 32 |
]; |
| 33 |
} |
| 34 |
|
| 35 |
public function getBlockFields() |
| 36 |
{ |
| 37 |
return [ |
| 38 |
'title' => __('Create Task', 'fluent-boards'), |
| 39 |
'sub_title' => __('Select which Board & Stage where task will be created', 'fluent-boards'), |
| 40 |
'fields' => [ |
| 41 |
'stage' => [ |
| 42 |
'type' => 'grouped-select', |
| 43 |
'is_multiple' => false, |
| 44 |
'label' => __('Select Board & It\'s stage', 'fluent-boards'), |
| 45 |
'placeholder' => __('Select Board & It\'s stage', 'fluent-boards'), |
| 46 |
'options' => Helper::getStagesByBoardGroup() |
| 47 |
], |
| 48 |
'title' => [ |
| 49 |
'type' => 'input-text-popper', |
| 50 |
'field_type' => 'text', |
| 51 |
'label' => __('Task Title', 'fluent-boards'), |
| 52 |
'placeholder' => __('Task Title', 'fluent-boards') |
| 53 |
], |
| 54 |
|
| 55 |
'due_day' => [ |
| 56 |
'label' => __('Due Date', 'fluent-boards'), |
| 57 |
'type' => 'input-number', |
| 58 |
'inline_help' => __('Set to your_input days after task creation, values less than zero will set due date to null', 'fluent-boards') |
| 59 |
], |
| 60 |
|
| 61 |
'description' => [ |
| 62 |
'type' => 'html_editor', |
| 63 |
'smart_codes' => 'yes', |
| 64 |
'context_codes' => 'yes', |
| 65 |
'label' => __('Description', 'fluent-boards') |
| 66 |
], |
| 67 |
|
| 68 |
'priority' => [ |
| 69 |
'type' => 'select', |
| 70 |
'label' => __('Select Priority', 'fluent-boards'), |
| 71 |
'options' => Helper::getPriorityOptions(), |
| 72 |
'inline_help' => __('Keeping it blank will select priority to low', 'fluent-boards') |
| 73 |
] |
| 74 |
] |
| 75 |
]; |
| 76 |
} |
| 77 |
|
| 78 |
public function handle( $subscriber, $sequence, $funnelSubscriberId, $funnelMetric ) |
| 79 |
{ |
| 80 |
$data = $sequence->settings; |
| 81 |
|
| 82 |
$stage = Arr::get($data, 'stage'); // this is a string of the pipeline stage id |
| 83 |
$title = Arr::get( $data, 'title'); |
| 84 |
$priority = Arr::get( $data, 'priority'); |
| 85 |
$due_day = Arr::get( $data, 'due_day'); |
| 86 |
|
| 87 |
if(isset($due_day)) { |
| 88 |
$due_date = Helper::dueDateConversion($due_day, 'day'); |
| 89 |
} |
| 90 |
|
| 91 |
$description = Arr::get( $data, 'description'); |
| 92 |
|
| 93 |
if ( empty($stage) ) { |
| 94 |
FunnelHelper::changeFunnelSubSequenceStatus( $funnelSubscriberId, $sequence->id, 'skipped' ); |
| 95 |
return; |
| 96 |
} |
| 97 |
$stageId = intval( $stage ); |
| 98 |
$board = Helper::getBoardByStageId( $stageId ); |
| 99 |
|
| 100 |
if ( !$stage ) { |
| 101 |
return; |
| 102 |
} |
| 103 |
|
| 104 |
$description = apply_filters('fluent_crm/parse_campaign_email_text', $description, $subscriber); |
| 105 |
$title = apply_filters('fluent_crm/parse_campaign_email_text', $title, $subscriber); |
| 106 |
|
| 107 |
(new Task())->createTask([ |
| 108 |
'title' => $title, |
| 109 |
'board_id' => $board->id, |
| 110 |
'crm_contact_id' => $subscriber->id, |
| 111 |
'type' => 'task', |
| 112 |
'status' => 'open', |
| 113 |
'stage_id' => $stageId, |
| 114 |
'source' => 'funnel', |
| 115 |
'description' => $description, |
| 116 |
'priority' => $priority, |
| 117 |
'due_at' => $due_date ?? null, |
| 118 |
'position' => (new TaskService())->getLastPositionOfTasks($stageId), |
| 119 |
]); |
| 120 |
|
| 121 |
FunnelHelper::changeFunnelSubSequenceStatus($funnelSubscriberId, $sequence->id, 'completed'); |
| 122 |
|
| 123 |
} |
| 124 |
|
| 125 |
} |