|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Sofa\Eloquence\Eloquence; |
|
6
|
|
|
use Sofa\Eloquence\Mappable; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class Photo. |
|
10
|
|
|
*/ |
|
11
|
|
|
class Photo extends ChocolateyModel |
|
12
|
|
|
{ |
|
13
|
|
|
use Eloquence, Mappable; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* The table associated with the model. |
|
17
|
|
|
* |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $table = 'camera_web'; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Primary Key of the Table. |
|
24
|
|
|
* |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $primaryKey = 'id'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* The attributes that will be mapped. |
|
31
|
|
|
* |
|
32
|
|
|
* @var array |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $maps = ['creator_id' => 'user_id', 'previewUrl' => 'url', 'creator_uniqueId' => 'user_id', 'time' => 'timestamp']; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* The Appender(s) of the Model. |
|
38
|
|
|
* |
|
39
|
|
|
* @var array |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $appends = ['creator_uniqueId', 'version', 'previewUrl', 'creator_id', 'likes', 'tags', 'version', 'type', 'room_id', 'creator_name']; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* The attributes that should be casted to native types. |
|
45
|
|
|
* |
|
46
|
|
|
* @var array |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $casts = ['tags' => 'array', 'creator_uniqueId' => 'string']; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Get the Unique Id of the Photo. |
|
52
|
|
|
* |
|
53
|
|
|
* @return string |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getIdAttribute(): string |
|
56
|
|
|
{ |
|
57
|
|
|
return (string) $this->attributes['id']; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Get the URL of the Photo. |
|
62
|
|
|
* |
|
63
|
|
|
* @return string |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getUrlAttribute(): string |
|
66
|
|
|
{ |
|
67
|
|
|
return str_replace('http:', '', str_replace('https:', '', $this->attributes['url'])); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Get the Version Attribute. |
|
72
|
|
|
* |
|
73
|
|
|
* @return int |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getVersionAttribute(): int |
|
76
|
|
|
{ |
|
77
|
|
|
return 1; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Get All Tags |
|
82
|
|
|
* Transforming it on an Array. |
|
83
|
|
|
* |
|
84
|
|
|
* @return array(string) |
|
|
|
|
|
|
85
|
|
|
*/ |
|
86
|
|
|
public function getTagsAttribute(): array |
|
87
|
|
|
{ |
|
88
|
|
|
return []; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Get Formatted Time |
|
93
|
|
|
* Convert Date to UNIX Timestamp. |
|
94
|
|
|
* |
|
95
|
|
|
* @return int |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getTimeAttribute(): int |
|
98
|
|
|
{ |
|
99
|
|
|
return strtotime($this->attributes['timestamp']) * 1000; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Get Photo Likes Directly as Username. |
|
104
|
|
|
* |
|
105
|
|
|
* @return array |
|
106
|
|
|
*/ |
|
107
|
|
|
public function getLikesAttribute(): array |
|
108
|
|
|
{ |
|
109
|
|
|
return array_map(function (array $item) { |
|
110
|
|
|
return $item['username']; |
|
111
|
|
|
}, PhotoLike::query()->select('username')->where('photo_id', $this->attributes['id'])->get(['username'])->toArray()); |
|
|
|
|
|
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Get the Photo Type Attribute. |
|
116
|
|
|
* |
|
117
|
|
|
* @return string |
|
118
|
|
|
*/ |
|
119
|
|
|
public function getTypeAttribute(): string |
|
120
|
|
|
{ |
|
121
|
|
|
return 'PHOTO'; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Get Room Id. |
|
126
|
|
|
* |
|
127
|
|
|
* @TODO: Add real RoomID |
|
128
|
|
|
* |
|
129
|
|
|
* @return int |
|
130
|
|
|
*/ |
|
131
|
|
|
public function getRoomIdAttribute(): int |
|
132
|
|
|
{ |
|
133
|
|
|
return 1; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Get User Name. |
|
138
|
|
|
* |
|
139
|
|
|
* @return string |
|
140
|
|
|
*/ |
|
141
|
|
|
public function getCreatorNameAttribute(): string |
|
142
|
|
|
{ |
|
143
|
|
|
return User::find($this->attributes['user_id'])->name; |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.