adding actual useful feature
This commit is contained in:
@@ -71,31 +71,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();
|
||||
}
|
||||
@@ -224,14 +236,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) {
|
||||
@@ -241,6 +263,7 @@ 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();
|
||||
|
Reference in New Issue
Block a user