PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / trunk
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration vtrunk
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 1.45 All 41 releases
fluent-boards / app / Models / Folder.php

Folder.php in FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration trunk, at app/Models/Folder.php

102 lines 2.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\Models;
4
5 use FluentBoards\App\Services\Constant;
6 use FluentBoards\Framework\Database\Orm\Builder;
7 use FluentBoards\Framework\Support\Arr;
8
9 class Folder extends Model
10 {
11 protected $table = 'fbs_boards';
12
13 protected $guarded = ['id'];
14
15 protected $hidden = [
16 'created_at',
17 'updated_at',
18 ];
19
20 protected $appends = ['meta'];
21
22 public static function boot()
23 {
24 static::creating(function ($model) {
25 $model->created_by = $model->created_by ?: get_current_user_id();
26 $model->type = $model->type ?: Constant::OBJECT_TYPE_FOLDER;
27 });
28
29 parent::boot();
30 static::addGlobalScope('type', function (Builder $builder) {
31 $builder->where('type', Constant::OBJECT_TYPE_FOLDER);
32 });
33 }
34
35 public function setSettingsAttribute($settings)
36 {
37 $this->attributes['settings'] = \maybe_serialize($settings);
38 }
39
40 public function getSettingsAttribute($settings)
41 {
42 return \maybe_unserialize($settings);
43 }
44
45 public function setBackgroundAttribute($background)
46 {
47 $this->attributes['background'] = \maybe_serialize($background);
48 }
49
50 public function getBackgroundAttribute($background)
51 {
52 return \maybe_unserialize($background);
53 }
54
55 public function getMetaAttribute()
56 {
57 $meta = Meta::where('object_id', $this->id)
58 ->where('object_type', Constant::OBJECT_TYPE_BOARD)
59 ->get();
60
61 $formattedMeta = [];
62 foreach ($meta as $item) {
63 $formattedMeta[$item->key] = $item->value;
64 }
65
66 return $formattedMeta;
67 }
68
69 public function parentFolder()
70 {
71 return $this->belongsTo(Folder::class, 'parent_id');
72 }
73
74 public function subFolders()
75 {
76 return $this->hasMany(Folder::class, 'parent_id')
77 ->whereNull('archived_at');
78 }
79
80 public function boards()
81 {
82 return $this->belongsToMany(
83 Board::class,
84 'fbs_relations',
85 'object_id',
86 'foreign_id'
87 )->withTimestamps()
88 ->withPivot('settings')
89 ->wherePivot('object_type', Constant::OBJECT_TYPE_FOLDER_BOARD);
90 }
91
92 public function toArray()
93 {
94 return [
95 'id' => $this->id,
96 'title' => $this->title,
97 'created_by' => $this->created_by,
98 'boards_ids' => Arr::pluck($this->boards, 'id'),
99 ];
100 }
101 }
102