Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 6 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
FlyShare | |
0.00% |
0 / 6 |
|
0.00% |
0 / 6 |
42 | |
0.00% |
0 / 1 |
getSharedWithAttribute | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAcceptedSharesAttribute | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
shortcuts | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
user | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
clonedSharedShortcuts | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
shareHistory | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace App\Http\Models; |
4 | |
5 | use App\Http\Models\Auth\User; |
6 | |
7 | class FlyShare extends Moloquent |
8 | { |
9 | /** |
10 | * Status values for user flyshare acceptance |
11 | * |
12 | * @var string |
13 | */ |
14 | public const FLYSHARE_INVITE_STATUS_PENDING = 'pending'; |
15 | |
16 | public const FLYSHARE_INVITE_STATUS_ACCEPTED = 'accepted'; |
17 | |
18 | /** |
19 | * The table associated with the model. |
20 | * |
21 | * @var string |
22 | */ |
23 | protected $table = 'flyshares'; |
24 | |
25 | /** |
26 | * The attributes that are mass assignable. |
27 | * |
28 | * @var array |
29 | */ |
30 | protected $fillable = [ |
31 | 'user_id', 'shortcut_ids', 'accepted_shares', 'shared_with', 'cloned_shared_ids', |
32 | ]; |
33 | |
34 | /** |
35 | * The accessors to append to the model's array form. |
36 | * |
37 | * @var array |
38 | */ |
39 | protected $appends = ['shared_with', 'accepted_shares']; |
40 | |
41 | /** |
42 | * Get the shared_with count atrribute for the flyshare. |
43 | */ |
44 | public function getSharedWithAttribute(): int |
45 | { |
46 | return $this->shareHistory()->count(); |
47 | } |
48 | |
49 | /** |
50 | * Get the accepted_shares count atrribute for the flyshare. |
51 | */ |
52 | public function getAcceptedSharesAttribute(): int |
53 | { |
54 | return $this->shareHistory()->where('status', self::FLYSHARE_INVITE_STATUS_ACCEPTED)->count(); |
55 | } |
56 | |
57 | /** |
58 | * The shortcuts that belong to the flyshare. |
59 | * |
60 | * @deprecated No longer used by internal code. |
61 | */ |
62 | public function shortcuts() |
63 | { |
64 | return $this->belongsToMany(Shortcut::class, null, 'flyshare_ids', 'shortcut_ids'); |
65 | } |
66 | |
67 | /** |
68 | * Get the user that owns the flyshare |
69 | * |
70 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
71 | */ |
72 | public function user() |
73 | { |
74 | return $this->belongsTo(User::class); |
75 | } |
76 | |
77 | /** |
78 | * Get the cloned shortcuts that belongs to the flyshare. |
79 | */ |
80 | public function clonedSharedShortcuts() |
81 | { |
82 | return $this->hasMany(ClonedSharedShortcut::class, 'flyshare_id'); |
83 | } |
84 | |
85 | /** |
86 | * Get the entities that the flyshare was shared with. |
87 | */ |
88 | public function shareHistory() |
89 | { |
90 | return $this->hasMany(ShareHistory::class, 'flyshare_id'); |
91 | } |
92 | } |