|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* rmarchiv.tk |
|
5
|
|
|
* (c) 2016-2017 by Marcel 'ryg' Hering |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace App\Models; |
|
9
|
|
|
|
|
10
|
|
|
use GeneaLabs\LaravelModelCaching\Traits\Cachable; |
|
11
|
|
|
use Laravel\Scout\Searchable; |
|
12
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
13
|
|
|
use Waavi\Translation\Traits\Translatable; |
|
14
|
|
|
use Spatie\Activitylog\Traits\LogsActivity; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class Game. |
|
18
|
|
|
* |
|
19
|
|
|
* @property int $id |
|
20
|
|
|
* @property string $title |
|
21
|
|
|
* @property string $subtitle |
|
22
|
|
|
* @property string $desc_md |
|
23
|
|
|
* @property string $desc_html |
|
24
|
|
|
* @property string $website_url |
|
25
|
|
|
* @property int $user_id |
|
26
|
|
|
* @property int $views |
|
27
|
|
|
* @property string $release_date |
|
28
|
|
|
* @property int $maker_id |
|
29
|
|
|
* @property int $lang_id |
|
30
|
|
|
* @property string $deleted_at |
|
31
|
|
|
* @property int $atelier_id |
|
32
|
|
|
* @property \Carbon\Carbon $created_at |
|
33
|
|
|
* @property \Carbon\Carbon $updated_at |
|
34
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereId($value) |
|
35
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereTitle($value) |
|
36
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereSubtitle($value) |
|
37
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereDescMd($value) |
|
38
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereDescHtml($value) |
|
39
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereWebsiteUrl($value) |
|
40
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereUserId($value) |
|
41
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereViews($value) |
|
42
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereReleaseDate($value) |
|
43
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereMakerId($value) |
|
44
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereLangId($value) |
|
45
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereDeletedAt($value) |
|
46
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereCreatedAt($value) |
|
47
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereUpdatedAt($value) |
|
48
|
|
|
* @mixin \Eloquent |
|
49
|
|
|
* @property-read \App\Models\User $user |
|
50
|
|
|
* @property-read \App\Models\Maker $maker |
|
51
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\GamesDeveloper[] $developer |
|
52
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Developer[] $developers |
|
53
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Screenshot[] $screenshots |
|
54
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Comment[] $comments |
|
55
|
|
|
* @property-read mixed $votes |
|
56
|
|
|
* @property-read \App\Models\Language $language |
|
57
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\GamesFile[] $gamefiles |
|
58
|
|
|
* @property string $youtube |
|
59
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereYoutube($value) |
|
60
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\TagRelation[] $tags |
|
61
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\UserCredit[] $credits |
|
62
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\GamesAward[] $awards |
|
63
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\Spatie\Activitylog\Models\Activity[] $activity |
|
64
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\GamesCoupdecoeur[] $cdcs |
|
65
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereAtelierId($value) |
|
66
|
|
|
* @property int $release_type |
|
67
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereReleaseType($value) |
|
68
|
|
|
* @property int $voteup |
|
69
|
|
|
* @property int $votedown |
|
70
|
|
|
* @property string $avg |
|
71
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereAvg($value) |
|
72
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereComments($value) |
|
73
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereVotedown($value) |
|
74
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Models\Game whereVoteup($value) |
|
75
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\Venturecraft\Revisionable\Revision[] $revisionHistory |
|
76
|
|
|
* @property string $desc_md_translation |
|
77
|
|
|
* @property int $license_id |
|
78
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Game whereDescMdTranslation($value) |
|
79
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Game whereLicenseId($value) |
|
80
|
|
|
* @property-read \App\Models\License $license |
|
81
|
|
|
*/ |
|
82
|
|
|
class Game extends Model |
|
83
|
|
|
{ |
|
84
|
|
|
use \Venturecraft\Revisionable\RevisionableTrait; |
|
85
|
|
|
//use Translatable; |
|
86
|
|
|
use LogsActivity; |
|
87
|
|
|
use Searchable; |
|
88
|
|
|
|
|
89
|
|
|
protected static $logAttributes = [ |
|
90
|
|
|
'title', |
|
91
|
|
|
'subtitle', |
|
92
|
|
|
'desc_md', |
|
93
|
|
|
'website_url', |
|
94
|
|
|
'user_id', |
|
95
|
|
|
'maker_id', |
|
96
|
|
|
'lang_id', |
|
97
|
|
|
'atelier_id', |
|
98
|
|
|
]; |
|
99
|
|
|
public $timestamps = true; |
|
|
|
|
|
|
100
|
|
|
protected $table = 'games'; |
|
|
|
|
|
|
101
|
|
|
protected $fillable = [ |
|
|
|
|
|
|
102
|
|
|
'title', |
|
103
|
|
|
'subtitle', |
|
104
|
|
|
'desc_md', |
|
105
|
|
|
'desc_html', |
|
106
|
|
|
'website_url', |
|
107
|
|
|
'user_id', |
|
108
|
|
|
'views', |
|
109
|
|
|
'release_date', |
|
110
|
|
|
'maker_id', |
|
111
|
|
|
'lang_id', |
|
112
|
|
|
'atelier_id', |
|
113
|
|
|
'release_type', |
|
114
|
|
|
'voteup', |
|
115
|
|
|
'votedown', |
|
116
|
|
|
'avg', |
|
117
|
|
|
'comments', |
|
118
|
|
|
'license_id', |
|
119
|
|
|
]; |
|
120
|
|
|
protected $hidden = [ |
|
|
|
|
|
|
121
|
|
|
'votes', |
|
122
|
|
|
]; |
|
123
|
|
|
|
|
124
|
|
|
protected $guarded = []; |
|
125
|
|
|
protected $appends = ['votes']; |
|
126
|
|
|
//protected $translatableAttributes = ['desc_md']; |
|
|
|
|
|
|
127
|
|
|
|
|
128
|
|
|
public function user() |
|
129
|
|
|
{ |
|
130
|
|
|
return $this->hasOne('App\Models\User', 'id', 'user_id'); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
public function maker() |
|
134
|
|
|
{ |
|
135
|
|
|
return $this->hasOne('App\Models\Maker', 'id', 'maker_id'); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public function developers() |
|
139
|
|
|
{ |
|
140
|
|
|
return $this->hasMany('App\Models\GamesDeveloper', 'game_id', 'id'); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
public function screenshots() |
|
144
|
|
|
{ |
|
145
|
|
|
return $this->hasMany('App\Models\Screenshot'); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
View Code Duplication |
public function getVotesAttribute() |
|
|
|
|
|
|
149
|
|
|
{ |
|
150
|
|
|
$vote['up'] = intval($this->comments()->sum('vote_up')); |
|
|
|
|
|
|
151
|
|
|
$vote['down'] = intval($this->comments()->sum('vote_down')); |
|
152
|
|
|
$vote['avg'] = @round(($vote['up'] - $vote['down']) / ($vote['up'] + $vote['down']), 2); |
|
|
|
|
|
|
153
|
|
|
//(voteup - votedown) / (voteup + votedown) |
|
154
|
|
|
return $vote; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
public function comments() |
|
|
|
|
|
|
158
|
|
|
{ |
|
159
|
|
|
return $this->hasMany('App\Models\Comment', 'content_id', 'id')->Where('content_type', '=', \DB::raw("'game'"))->with('user'); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
public function language() |
|
163
|
|
|
{ |
|
164
|
|
|
return $this->hasOne('App\Models\Language', 'id', 'lang_id'); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
public function gamefiles() |
|
|
|
|
|
|
168
|
|
|
{ |
|
169
|
|
|
return $this->hasMany('App\Models\GamesFile', 'game_id', 'id') |
|
170
|
|
|
->orderBy('release_type', 'desc') |
|
171
|
|
|
->orderBy('release_year', 'desc') |
|
172
|
|
|
->orderBy('release_month', 'desc') |
|
173
|
|
|
->orderBy('release_day', 'desc') |
|
174
|
|
|
->with('gamefiletype') |
|
175
|
|
|
->withTrashed(); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
public function tagCount() |
|
|
|
|
|
|
179
|
|
|
{ |
|
180
|
|
|
return $this->tags() |
|
181
|
|
|
->selectRaw('id, count(*) as tagcount') |
|
182
|
|
|
->groupBy('id'); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
public function tags() |
|
|
|
|
|
|
186
|
|
|
{ |
|
187
|
|
|
return $this->hasMany('App\Models\TagRelation', 'content_id', 'id')->Where('content_type', '=', \DB::raw("'game'"))->with('tag'); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
public function credits() |
|
191
|
|
|
{ |
|
192
|
|
|
return $this->hasMany('App\Models\UserCredit', 'game_id', 'id'); |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
public function awards() |
|
|
|
|
|
|
196
|
|
|
{ |
|
197
|
|
|
return $this->hasMany('App\Models\GamesAward', 'game_id', 'id')->Where('place', '<=', 3); |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
public function cdcs() |
|
201
|
|
|
{ |
|
202
|
|
|
return $this->hasMany('App\Models\GamesCoupdecoeur', 'game_id', 'id'); |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* Get the indexable data array for the model. |
|
207
|
|
|
* |
|
208
|
|
|
* @return array |
|
209
|
|
|
*/ |
|
210
|
|
|
public function toSearchableArray() |
|
211
|
|
|
{ |
|
212
|
|
|
return [ |
|
213
|
|
|
'id' => $this->id, |
|
214
|
|
|
'title' => $this->title, |
|
215
|
|
|
'subtitle' => $this->subtitle, |
|
216
|
|
|
]; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
public function license() |
|
220
|
|
|
{ |
|
221
|
|
|
return $this->hasOne('App\Models\License', 'id', 'license_id'); |
|
222
|
|
|
} |
|
223
|
|
|
} |
|
224
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.