]> git.localhorst.tv Git - alttp.git/blobdiff - app/Models/Technique.php
exclude 0 scores from leaderboard calculation
[alttp.git] / app / Models / Technique.php
index 1a54a0e1b29767f6f7ce29d1efc485ec1b17328d..cc94327389a5d3476939c9a830398ee6fb5c3166 100644 (file)
@@ -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')
@@ -17,7 +23,36 @@ class Technique extends Model
                        ->using(TechniqueChapter::class);
        }
 
+       public function relations() {
+               return $this
+                       ->belongsToMany(Technique::class, 'technique_relations', 'from_id', 'to_id')
+                       ->withPivot('type')
+                       ->using(TechniqueRelation::class);
+       }
+
+       public function translations() {
+               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 = [
+               'translations',
+       ];
+
 }