PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 1.11
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v1.11
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 / FluentFormIntegration / Bootstrap.php

Bootstrap.php in FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration 1.11, at app/Services/Intergrations/FluentFormIntegration/Bootstrap.php

433 lines 15.6 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\FluentFormIntegration;
4
5 use FluentBoards\App\Models\Label;
6 use FluentBoards\App\Models\Stage;
7 use FluentBoards\App\Models\User;
8 use FluentBoards\App\Services\Constant;
9 use FluentBoards\App\Services\NotificationService;
10 use FluentBoards\App\Services\TaskService;
11 use FluentForm\App\Http\Controllers\IntegrationManagerController;
12 use FluentBoards\Framework\Support\Arr;
13 use FluentBoards\App\Models\Board;
14 use FluentBoards\App\Models\Task;
15 use FluentBoards\App\Services\Helper;
16 use FluentCrm\App\Models\Subscriber;
17 use FluentBoards\App\App;
18
19
20 class Bootstrap extends IntegrationManagerController
21 {
22 public $disableGlobalSettings = 'yes';
23
24 public function __construct($app)
25 {
26 parent::__construct(
27 $app,
28 'Fluent Boards',
29 'fluent_boards',
30 '_fluentform_fluent_boards_settings',
31 'fluentform_fluent_boards_feed',
32 30
33 );
34
35 $fluentBoards = App::getInstance();
36 $this->logo = $fluentBoards['url.assets'] . 'images/icon.png';
37
38 $this->description = 'Connect Fluent Boards with WP Fluent Forms and create a task when a form is submitted.';
39
40 $this->registerAdminHooks();
41
42 add_action('wp_ajax_fluentform_fluent_board_config', array($this, 'getBoardConfigOptions'));
43 add_filter('fluentform/notifying_async_fluent_boards', '__return_false');
44 }
45
46 public function addGlobalMenu($setting)
47 {
48 return $setting;
49 }
50
51 public function pushIntegration($integrations, $formId)
52 {
53 $integrations[$this->integrationKey] = [
54 'title' => $this->title . ' Integration',
55 'logo' => $this->logo,
56 'disable_global_settings' => 'yes',
57 'category' => '',
58 'is_active' => $this->isConfigured()
59 ];
60
61 return $integrations;
62 }
63
64 public function isConfigured()
65 {
66 return true;
67 }
68
69 public function getIntegrationDefaults($settings, $formId)
70 {
71 return [
72 'name' => '',
73 'list_id' => '',
74 'board_config' => [
75 'board_id' => '',
76 'stage_id' => '',
77 'board_label_id' => [],
78 'member_ids' => [],
79 'crm_contact_id' => '',
80 'priority' => ''
81 ],
82 'task_title' => '',
83 'submitter_name' => '',
84 'submitter_email' => '',
85 'priority' => '',
86 'description' => '',
87 'position' => 'bottom',
88 'conditionals' => [
89 'conditions' => [],
90 'status' => false,
91 'type' => 'all'
92 ],
93
94
95 'enabled' => true
96 ];
97 }
98
99 public function getSettingsFields($settings, $formId)
100 {
101 return [
102 'fields' => [
103 [
104 'key' => 'board_config',
105 'label' => 'Fluent Boards Configuration',
106 'required' => true,
107 'component' => 'chained_select',
108 'primary_key' => 'board_id',
109 'fields_options' => [
110 'board_id' => [],
111 'stage_id' => [],
112 'board_label_id' => [],
113 'member_ids' => [],
114 'priority' => []
115 ],
116 'options_labels' => [
117 'board_id' => [
118 'label' => 'Select Board',
119 'type' => 'select',
120 'placeholder' => 'Select Board'
121 ],
122 'stage_id' => [
123 'label' => 'Select Stage',
124 'type' => 'select',
125 'placeholder' => 'Select Stage'
126 ],
127 'board_label_id' => [
128 'label' => 'Select Labels',
129 'type' => 'multi-select',
130 'placeholder' => 'Select Labels'
131 ],
132 'member_ids' => [
133 'label' => 'Select Assignees',
134 'type' => 'multi-select',
135 'placeholder' => 'Select Assignees'
136 ],
137 'priority' => [
138 'label' => 'Select Priority',
139 'type' => 'select',
140 'placeholder' => 'Priority'
141 ]
142 ],
143 'remote_url' => admin_url('admin-ajax.php?action=fluentform_fluent_board_config')
144 ],
145 [
146 'key' => 'task_title',
147 'label' => 'Task Title',
148 'required' => true,
149 'placeholder' => 'Task Title',
150 'component' => 'value_text'
151 ],
152 [
153 'key' => 'description',
154 'label' => 'Description',
155 'required' => false,
156 'placeholder' => 'Describe your task',
157 'component' => 'wp_editor',
158 ],
159
160 [
161 'key' => 'submitter_name',
162 'label' => 'Submitter Name',
163 'required' => true,
164 'placeholder' => 'Submitter Name',
165 'component' => 'value_text'
166 ],
167 [
168 'key' => 'submitter_email',
169 'label' => 'Submitter Email',
170 'required' => true,
171 'placeholder' => 'Submitter Email',
172 'component' => 'value_text'
173 ],
174 [
175 'key' => 'position',
176 'label' => 'Task Position',
177 'required' => true,
178 'placeholder' => 'Position',
179 'component' => 'radio_choice',
180 'options' => [
181 'bottom' => 'Bottom',
182 'top' => 'Top'
183 ]
184 ],
185 [
186 'key' => 'conditionals',
187 'label' => 'Conditional Logics',
188 'tips' => 'Allow integration conditionally based on your submission values',
189 'component' => 'conditional_block'
190 ],
191 [
192 'key' => 'enabled',
193 'label' => 'Status',
194 'component' => 'checkbox-single',
195 'checkbox_label' => 'Enable This feed'
196 ]
197 ],
198 'button_require_list' => false,
199 'integration_title' => $this->title
200 ];
201 }
202
203
204 public function getBoardConfigOptions()
205 {
206 $requestInfo = $this->app->request->get('settings');
207 $boardConfig = Arr::get($requestInfo, 'board_config');
208
209 $boardId = Arr::get($boardConfig, 'board_id');
210
211 $data = [
212 'board_id' => $this->getBoards(),
213 'stage_id' => [],
214 'board_label_id' => [],
215 'member_ids' => [],
216 'priority' => [
217 'low' => 'Low',
218 'medium' => 'Medium',
219 'high' => 'High'
220 ]
221 ];
222
223 if ($boardId) {
224 $data['stage_id'] = $this->getStages($boardId);
225 $data['board_label_id'] = $this->getBoardLabels($boardId);
226 $data['member_ids'] = $this->getBoardMemmbers($boardId);
227 }
228
229 wp_send_json_success([
230 'fields_options' => $data
231 ], 200);
232 }
233
234 protected function getBoards()
235 {
236 $boards = Board::query()->whereNull('archived_at')->get()->toArray();
237
238 $formattedBoards = [];
239 foreach ($boards as $board) {
240 if (is_array($board)) {
241 $formattedBoards[$board['id']] = $board['title'];
242 }
243 }
244
245 return $formattedBoards;
246 }
247
248 protected function getStages($boardId)
249 {
250 $stages = Stage::where('board_id', $boardId)->whereNull('archived_at')->get()->toArray();
251
252 $formattedStages = [];
253 foreach ($stages as $stage) {
254 if (is_array($stage)) {
255 $formattedStages[$stage['id']] = $stage['title'];
256 }
257 }
258
259 return $formattedStages;
260 }
261
262
263 /**
264 * Prepare Fluent Boards forms for feed field.
265 *
266 * @return array
267 */
268
269 /*
270 * Submission Broadcast Handler
271 */
272
273 public function notify($feed, $formData, $entry, $form)
274 {
275 if (function_exists('fluentBoards')) {
276 $feedData = $feed['processedValues'];
277 $taskName = trim(Arr::get($feedData, 'task_title'));
278 $boardId = Arr::get($feedData, 'board_config.board_id');
279 $stageId = Arr::get($feedData, 'board_config.stage_id');
280 $boardLabels = Arr::get($feedData, 'board_config.board_label_id');
281 $assignees = Arr::get($feedData, 'board_config.member_ids');
282 $priority = Arr::get($feedData, 'board_config.priority');
283 $description = Arr::get($feedData, 'description');
284 $position = Arr::get($feedData, 'position');
285 $crmContactId = Arr::get($feedData, 'board_config.crm_contact_id');
286 $submitterName = Arr::get($feedData, 'submitter_name');
287 $submitterEmail = Arr::get($feedData, 'submitter_email');
288 $watcher = trim(Arr::get($feedData, 'watcher_id'));
289 if (!$boardId) {
290 do_action('fluentform/integration_action_result', $feed, 'failed', 'Board is required');
291 return;
292 }
293 $board = Board::find($boardId)->toArray();
294 if (!$board) {
295 do_action('fluentform/integration_action_result', $feed, 'failed', "Board doesn't exist");
296 return;
297 }
298 if (!$stageId) {
299 do_action('fluentform/integration_action_result', $feed, 'failed', "Stage is required");
300 return;
301 }
302 $stage = Stage::find($stageId)->toArray();
303 if (!$stage) {
304 do_action('fluentform/integration_action_result', $feed, 'failed', "Stage doesn't exist");
305 return;
306 }
307 if (!$taskName) {
308 do_action('fluentform/integration_action_result', $feed, 'failed', "Task title is required");
309 return;
310 } else if (!is_string($taskName)) {
311 do_action('fluentform/integration_action_result', $feed, 'failed', "Invalid Task title is required");
312 return;
313 }
314
315 $data = [
316 'title' => $taskName,
317 'board_id' => $boardId,
318 'stage_id' => $stageId,
319 'priority' => $priority,
320 'description' => $description,
321 'crm_contact_id' => $crmContactId,
322 'position' => $this->getLastPositionOfStageTask($boardId, $stageId),
323 'source' => 'FluentForm'
324
325 ];
326
327 $formSubmitter = User::where('user_email', $submitterEmail)->first();
328 if (isset($formSubmitter['ID'])) {
329 $data['created_by'] = $formSubmitter->ID;
330 } else {
331 $data['settings']['author'] = [
332 'name' => sanitize_text_field($submitterName),
333 'email' => sanitize_email($submitterEmail),
334 'cover' => [
335 'backgroundColor' => ''
336 ],
337 'subtask_count' => 0
338 ];
339 }
340
341 if (function_exists('fluentCrm')) {
342 $crmConatct = Subscriber::where('email', $submitterEmail)->first();
343 if ($crmConatct) {
344 $data['crm_contact_id'] = $crmConatct->id;
345 }
346 }
347
348 $data = Helper::sanitizeTask($data);
349 $task = (new Task())->createTask($data);
350
351 if ($task->id) {
352 do_action('fluent_boards/task_added_from_fluent_form', $task);
353 if ($position == 'top') {
354 $task->moveToNewPosition(1);
355 }
356
357 if ($assignees) {
358 foreach ($assignees as $assignee) {
359 $operation = $task->addOrRemoveAssignee($assignee);
360 $task->load('assignees');
361 $task->updated_at = current_time('mysql');
362
363 $task->save();
364
365 if ($operation == 'added') {
366 if ((new NotificationService())->checkIfEmailEnable($assignee, Constant::BOARD_EMAIL_TASK_ASSIGN, $task->board_id)) {
367 (new TaskService())->sendMailAfterTaskModify('add_assignee', $assignee, $task->id);
368 }
369 do_action('fluent_boards/task_assignee_changed', $task, $assignee, $operation);
370 }
371 }
372 }
373
374 if ($boardLabels) {
375 foreach ($boardLabels as $label) {
376 $task->labels()->syncWithoutDetaching([$label => ['object_type' => Constant::OBJECT_TYPE_TASK_LABEL]]);
377 }
378 }
379
380 $successMessage = __('Fluent Boards feed has been successfully initialized and data has been pushed.', 'fluent-boards');
381 do_action('fluentform/integration_action_result', $feed, 'success', $successMessage);
382 } else {
383 $error = __('Error when submitting data to Fluent Board server.', 'fluent-boards');
384 do_action('fluentform/integration_action_result', $feed, 'failed', $error);
385 }
386 } else {
387 do_action('fluentform/integration_action_result', $feed, 'failed', "Fluent Board doesn't exists.");
388 }
389 }
390
391 function getMergeFields($list, $listId, $formId)
392 {
393 return false;
394 }
395
396 function getLastPositionOfStageTask($board_id, $stage_id)
397 {
398 $lastPosition = Task::query()
399 ->where('board_id', $board_id)
400 ->where('parent_id', null)
401 ->where('stage_id', $stage_id)
402 ->whereNull('archived_at')
403 ->orderBy('position', 'desc')
404 ->pluck('position')
405 ->first();
406
407 return $lastPosition + 1;
408 }
409
410 function getBoardLabels($boardId)
411 {
412 $labels = Label::where('board_id', $boardId)->whereNull('archived_at')->orderBy('position', 'asc')->get();
413
414 $formattedLabels = [];
415 foreach ($labels as $label) {
416 $formattedLabels[$label['id']] = $label['title'] ?? $label['slug'];
417 }
418
419 return $formattedLabels;
420 }
421
422 function getBoardMemmbers($boardId)
423 {
424 $board = Board::findOrFail($boardId);
425 $boardUsers = $board->users;
426 $formattedBoardUsers = [];
427 foreach ($boardUsers as $boardUser) {
428 $formattedBoardUsers[$boardUser['ID']] = $boardUser['user_login'] . " (" . $boardUser['user_email'] . ")";
429 }
430 return $formattedBoardUsers;
431 }
432 }
433