PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 2.1.2
Fluent Support – Helpdesk & Customer Support Ticket System v2.1.2
2.4.0 2.3.2 2.3.1 2.3.0 2.2.1 2.2.0 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.4.0 1.4.1 1.4.2 1.4.5 1.4.6 1.4.7 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 All 68 releases
fluent-support / app / Http / Controllers / FluentBoardsController.php

FluentBoardsController.php in Fluent Support – Helpdesk & Customer Support Ticket System 2.1.2, at app/Http/Controllers/FluentBoardsController.php

100 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentSupport\App\Http\Controllers;
4
5 use FluentSupport\App\Services\FluentBoardsService;
6 use FluentSupport\App\Services\Helper;
7 use FluentSupport\Framework\Http\Request\Request;
8
9 class FluentBoardsController extends Controller
10 {
11 public function getBoards()
12 {
13 if (!function_exists('FluentBoardsApi')) {
14 return $this->sendError([
15 'message' => __('Fluent Boards plugin is not installed or activated.', 'fluent-support')
16 ], 400);
17 }
18
19 $boards = FluentBoardsApi('boards')->getBoards();
20 $formattedBoards = [];
21
22 foreach ($boards as $board) {
23 $formattedBoards[] = [
24 'id' => $board->id,
25 'title' => $board->title,
26 'tasks' => [],
27 ];
28 }
29
30 return ['boards' => $formattedBoards];
31 }
32
33 public function getStages(Request $request)
34 {
35 if (!function_exists('FluentBoardsApi')) {
36 return $this->sendError([
37 'message' => __('Fluent Boards plugin is not installed or activated.', 'fluent-support')
38 ], 400);
39 }
40
41 $boardId = $request->getSafe('board_id', 'intval');
42 $boardStages = FluentBoardsApi('boards')->getStagesByBoard($boardId);
43
44 $formattedStages = [];
45 if (!empty($boardStages)) {
46 foreach ($boardStages[0]->stages as $stage) {
47 $formattedStages[] = [
48 'id' => $stage->id,
49 'title' => $stage->title,
50 ];
51 }
52 }
53
54 return ['stages' => $formattedStages];
55 }
56
57 public function createTask(Request $request, FluentBoardsService $fluentBoardsService)
58 {
59 if (!function_exists('FluentBoardsApi')) {
60 return $this->sendError([
61 'message' => __('Fluent Boards plugin is not installed or activated.', 'fluent-support')
62 ], 400);
63 }
64
65 try {
66 $taskData = [
67 'source_id' => $request->getSafe('source_id', 'intval'),
68 'board_id' => $request->getSafe('board_id', 'intval'),
69 'stage_id' => $request->getSafe('stage_id', 'intval'),
70 'crm_contact_id' => $request->getSafe('crm_contact_id', 'intval') ?: null,
71 'title' => $request->getSafe('title', 'sanitize_text_field'),
72 'description' => $request->getSafe('description', 'wp_kses_post'),
73 'source' => $request->getSafe('source', 'sanitize_text_field'),
74 'started_at' => $request->getSafe('started_at', 'sanitize_text_field'),
75 'due_at' => $request->getSafe('due_at', 'sanitize_text_field'),
76 'labels' => [],
77 'assignees' => [],
78 ];
79
80 $task = FluentBoardsApi('tasks')->create($taskData);
81
82 if (!$task) {
83 return $this->sendError(__('Failed to create task.', 'fluent-support'));
84 }
85
86 $fluentBoardsService->addInternalNote($task);
87 $fluentBoardsService->addComment($task);
88
89 return [
90 'message' => __('Task successfully added to Fluent Boards', 'fluent-support'),
91 'task' => $task
92 ];
93 } catch (\Exception $e) {
94 return $this->sendError([
95 'message' => Helper::getSafeErrorMessage($e)
96 ]);
97 }
98 }
99 }
100