X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FModels%2FTechnique.php;h=cc94327389a5d3476939c9a830398ee6fb5c3166;hb=8645b77ea2dc402f0265e1c8022ba18302506ca1;hp=f0a29d39ec3e975bf4ff973220ab83e50da25555;hpb=0586e04204885088f31ac9861446eb0759cc8d2f;p=alttp.git diff --git a/app/Models/Technique.php b/app/Models/Technique.php index f0a29d3..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,8 +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 = [