129 lines
5 KiB
PHP
129 lines
5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Services\Util;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use App\Models\UserLevel as ModelsUserLevel;
|
|
|
|
/**
|
|
* App\Models\UserLevel
|
|
*
|
|
* @property int $id
|
|
* @property string $name
|
|
* @property array|null $trans_name
|
|
* @property float|null $margin
|
|
* @property int|null $pos
|
|
* @property int $active
|
|
* @property int $default
|
|
* @property \Illuminate\Support\Carbon|null $created_at
|
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserLevel newModelQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserLevel newQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserLevel query()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserLevel whereActive($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserLevel whereDefault($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserLevel whereCreatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserLevel whereId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserLevel whereMargin($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserLevel whereName($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserLevel wherePos($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserLevel whereTransName($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserLevel whereUpdatedAt($value)
|
|
* @mixin \Eloquent
|
|
* @property int|null $next_id
|
|
* @property int|null $margin_shop
|
|
* @property int|null $qual_kp
|
|
* @property int|null $qual_tp
|
|
* @property string|null $growth_bonus
|
|
* @property int|null $pr_line_1
|
|
* @property int|null $pr_line_2
|
|
* @property int|null $pr_line_3
|
|
* @property int|null $pr_line_4
|
|
* @property int|null $pr_line_5
|
|
* @property int|null $pr_line_6
|
|
* @property-read UserLevel|null $next_user_level
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserLevel whereGrowthBonus($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserLevel whereMarginShop($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserLevel whereNextId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserLevel wherePrLine1($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserLevel wherePrLine2($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserLevel wherePrLine3($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserLevel wherePrLine4($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserLevel wherePrLine5($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserLevel wherePrLine6($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserLevel whereQualKp($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|UserLevel whereQualTp($value)
|
|
*/
|
|
class UserLevel extends Model
|
|
{
|
|
protected $table = 'user_levels';
|
|
|
|
protected $casts = ['trans_name' => 'array'];
|
|
|
|
protected $fillable = [
|
|
'next_id', 'name', 'margin', 'margin_shop', 'qual_kp', 'qual_tp', 'growth_bonus', 'pr_line_1', 'pr_line_2', 'pr_line_3', 'pr_line_4', 'pr_line_5', 'pr_line_6', 'pos', 'active', 'default',
|
|
];
|
|
|
|
|
|
public function next_user_level()
|
|
{
|
|
return $this->belongsTo('App\Models\UserLevel', 'next_id', 'id');
|
|
}
|
|
|
|
public function getNextUserLevels(){
|
|
//$ret = [0=>'Keinen'];
|
|
$ret = UserLevel::where('active', true)->where('id', '!=', $this->id)->orderBy('pos', 'asc')->get()->pluck('name', 'id')->toArray();
|
|
return array_add($ret, 0, '-> Keinen Karriere Level');
|
|
}
|
|
|
|
public function setPosAttribute($value){
|
|
$this->attributes['pos'] = is_numeric($value) ? $value : null;
|
|
|
|
}
|
|
|
|
public function setGrowthBonusAttribute($value)
|
|
{
|
|
$this->attributes['growth_bonus'] = $value !== null ? Util::reFormatNumber($value) : null;
|
|
}
|
|
public function getFormattedGrowthBonus()
|
|
{
|
|
return isset($this->attributes['growth_bonus']) ? Util::formatNumber($this->attributes['growth_bonus'],1) : "";
|
|
}
|
|
|
|
public function getFormattedMargin()
|
|
{
|
|
return isset($this->attributes['margin']) ? $this->attributes['margin'] : "";
|
|
}
|
|
|
|
|
|
public function getLang($key)
|
|
{
|
|
$lang = \App::getLocale();
|
|
if ($lang === 'de') {
|
|
return $this->{$key};
|
|
}
|
|
$trans = $this->getTrans($key, $lang);
|
|
if (!$trans || $trans == '') {
|
|
return $this->{$key};
|
|
}
|
|
return $trans;
|
|
}
|
|
|
|
public function getTrans($key, $lang)
|
|
{
|
|
$key = 'trans_' . $key;
|
|
if (!empty($this->{$key}[$lang])) {
|
|
return $this->{$key}[$lang];
|
|
}
|
|
}
|
|
|
|
public function getTranNames()
|
|
{
|
|
$ret = "";
|
|
foreach ((array) $this->trans_name as $value){
|
|
$ret .= $value.', ';
|
|
}
|
|
return rtrim($ret, ', ');
|
|
}
|
|
}
|