Jeeeede Menge updates.
This commit is contained in:
19
app/Models/Comment.php
Normal file
19
app/Models/Comment.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Comment extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public function film() {
|
||||
return $this->belongsTo(Film::class, 'film');
|
||||
}
|
||||
|
||||
public function author() {
|
||||
return $this->belongsTo(User::class, 'user');
|
||||
}
|
||||
}
|
74
app/Models/Film.php
Normal file
74
app/Models/Film.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class Film extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public function comments() {
|
||||
return $this->hasMany(Comment::class, 'film');
|
||||
}
|
||||
|
||||
public function votes()
|
||||
{
|
||||
return $this->hasMany(Vote::class, 'film');
|
||||
}
|
||||
|
||||
public function suggester() {
|
||||
return $this->belongsTo(User::class, 'user');
|
||||
}
|
||||
|
||||
public function getBewertung() {
|
||||
if(!is_null($this->seen)) {
|
||||
$count = Comment::where('film', $this->id)->where('evaluation', '>', 0)->count();
|
||||
return $count > 0 ? Comment::where('film', $this->id)->where('evaluation', '>', 0)->sum('evaluation') / $count : 0;
|
||||
} else return 0;
|
||||
}
|
||||
|
||||
public function activeVotes() {
|
||||
return $this->votes()->leftJoin('users', 'votes.user', '=', 'users.id')->leftJoin('settings', function($join) {
|
||||
$join->on('users.id', '=', 'settings.user')->where('settings.key', '=', 'disabled');
|
||||
})->whereNull('settings.value');
|
||||
}
|
||||
|
||||
public function nextfilm() {
|
||||
$id = Setting::where('key', 'nextfilm')->first()->value;
|
||||
return static::load($id);
|
||||
}
|
||||
|
||||
public function isNext() {
|
||||
$next = Setting::where('key', 'nextfilm')->first()->value;
|
||||
return $next == $this->id;
|
||||
}
|
||||
|
||||
public function scopePopular($query) {
|
||||
$nextfilm = Setting::where('key', 'nextfilm')->first()->value;
|
||||
return $query->addSelect(DB::raw('films.*, COUNT(case when votes.vote IS TRUE then 1 end) as upvotes, COUNT(*) as votes'))
|
||||
->leftJoin('votes', 'votes.film', '=', 'films.id')
|
||||
->leftJoin('users', 'users.id', '=', 'votes.user')
|
||||
->whereNull('seen')->whereNull('rejected')
|
||||
->whereNot('films.id', '=', $nextfilm)
|
||||
->whereNot('users.disabled', '=', 1)
|
||||
->groupBy('films.id')
|
||||
->orderBy('upvotes', 'DESC')
|
||||
->orderBy('suggested', 'ASC')
|
||||
;
|
||||
}
|
||||
|
||||
public function scopeSeen($query) {
|
||||
return $query->whereNull('rejected')->whereNotNull('seen')->orderBy('seen', 'DESC');
|
||||
}
|
||||
|
||||
public function scopeRejected($query) {
|
||||
return $query->whereNull('seen')->whereNotNull('rejected')->orderBy('rejected', 'DESC');
|
||||
}
|
||||
|
||||
public function scopeSuggested($query) {
|
||||
return $query->whereNull('seen')->whereNull('rejected')->orderBy('updated_at', 'DESC');
|
||||
}
|
||||
}
|
15
app/Models/News.php
Normal file
15
app/Models/News.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class News extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public function author() {
|
||||
return $this->belongsTo(User::class, 'user');
|
||||
}
|
||||
}
|
19
app/Models/Setting.php
Normal file
19
app/Models/Setting.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Setting extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public function user() {
|
||||
return $this->belongsTo(User::class, 'user');
|
||||
}
|
||||
|
||||
public function scopeNextFilm($query) {
|
||||
return $query->where('key', 'nextfilm');
|
||||
}
|
||||
}
|
@@ -41,4 +41,38 @@ class User extends Authenticatable
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function comments() {
|
||||
return $this->hasMany(Comment::class, 'user');
|
||||
}
|
||||
|
||||
public function films() {
|
||||
return $this->hasMany(Film::class, 'user');
|
||||
}
|
||||
|
||||
public function votes() {
|
||||
return $this->hasMany(Vote::class, 'user');
|
||||
}
|
||||
|
||||
public function settings() {
|
||||
return $this->hasMany(Setting::class, 'user');
|
||||
}
|
||||
|
||||
public function news() {
|
||||
return $this->hasMany(News::class, 'user');
|
||||
}
|
||||
|
||||
public function getAvatar() {
|
||||
$settings = $this->settings()->where('key', '=', 'avatar')->first();
|
||||
return is_null($settings) ? "no-avatar.jpg" : $settings->value;
|
||||
}
|
||||
|
||||
public function isActive() {
|
||||
return !$this->disabled;
|
||||
}
|
||||
|
||||
public function isAdmin() {
|
||||
$settings = $this->settings()->where('key', '=', 'admin')->first();
|
||||
return !is_null($settings);
|
||||
}
|
||||
}
|
||||
|
15
app/Models/Vote.php
Normal file
15
app/Models/Vote.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Vote extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public function voter() {
|
||||
return $this->belongsTo(User::class, 'user');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user