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

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