Backend for songs.zachdecook.com
Song: Make it possible to sort by verse
Zach DeCook 2023-07-20
parent 653a6c4 · commit 5fc43b8
-rw-r--r--laravel/app/Song.php13
1 files changed, 13 insertions, 0 deletions
diff --git a/laravel/app/Song.php b/laravel/app/Song.php
index c4722a2..b8d2e4c 100644
--- a/laravel/app/Song.php
+++ b/laravel/app/Song.php
@@ -21,6 +21,19 @@ class Song extends Model
$bc = explode(':', $refs[0])[0];
return Song::where('verse', 'LIKE', "$bc:%")->orWhere('verse',"$bc")->orWhere('verse','like',$refs[0].";%")->orWhere('verse', 'LIKE', "%; $bc:%");
}
+ public function getPassagesAttribute() {
+ $parser = new BiblePassageParser();
+ $refs = $parser->parse($this->verse);
+ return $refs;
+ }
+ public static function passageSort($a, $b) {
+ try {
+ return $a->passages[0]->from()->integerNotation() <=> $b->passages[0]->from()->integerNotation();
+ } catch (\Exception $e) {
+ // I don't care.
+ }
+ return 0;
+ }
public function textTranspose($key)
{
$sc = new SongController();