diff options
| author | Zach DeCook <zachdecook@librem.one> | 2022-08-27 13:28:18 +0000 |
|---|---|---|
| committer | Zach DeCook <zachdecook@librem.one> | 2022-08-27 13:28:18 +0000 |
| commit | c4e645d6c29884b6cb0c75775ea21380befe8c75 (patch) | |
| tree | 8f1bc53032162b170f49d5e30a1ac0a1574c5a48 /laravel/app/Song.php | |
| parent | 4f1afd6cb6506f5db479396766e3c6fb3701f6d7 (diff) | |
| download | prosongsa-c4e645d6c29884b6cb0c75775ea21380befe8c75.tar.gz | |
validation: use bible passage parser to validate verse references
Diffstat (limited to 'laravel/app/Song.php')
| -rw-r--r-- | laravel/app/Song.php | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/laravel/app/Song.php b/laravel/app/Song.php index a6cb0c0..0f7248a 100644 --- a/laravel/app/Song.php +++ b/laravel/app/Song.php @@ -4,6 +4,7 @@ namespace App; use Illuminate\Database\Eloquent\Model; use App\Http\Controllers\SongController; +use TechWilk\BibleVerseParser\BiblePassageParser; class Song extends Model { @@ -34,7 +35,7 @@ class Song extends Model public function setKeyAttribute($value) { - if (!$value) return; + if (!$value) return $this->attributes['key'] = null; if ($value[0]>="A"&&$value[0]<="G"){ $this->attributes['key'] = $value; } else { @@ -65,6 +66,15 @@ class Song extends Model file_put_contents("public/text/{$this->id}.txt", $text); } } + + public function setVerseAttribute($text) + { + if (!$text) return $this->attributes['verse'] = null; + $parser = new BiblePassageParser(); + // Can throw an exception. + return $this->attributes['verse'] = implode("; ", $parser->parse($text)); + } + public function getChordsAttribute($txt = null) { $txt = $txt ?? $this->text; |
