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

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