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

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