X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FModels%2FTechnique.php;h=cc94327389a5d3476939c9a830398ee6fb5c3166;hb=212561cf1c6724b52c490104f5a2b4c3418b1c62;hp=446967125c8e98ebad935fb2a45d20cbeed1ada7;hpb=f1c8c3cc53a09d1c261875d2f482b6e19bc48a9a;p=alttp.git diff --git a/app/Models/Technique.php b/app/Models/Technique.php index 4469671..cc94327 100644 --- a/app/Models/Technique.php +++ b/app/Models/Technique.php @@ -4,11 +4,17 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\App; class Technique extends Model { use HasFactory; + public static function locale2lang($locale) { + if (strtolower(substr($locale, 0, 2)) == 'de') return 'de'; + return 'en'; + } + public function chapters() { return $this ->belongsToMany(Technique::class, 'technique_chapter', 'parent_id', 'child_id') @@ -28,10 +34,21 @@ class Technique extends Model return $this->hasMany(TechniqueTranslation::class); } + public function getTranslatedProperty($prop, $lang = null) { + if (is_null($lang)) $lang = App::getLocale(); + foreach ($this->translations as $translation) { + if ($translation->locale == $lang) { + return $translation->{$prop}; + } + } + return $this->{$prop}; + } + protected $casts = [ 'index' => 'boolean', 'requirements' => 'array', 'rulesets' => 'array', + 'title_icons' => 'array', ]; protected $with = [