PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 1.13
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v1.13
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 / Hooks / Handlers / BoardHandler.php

BoardHandler.php in FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration 1.13, at app/Hooks/Handlers/BoardHandler.php

396 lines 13.7 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\Hooks\Handlers;
4
5 use FluentBoards\App\Models\Comment;
6 use FluentBoards\App\Models\Meta;
7 use FluentBoards\App\Models\NotificationUser;
8 use FluentBoards\App\Models\Relation;
9 use FluentBoards\App\Models\Stage;
10 use FluentBoards\App\Models\Task;
11 use FluentBoards\App\Models\Board;
12 use FluentBoards\App\Models\User;
13 use FluentBoards\App\Services\Constant;
14 use FluentBoards\App\Services\Helper;
15
16 class BoardHandler
17 {
18 public function createLogActivity($boardId, $action, $column = null, $oldValue = null, $newValue = null, $description = null, $settings = null )
19 {
20 $data = [
21 'object_type' => Constant::ACTIVITY_BOARD,
22 'object_id' => $boardId,
23 'action' => $action, // action type: changed, updated, added, removed, created
24 'column' => $column,
25 'old_value' => $oldValue,
26 'new_value' => $newValue,
27 'description' => $description,
28 'settings' => $settings
29 ];
30
31 Helper::createActivity($data);
32 }
33 public function getAllBoards($sortBy = 'ASC')
34 {
35 $boards = Board::orderBy('created_at', $sortBy)->get();
36
37 return [
38 'boards' => $boards,
39 ];
40 }
41
42 public function boardCreated($board)
43 {
44 $boardId = $board->id;
45 $this->createLogActivity($boardId, 'created', 'board', null, null, $board->title);
46 $this->updateOnboarding();
47 }
48
49 private function updateOnboarding()
50 {
51 $onboarding = Meta::where('key', Constant::FBS_ONBOARDING)->first();
52 if($onboarding && $onboarding->value == 'no'){
53 $onboarding->value = 'yes' ;
54 $onboarding->save();
55 }
56 }
57
58 public function taskCreatedOnBoard($task)
59 {
60 $boardId = $task->board_id;
61 $this->updateBoardTaskCount($boardId, 1);
62 $taskStage = $task->stage;
63 $settings = ['task_id' => $task->id];
64 $this->createLogActivity($boardId, 'created', 'task', null, $task->title, 'on stage '.$taskStage->title, $settings);
65 }
66
67 public function boardStagesReOrdered($boardId, $oldStageOrders)
68 {
69 $stages = [];
70 foreach ($oldStageOrders as $oldStageId){
71 $stage = Stage::findOrFail($oldStageId);
72 $stages[] = $stage->title;
73 }
74 $this->createLogActivity($boardId,'moved', 'stages', implode(',', $stages));
75 }
76
77 public function beforeBoardDeleted($board, $options = [])
78 {
79 // do something
80 }
81
82 public function boardDeleted($board)
83 {
84 // do something // commented for better code
85 $taskIdsByBoard = (array) Task::where('board_id', '=', $board->id)->pluck('id')->toArray();
86 foreach ($taskIdsByBoard as $taskId) {
87 $task = Task::find($taskId);
88 $task->delete();
89 do_action('fluent_boards/task_deleted', $task);
90 }
91 // TaskActivity::whereIn('task_id', $taskIdsByBoard)->delete();
92 // TaskAssignee::whereIn('task_id', $taskIdsByBoard)->delete();
93 // Task::destroy($taskIdsByBoard);
94 }
95
96 public function boardUpdated($board, $oldBoard)
97 {
98 $boardId = $board->id;
99 $titleChanged = false;
100 $descriptionChanged = ($board->description != $oldBoard->description) ? true : false;
101 if ($board->title != $oldBoard->title) {
102 $titleChanged = true;
103 }
104 if ($descriptionChanged) {
105 $this->createLogActivity($boardId, 'changed', 'description',null , $oldBoard->description, $board->description);
106 }
107 if ($titleChanged) {
108 $this->createLogActivity($boardId, 'changed', 'title', $oldBoard->title, $board->title);
109 }
110 }
111
112 public function boardStageUpdated($boardId, $newStageLabel, $oldStageLabel)
113 {
114 $this->createLogActivity($boardId, 'updated', 'title of stage', $oldStageLabel, $newStageLabel);
115 }
116
117 public function boardStageDragged($stage)
118 {
119 $message = sprintf(__('had changed the position of <em><strong>%1s</strong></em> stage.', 'fluent-boards'), $stage->label);
120 $this->createLogActivity($stage->board_id,'moved', 'stage', $stage->label);
121 }
122
123 public function boardStageAdded($board, $stage)
124 {
125 $this->createLogActivity($board->id,'created', 'stage', null, $stage->title);
126 }
127 public function boardStageMoved($stage, $direction)
128 {
129 $this->createLogActivity($stage->board_id,'moved', $stage->title.' stage', $direction);
130 }
131
132 public function boardStageDeleted($board, $stageTobeDeleted)
133 {
134 $this->createLogActivity($board->id,'deleted', 'stage', $stageTobeDeleted);
135 }
136
137 public function boardStageArchived($boardId, $stageTitle)
138 {
139 $this->createLogActivity($boardId,'archived', 'stage', $stageTitle);
140 }
141
142 public function boardArchivedStageRestore($boardId, $stageTitle)
143 {
144 $this->createLogActivity($boardId,'restored', 'stage', $stageTitle);
145 }
146
147 public function boardMemberAdded($boardId, $memberName)
148 {
149 $this->createLogActivity($boardId,'added', 'member', $memberName, null, '');
150 }
151
152 public function boardMemberRemoved($boardId, $memberName)
153 {
154 $this->createLogActivity($boardId,'removed', 'member', $memberName, 'from board');
155 }
156
157 public function boardAdminRemoved($boardId, $memberId)
158 {
159 $boardMember = $this->getMember($memberId);
160 $this->createLogActivity($boardId,'demoted', $boardMember->display_name, 'Manager', 'Member');
161 }
162
163 public function boardAdminAdded($boardId, $memberId)
164 {
165 $boardMember = $this->getMember($memberId);
166 $this->createLogActivity($boardId,'promoted', $boardMember->display_name, 'Member','Manager');
167 }
168
169 private function getMember($memberId)
170 {
171 return User::find($memberId);
172 }
173
174 public function beforeTaskDeleted($task, $options = [])
175 {
176 //do something
177 }
178
179 public function taskdeleted($task)
180 {
181 if (!$task->parent_id) {
182 $this->createLogActivity($task->board_id, 'deleted', 'task', $task->title);
183 }
184 }
185
186 public function taskarchivedOnBoard($task)
187 {
188 if(!$task->archived_at){
189 $this->createLogActivity($task->board_id, 'restored', 'task', $task->title);
190 $this->updateBoardTaskCount($task->board_id, 1);
191 }else{
192 $this->createLogActivity($task->board_id, 'archived', 'task', $task->title);
193 $this->updateBoardTaskCount($task->board_id, -1);
194 }
195 }
196
197 public function boardLabelActivity($label, $action)
198 {
199 $column = 'label';
200 $settings = [
201 'bg_color' => $label->bg_color,
202 'color' => $label->color,
203 'title' => $label->title ?? ''
204 ];
205 $this->createLogActivity(
206 $label->board_id,
207 $action,
208 $column,
209 null,
210 null,
211 null,
212 $settings
213 );
214 }
215
216 public static function getCurrencies()
217 {
218 return [
219 'AED' => 'United Arab Emirates Dirham',
220 'AFN' => 'Afghan Afghani',
221 'ALL' => 'Albanian Lek',
222 'AMD' => 'Armenian Dram',
223 'ANG' => 'Netherlands Antillean Gulden',
224 'AOA' => 'Angolan Kwanza',
225 'ARS' => 'Argentine Peso', // non amex
226 'AUD' => 'Australian Dollar',
227 'AWG' => 'Aruban Florin',
228 'AZN' => 'Azerbaijani Manat',
229 'BAM' => 'Bosnia & Herzegovina Convertible Mark',
230 'BBD' => 'Barbadian Dollar',
231 'BDT' => 'Bangladeshi Taka',
232 'BIF' => 'Burundian Franc',
233 'BGN' => 'Bulgarian Lev',
234 'BMD' => 'Bermudian Dollar',
235 'BND' => 'Brunei Dollar',
236 'BOB' => 'Bolivian Boliviano',
237 'BRL' => 'Brazilian Real',
238 'BSD' => 'Bahamian Dollar',
239 'BWP' => 'Botswana Pula',
240 'BZD' => 'Belize Dollar',
241 'CAD' => 'Canadian Dollar',
242 'CDF' => 'Congolese Franc',
243 'CHF' => 'Swiss Franc',
244 'CLP' => 'Chilean Peso',
245 'CNY' => 'Chinese Renminbi Yuan',
246 'COP' => 'Colombian Peso',
247 'CRC' => 'Costa Rican Colón',
248 'CVE' => 'Cape Verdean Escudo',
249 'CZK' => 'Czech Koruna',
250 'DJF' => 'Djiboutian Franc',
251 'DKK' => 'Danish Krone',
252 'DOP' => 'Dominican Peso',
253 'DZD' => 'Algerian Dinar',
254 'EGP' => 'Egyptian Pound',
255 'ETB' => 'Ethiopian Birr',
256 'EUR' => 'Euro',
257 'FJD' => 'Fijian Dollar',
258 'FKP' => 'Falkland Islands Pound',
259 'GBP' => 'British Pound',
260 'GEL' => 'Georgian Lari',
261 'GIP' => 'Gibraltar Pound',
262 'GMD' => 'Gambian Dalasi',
263 'GNF' => 'Guinean Franc',
264 'GTQ' => 'Guatemalan Quetzal',
265 'GYD' => 'Guyanese Dollar',
266 'HKD' => 'Hong Kong Dollar',
267 'HNL' => 'Honduran Lempira',
268 'HRK' => 'Croatian Kuna',
269 'HTG' => 'Haitian Gourde',
270 'HUF' => 'Hungarian Forint',
271 'IDR' => 'Indonesian Rupiah',
272 'ILS' => 'Israeli New Sheqel',
273 'INR' => 'Indian Rupee',
274 'ISK' => 'Icelandic Króna',
275 'JMD' => 'Jamaican Dollar',
276 'JPY' => 'Japanese Yen',
277 'KES' => 'Kenyan Shilling',
278 'KGS' => 'Kyrgyzstani Som',
279 'KHR' => 'Cambodian Riel',
280 'KMF' => 'Comorian Franc',
281 'KRW' => 'South Korean Won',
282 'KYD' => 'Cayman Islands Dollar',
283 'KZT' => 'Kazakhstani Tenge',
284 'LAK' => 'Lao Kip',
285 'LBP' => 'Lebanese Pound',
286 'LKR' => 'Sri Lankan Rupee',
287 'LRD' => 'Liberian Dollar',
288 'LSL' => 'Lesotho Loti',
289 'MAD' => 'Moroccan Dirham',
290 'MDL' => 'Moldovan Leu',
291 'MGA' => 'Malagasy Ariary',
292 'MKD' => 'Macedonian Denar',
293 'MNT' => 'Mongolian Tögrög',
294 'MOP' => 'Macanese Pataca',
295 'MRO' => 'Mauritanian Ouguiya',
296 'MUR' => 'Mauritian Rupee',
297 'MVR' => 'Maldivian Rufiyaa',
298 'MWK' => 'Malawian Kwacha',
299 'MXN' => 'Mexican Peso',
300 'MYR' => 'Malaysian Ringgit',
301 'MZN' => 'Mozambican Metical',
302 'NAD' => 'Namibian Dollar',
303 'NGN' => 'Nigerian Naira',
304 'NIO' => 'Nicaraguan Córdoba',
305 'NOK' => 'Norwegian Krone',
306 'NPR' => 'Nepalese Rupee',
307 'NZD' => 'New Zealand Dollar',
308 'PAB' => 'Panamanian Balboa',
309 'PEN' => 'Peruvian Nuevo Sol',
310 'PGK' => 'Papua New Guinean Kina',
311 'PHP' => 'Philippine Peso',
312 'PKR' => 'Pakistani Rupee',
313 'PLN' => 'Polish Złoty',
314 'PYG' => 'Paraguayan Guaraní',
315 'QAR' => 'Qatari Riyal',
316 'RON' => 'Romanian Leu',
317 'RSD' => 'Serbian Dinar',
318 'RUB' => 'Russian Ruble',
319 'RWF' => 'Rwandan Franc',
320 'SAR' => 'Saudi Riyal',
321 'SBD' => 'Solomon Islands Dollar',
322 'SCR' => 'Seychellois Rupee',
323 'SEK' => 'Swedish Krona',
324 'SGD' => 'Singapore Dollar',
325 'SHP' => 'Saint Helenian Pound',
326 'SLL' => 'Sierra Leonean Leone',
327 'SOS' => 'Somali Shilling',
328 'SRD' => 'Surinamese Dollar',
329 'STD' => 'São Tomé and Príncipe Dobra',
330 'SVC' => 'Salvadoran Colón',
331 'SZL' => 'Swazi Lilangeni',
332 'THB' => 'Thai Baht',
333 'TJS' => 'Tajikistani Somoni',
334 'TOP' => 'Tongan Paʻanga',
335 'TRY' => 'Turkish Lira',
336 'TTD' => 'Trinidad and Tobago Dollar',
337 'TWD' => 'New Taiwan Dollar',
338 'TZS' => 'Tanzanian Shilling',
339 'UAH' => 'Ukrainian Hryvnia',
340 'UGX' => 'Ugandan Shilling',
341 'USD' => 'United States Dollar',
342 'UYU' => 'Uruguayan Peso',
343 'UZS' => 'Uzbekistani Som',
344 'VND' => 'Vietnamese Đồng',
345 'VUV' => 'Vanuatu Vatu',
346 'WST' => 'Samoan Tala',
347 'XAF' => 'Central African Cfa Franc',
348 'XCD' => 'East Caribbean Dollar',
349 'XOF' => 'West African Cfa Franc',
350 'XPF' => 'Cfp Franc',
351 'YER' => 'Yemeni Rial',
352 'ZAR' => 'South African Rand',
353 'ZMW' => 'Zambian Kwacha',
354 ];
355 }
356 public function taskMovedFromBoard($task, $oldBoard, $newBoard)
357 {
358 // add tasks_count in the board
359 $this->updateBoardTaskCount($newBoard->id, 1);
360 // subtract tasks_count in the board
361 $this->updateBoardTaskCount($oldBoard->id, -1);
362
363 $this->createLogActivity($oldBoard->id, 'moved', 'task', $task->title . ' to ' . $newBoard->title);
364 $this->createLogActivity($newBoard->id, 'added', 'task', $task->title . ' from ' . $oldBoard->title);
365 }
366
367 public function deleteUserRelatedData($id, $reassign, $user)
368 {
369 try{
370 if(!$id) {
371 throw new \Exception('Member Not deleted');
372 }
373 Meta::where('object_type', Constant::OBJECT_TYPE_USER)
374 ->where('object_id', $id)
375 ->delete();
376 NotificationUser::where('user_id', $id)->delete();
377 Relation::where('foreign_id', $id)
378 ->whereIn('object_type', [
379 Constant::OBJECT_TYPE_BOARD_USER,
380 Constant::OBJECT_TYPE_USER_TASK_WATCH,
381 Constant::TASK_ASSIGNEE
382 ])->delete();
383 }catch (\Exception $e){}
384
385 }
386 private function updateBoardTaskCount($boardId, $count)
387 {
388 $board = Board::find($boardId);
389 $settings = $board->settings ?? [];
390
391 $settings['tasks_count'] = $board->tasks->where('parent_id', null)->count();
392 $board->settings = $settings;
393 $board->save();
394 }
395 }
396