PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 1.30
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v1.30
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 / Stages.php

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

181 lines 3.9 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 use FluentBoards\App\Models\Stage;
6 use FluentBoards\App\Services\BoardService;
7 use FluentBoards\App\Services\Helper;
8 use FluentBoards\App\Services\PermissionManager;
9 use FluentBoards\App\Services\StageService;
10
11 defined('ABSPATH') || exit;
12
13 class Stages
14 {
15 private $instance = null;
16
17 private $allowedInstanceMethods
18 = [
19 'all',
20 'get',
21 'find',
22 'first',
23 'paginate',
24 ];
25
26 public function __construct(Stage $stage)
27 {
28 $this->instance = $stage;
29 }
30
31 public function getStage($id, $with = [])
32 {
33 if ( ! $id) {
34 return false;
35 }
36
37 $stage = Stage::where('id', $id)->with($with)->first();
38
39 if ( ! $stage) {
40 return false;
41 }
42
43 return $stage;
44 }
45
46 public function getStagesByBoard($boardId, $with = [])
47 {
48 if ( ! $boardId) {
49 return false;
50 }
51
52 if ( ! PermissionManager::userHasPermission($boardId)) {
53 return false;
54 }
55
56 $query = Stage::where('board_id', $boardId)
57 ->whereNull('archived_at');
58
59 if ( ! empty($with)) {
60 $query->with($with);
61 }
62
63 $stages = $query->get();
64
65 return $stages;
66 }
67
68 public function create($data)
69 {
70 if (empty($data)) {
71 return false;
72 }
73
74 if (empty($data['title']) || empty($data['board_id'])) {
75 return false;
76 }
77
78 //checking if current user has access to board
79 if ( ! PermissionManager::userHasPermission($data['board_id'])) {
80 return false;
81 }
82
83 $stageData = Helper::sanitizeStage($data);
84
85 $stageService = new StageService();
86 $stage = $stageService->createStage($stageData,
87 $stageData['board_id']);
88
89 return $stage;
90 }
91
92 public function updateProperty($stageId, $property, $value)
93 {
94 $stageService = new StageService();
95
96 $stage = Stage::findOrFail($stageId);
97
98 if ( ! $stage) {
99 return false;
100 }
101
102 $allowedColumns = ['title', 'status', 'bg_color'];
103
104 if ( ! in_array($property, $allowedColumns)) {
105 return false;
106 }
107
108 //checking if current user has access to board
109 if ( ! PermissionManager::userHasPermission($stage->board_id)) {
110 return false;
111 }
112
113 $stage = $stageService->updateStageProperty($property, $value,
114 $stageId);
115
116 return $stage;
117 }
118
119 public function archiveStage($stageId)
120 {
121 if ( ! $stageId) {
122 return false;
123 }
124
125 $stage = Stage::findOrFail($stageId);
126
127 if ( ! $stage) {
128 return false;
129 }
130
131 //checking if current user has access to board
132 if ( ! PermissionManager::userHasPermission($stage->board_id)) {
133 return false;
134 }
135
136 $boardService = new BoardService();
137
138 $stage = $boardService->archiveStage($stage->board_id, $stage);
139
140 return $stage;
141 }
142
143 public function restoreStage($stageId)
144 {
145 if ( ! $stageId) {
146 return false;
147 }
148
149 $stage = Stage::findOrFail($stageId);
150
151 if ( ! $stage) {
152 return false;
153 }
154
155 //checking if current user has access to board
156 if ( ! PermissionManager::userHasPermission($stage->board_id)) {
157 return false;
158 }
159
160 $boardService = new BoardService();
161
162 return $boardService->restoreStage($stage->board_id, $stage);
163 }
164
165
166 public function getInstance()
167 {
168 return $this->instance;
169 }
170
171 public function __call($method, $params)
172 {
173 if (in_array($method, $this->allowedInstanceMethods)) {
174 return call_user_func_array([$this->instance, $method], $params);
175 }
176
177 throw new \Exception("Method {$method} does not exist.");
178 }
179
180
181 }