adding actual useful feature

This commit is contained in:
x
2024-06-10 00:27:00 +02:00
committed by Abu Ottermann
parent 3077b2bede
commit 7990870f7c
4 changed files with 181 additions and 19 deletions

View File

@@ -67,31 +67,43 @@ class Video extends Model
return $this->belongsToMany(User::class, 'favorites', 'video_id', 'user_id');
}
public static function getFirstId($related = null) {
public static function getFirstId($related = null, $isTag = false) {
if ($related) {
return $related->videos()->filtered()->orderBy('id', 'ASC')->first()->id;
if (!$isTag) {
return $related->videos()->filtered()->orderBy('id', 'ASC')->first()->id;
}
return Video::withAnyTags($related)->filtered()->orderBy('id', 'ASC')->first()->id;
}
return static::filtered()->orderBy('id', 'ASC')->first()->id;
}
public static function getLastId($related = null) {
public static function getLastId($related = null, $isTag = false) {
if ($related) {
return $related->videos()->filtered()->orderBy('id', 'DESC')->first()->id;
if (!$isTag) {
return $related->videos()->filtered()->orderBy('id', 'DESC')->first()->id;
}
return Video::withAnyTags($related)->filtered()->orderBy('id', 'DESC')->first()->id;
}
return static::select('id')->filtered()->orderBy('id', 'DESC')->first()->id;
}
public function getNext($related = null) {
public function getNext($related = null, $isTag = false) {
if ($related) {
return $related->videos()->filtered()->where('id', '>', $this->id)->orderBy('id', 'ASC')->first();
if (!$isTag) {
return $related->videos()->filtered()->where('id', '>', $this->id)->orderBy('id', 'ASC')->first();
}
return Video::withAnyTags($related)->filtered()->where('id', '>', $this->id)->orderBy('id', 'ASC')->first();
} else {
return static::filtered()->where('id', '>', $this->id)->orderBy('id', 'ASC')->first();
}
}
public function getPrev($related = null) {
public function getPrev($related = null, $isTag = false) {
if ($related) {
return $related->videos()->filtered()->where('id', '<', $this->id)->orderBy('id', 'DESC')->first();
if (!$isTag) {
return $related->videos()->filtered()->where('id', '<', $this->id)->orderBy('id', 'DESC')->first();
}
return Video::withAnyTags($related)->filtered()->where('id', '<', $this->id)->orderBy('id', 'DESC')->first();
} else {
return static::filtered()->where('id', '<', $this->id)->orderBy('id', 'DESC')->first();
}
@@ -220,14 +232,24 @@ public function blurryThumb() {
}
}
public static function getRandom($related = null) {
public static function getRandom($related = null, $tag = false) {
if ($related) {
$id = $related->videos()->filtered()->countScoped()->count() - 1;
if (!$tag) {
$id = $related->videos()->filtered()->countScoped()->count() - 1;
if ($id < 0) {
return redirect()->back()->with('error', 'no videos found');
}
$id = mt_rand(0, $id);
return $related->videos()->filtered()->skip($id);
}
// jetzt sind wir im tag
$id = Video::withAnyTags($related)->filtered()->countScoped()->count()-1;
if ($id < 0) {
return redirect()->back()->with('error', 'no videos found');
}
$id = mt_rand(0, $id);
return $related->videos()->filtered()->skip($id);
$id = mt_rand(0,$id);
return Video::withAnyTags($related)->filtered()->skip($id);
}
$id = static::filtered()->countScoped()->count() - 1;
if ($id < 0) {
@@ -237,6 +259,16 @@ public function blurryThumb() {
return static::filtered()->skip($id);
}
public static function getSingleRandom($related = null) {
$query = $related ? $related->videos()->filtered() : static::filtered();
$count = $query->countScoped()->count();
if ($count < 1) {
return null; // Return null if no videos found
}
return $query->inRandomOrder()->first();
}
public function isSfw() {
return !$this->tags->contains(function ($key, $tag) {
return $tag->normalized === 'nsfw';