PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 1.20
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v1.20
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 / Api / Classes / Boards.php

Boards.php in FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration 1.20, at app/Api/Classes/Boards.php

123 lines 2.8 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\Api\Classes;
4
5 defined('ABSPATH') || exit;
6
7 use FluentBoards\App\Models\Board;
8 use FluentBoards\App\Services\BoardService;
9 use FluentBoards\App\Services\Helper;
10 use FluentBoards\App\Services\PermissionManager;
11 use FluentBoards\App\Services\StageService;
12 use FluentBoards\App\Services\LabelService;
13 use FluentBoards\Framework\Support\Arr;
14
15
16 /**
17 * Contacts Class - PHP APi Wrapper
18 *
19 * Contacts API Wrapper Class that can be used as <code>FluentBoardsApi('boards')</code> to get the class instance
20 *
21 * @package FluentBoards\App\Api\Classes
22 * @namespace FluentBoards\App\Api\Classes
23 *
24 * @version 1.0.0
25 */
26 class Boards
27 {
28 private $instance = null;
29
30 private $allowedInstanceMethods = [
31 'all',
32 'get',
33 'find',
34 'first',
35 'paginate'
36 ];
37
38 public function __construct(Board $instance)
39 {
40 $this->instance = $instance;
41 }
42
43 /**
44 * Get Boards
45 *
46 * Use:
47 * <code>FluentBoardsApi('boards')->getBoards();</code>
48 *
49 * @param array $with
50 * @return array|Board Model
51 */
52 public function getBoards($with = [], $sortBy = 'title', $sortOrder = 'asc')
53 {
54 $userId = get_current_user_id();
55 $query = Board::byAccessUser($userId);
56
57 if($sortBy) {
58 $query->orderBy($sortBy, $sortOrder);
59 }
60
61 if ($with) {
62 $query->with($with);
63 }
64
65 $boards = $query->get();
66 return $boards;
67 }
68
69 /**
70 * Get stages by board
71 *
72 * Use:
73 * <code>FluentBoardsApi('boards')->getStagesByBoard($board_id);</code>
74 *
75 * @param int|string $board_id
76 * @return array Model
77 */
78 public function getStagesByBoard($board_id)
79 {
80 if (empty($board_id)) {
81 return [];
82 }
83
84 return Board::with('stages')->where('id', $board_id)->get();
85 }
86
87 public function create($data)
88 {
89 if (empty($data['title'])) {
90 return false;
91 }
92
93 $boardData = $this->boardSanitizeAndValidate($data);
94
95 $boardService = new BoardService();
96 $labelService = new LabelService();
97 $stageService = new StageService();
98
99 $board = $boardService->createBoard($boardData);
100
101 if (!$board) {
102 return false;
103 }
104
105 $labelService->createDefaultLabel($board->id);
106 $stageService->createDefaultStages($board);
107
108 // if board is created from crm contact
109 if (isset($boardData['crm_contact_id'])) {
110 $boardService->updateAssociateMember($boardData['crm_contact_id'], $board->id);
111 }
112 do_action('fluent_boards/board_created', $board);
113
114 return $board;
115 }
116
117 private function boardSanitizeAndValidate($data)
118 {
119 return Helper::sanitizeBoard($data);
120 }
121
122 }
123