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

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