1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
6
|
|
|
use Illuminate\Support\Facades\Config; |
7
|
|
|
use Sofa\Eloquence\Eloquence; |
8
|
|
|
use Sofa\Eloquence\Mappable; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class Room. |
12
|
|
|
* |
13
|
|
|
* @property int id |
14
|
|
|
*/ |
15
|
|
|
class Room extends Model |
16
|
|
|
{ |
17
|
|
|
use Eloquence, Mappable; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Disable Timestamps. |
21
|
|
|
* |
22
|
|
|
* @var bool |
23
|
|
|
*/ |
24
|
|
|
public $timestamps = false; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Leader Board Rank. |
28
|
|
|
* |
29
|
|
|
* @var int |
30
|
|
|
*/ |
31
|
|
|
public $leaderboardRank = 1; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* The table associated with the model. |
35
|
|
|
* |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
protected $table = 'rooms'; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Primary Key of the Table. |
42
|
|
|
* |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
protected $primaryKey = 'id'; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* The attributes that will be mapped. |
49
|
|
|
* |
50
|
|
|
* @var array |
51
|
|
|
*/ |
52
|
|
|
protected $maps = ['uniqueId' => 'id', 'ownerName' => 'owner_name', 'ownerUniqueId' => 'owner_id', 'doorMode' => 'state', |
53
|
|
|
'leaderboardValue' => 'score', 'maximumVisitors' => 'users_max', 'habboGroupId' => 'guild_id', 'rating' => 'score', ]; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* The Appender(s) of the Model. |
57
|
|
|
* |
58
|
|
|
* @var array |
59
|
|
|
*/ |
60
|
|
|
protected $appends = ['uniqueId', 'leaderboardRank', 'thumbnailUrl', 'imageUrl', 'leaderboardValue', 'doorMode', 'maximumVisitors', |
61
|
|
|
'publicRoom', 'ownerUniqueId', 'ownerName', 'showOwnerName', 'categories', 'rating', ]; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* The attributes excluded from the model's JSON form. |
65
|
|
|
* |
66
|
|
|
* @var array |
67
|
|
|
*/ |
68
|
|
|
protected $hidden = ['owner_name', 'owner_id', 'is_public', 'state', 'password', 'model', 'users', 'users_max', 'guild_id', 'category', 'score', 'paper_floor', 'paper_wall', |
69
|
|
|
'paper_landscape', 'thickness_wall', 'wall_height', 'thickness_floor', 'moodlight_data', 'is_staff_picked', 'allow_other_pets', 'allow_other_pets_eat', 'allow_walkthrough', |
70
|
|
|
'allow_hidewall', 'chat_mode', 'chat_weight', 'chat_speed', 'chat_hearing_distance', 'chat_protection', 'override_model', 'who_can_mute', 'who_can_kick', 'who_can_ban', 'poll_id', |
71
|
|
|
'roller_speed', 'promoted', 'trade_mode', 'move_diagonally', ]; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Stores a new Room. |
75
|
|
|
* |
76
|
|
|
* @param string $roomName |
77
|
|
|
* @param string $description |
78
|
|
|
* @param string $model |
79
|
|
|
* @param int $maxUsers |
80
|
|
|
* @param int $roomCategory |
81
|
|
|
* @param int $floorPaper |
82
|
|
|
* @param int $wallPaper |
83
|
|
|
* @param float $landscapePaper |
84
|
|
|
* @param int $ownerId |
85
|
|
|
* @param string $ownerName |
86
|
|
|
* |
87
|
|
|
* @return Room |
88
|
|
|
*/ |
89
|
|
|
public function store(string $roomName, string $description, string $model, int $maxUsers, int $roomCategory, int $floorPaper, int $wallPaper, float $landscapePaper, int $ownerId, string $ownerName) |
90
|
|
|
{ |
91
|
|
|
$this->attributes['name'] = $roomName; |
92
|
|
|
$this->attributes['description'] = $description; |
93
|
|
|
$this->attributes['model'] = $model; |
94
|
|
|
$this->attributes['users_max'] = $maxUsers; |
95
|
|
|
$this->attributes['category'] = $roomCategory; |
96
|
|
|
$this->attributes['paper_floor'] = $floorPaper; |
97
|
|
|
$this->attributes['paper_wall'] = $wallPaper; |
98
|
|
|
$this->attributes['paper_landscape'] = $landscapePaper; |
99
|
|
|
$this->attributes['thickness_wall'] = 0; |
100
|
|
|
$this->attributes['wall_height'] = -1; |
101
|
|
|
$this->attributes['thickness_floor'] = 0; |
102
|
|
|
$this->attributes['owner_id'] = $ownerId; |
103
|
|
|
$this->attributes['owner_name'] = $ownerName; |
104
|
|
|
$this->timestamps = false; |
105
|
|
|
|
106
|
|
|
$this->save(); |
107
|
|
|
|
108
|
|
|
return $this; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Get Room Tags. |
113
|
|
|
* |
114
|
|
|
* @return array |
115
|
|
|
*/ |
116
|
|
|
public function getTagsAttribute(): array |
117
|
|
|
{ |
118
|
|
|
return array_filter(explode(';', $this->attributes['tags']), function ($element) { |
119
|
|
|
return !empty($element); |
120
|
|
|
}); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Get Image Url. |
125
|
|
|
* |
126
|
|
|
* @TODO: Get Real Full Room Image |
127
|
|
|
* |
128
|
|
|
* @return string |
129
|
|
|
*/ |
130
|
|
|
public function getImageUrlAttribute(): string |
131
|
|
|
{ |
132
|
|
|
return "//arcturus.wf/full_{$this->attributes['id']}.png"; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Get Thumbnail Url. |
137
|
|
|
* |
138
|
|
|
* @return string |
139
|
|
|
*/ |
140
|
|
|
public function getThumbnailUrlAttribute(): string |
141
|
|
|
{ |
142
|
|
|
$userName = Config::get('chocolatey.arcturus'); |
143
|
|
|
|
144
|
|
|
return "//arcturus.wf/camera/{$userName}/thumbnail_{$this->attributes['id']}.png"; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Return if need show Owner Name. |
149
|
|
|
* |
150
|
|
|
* @TODO: What this really does? |
151
|
|
|
* |
152
|
|
|
* @return bool |
153
|
|
|
*/ |
154
|
|
|
public function getShowOwnerNameAttribute(): bool |
155
|
|
|
{ |
156
|
|
|
return true; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Set a Leader Board Position. |
161
|
|
|
* |
162
|
|
|
* @param int $roomPosition |
163
|
|
|
*/ |
164
|
|
|
public function setLeaderBoardRankAttribute(int $roomPosition = 1) |
165
|
|
|
{ |
166
|
|
|
$this->leaderboardRank = $roomPosition; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Get Leader Board Rank. |
171
|
|
|
* |
172
|
|
|
* @return int |
173
|
|
|
*/ |
174
|
|
|
public function getLeaderBoardRankAttribute(): int |
175
|
|
|
{ |
176
|
|
|
return $this->leaderboardRank; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Get if the Room is Public. |
181
|
|
|
* |
182
|
|
|
* @return bool |
183
|
|
|
*/ |
184
|
|
|
public function getPublicRoomAttribute(): bool |
185
|
|
|
{ |
186
|
|
|
return $this->attributes['is_public'] == 1; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Get Room Category. |
191
|
|
|
* |
192
|
|
|
* @return array |
193
|
|
|
*/ |
194
|
|
|
public function getCategoriesAttribute(): array |
195
|
|
|
{ |
196
|
|
|
return [str_replace('}', '', str_replace('${', '', FlatCat::find($this->attributes['category'])->caption))]; |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
|