about summary refs log tree commit diff
path: root/laravel
diff options
context:
space:
mode:
authorZach DeCook <zachdecook@librem.one>2022-05-11 13:27:03 +0000
committerZach DeCook <zachdecook@librem.one>2022-05-11 13:27:03 +0000
commit6288883d88c420e242ffc07e81d9ca315eec4a5a (patch)
tree6c4cefe2e06f2036a95e72c27f1bd56539989f1e /laravel
parentb5b0dc2fd788ce2e27bebb14562f2225c0078871 (diff)
downloadprosongsa-6288883d88c420e242ffc07e81d9ca315eec4a5a.tar.gz
gemini: Add feature to search by bible verse
Diffstat (limited to 'laravel')
-rw-r--r--laravel/app/Song.php7
-rwxr-xr-xlaravel/public/searchVerse.gmi29
2 files changed, 36 insertions, 0 deletions
diff --git a/laravel/app/Song.php b/laravel/app/Song.php
index 99b0aa4..6705dfa 100644
--- a/laravel/app/Song.php
+++ b/laravel/app/Song.php
@@ -12,6 +12,13 @@ class Song extends Model
     {
         return $this->belongsToMany('App\Playlist');
     }
+    public static function whereVerse($passage)
+    {
+    	$book = explode(' ',$passage)[0];
+    	$chapter = (int)explode(' ', $passage)[1];
+    	
+		return Song::where('verse', 'LIKE', "$book $chapter:%")->orWhere('verse',"$book $chapter");
+    }
     public function textTranspose($key)
     {
         $sc = new SongController();
diff --git a/laravel/public/searchVerse.gmi b/laravel/public/searchVerse.gmi
new file mode 100755
index 0000000..d779988
--- /dev/null
+++ b/laravel/public/searchVerse.gmi
@@ -0,0 +1,29 @@
+#!/usr/bin/php8
+<?php
+
+define('LARAVEL_START', microtime(true));
+require __DIR__.'/../vendor/autoload.php';
+require __DIR__.'/../load-eloquent.php';
+$app = require_once __DIR__.'/../bootstrap/app.php';
+$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
+use App\Song;
+
+$q = getenv('QUERY_STRING');
+if (!$q) {
+	printf("10 Enter a verse to search.\r\n");
+	exit(0);
+}
+
+$results = Song::whereVerse($q)->get(['id', 'verse', 'title']);
+
+if (!count($results)) {
+	printf("51 No songs found for '$q'.");
+	exit(0);
+}
+
+printf("20 text/gemini\r\n");
+?>
+<?php foreach($results as $song): ?>
+=> /song.gmi.php/<?=$song->id?> <?= $song->verse ?>: <?= $song->title ?>
+
+<?php endforeach; ?>