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

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