about summary refs log tree commit diff
path: root/laravel/app/Song.php
diff options
context:
space:
mode:
authorZach DeCook <zachdecook@librem.one>2025-02-06 17:27:44 +0000
committerZach DeCook <zachdecook@librem.one>2025-02-06 17:27:44 +0000
commit9e8949e73ea94e40d84cc83e2cacf2f08a6bd11f (patch)
tree5fa91b8d28dad5be3163880986cc08a77da29fa7 /laravel/app/Song.php
parent336838ecb40db4aca6c2298a673cc787d2c24b69 (diff)
downloadprosongsa-9e8949e73ea94e40d84cc83e2cacf2f08a6bd11f.tar.gz
Songs page: seed the random order for suggestions
Diffstat (limited to 'laravel/app/Song.php')
-rw-r--r--laravel/app/Song.php6
1 files changed, 6 insertions, 0 deletions
diff --git a/laravel/app/Song.php b/laravel/app/Song.php
index b8d2e4c..ed2bf25 100644
--- a/laravel/app/Song.php
+++ b/laravel/app/Song.php
@@ -3,6 +3,7 @@
 namespace App;
 
 use Illuminate\Database\Eloquent\Model;
+use Illuminate\Support\Facades\DB;
 use App\Http\Controllers\SongController;
 use TechWilk\BibleVerseParser\BiblePassageParser;
 
@@ -13,6 +14,11 @@ class Song extends Model
     {
         return $this->belongsToMany('App\Playlist');
     }
+    public function scopeInRandomOrderSeeded($query, $id = 0) {
+        $seed = ((intval(now()->unix()/600) . $id)%100000)/100000;
+        DB::query()->selectRaw("SETSEED($seed)")->get();
+        $query->inRandomOrder();
+    }
     public static function whereVerse($passage)
     {
     	$parser = new BiblePassageParser();