parent
f03862b523
commit
1a43060996
42 changed files with 1160 additions and 83 deletions
79
app/Models/UserLevel.php
Normal file
79
app/Models/UserLevel.php
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class UserLevel extends Model
|
||||
{
|
||||
protected $table = 'user_levels';
|
||||
|
||||
protected $casts = ['trans_name' => 'array'];
|
||||
|
||||
protected $fillable = [
|
||||
'name', 'margin', 'pos', 'active',
|
||||
];
|
||||
|
||||
|
||||
/* public function childrens()
|
||||
{
|
||||
return $this->hasMany('App\Models\Attribute', 'parent_id', 'id');
|
||||
}
|
||||
*/
|
||||
|
||||
public function setPosAttribute($value){
|
||||
$this->attributes['pos'] = is_numeric($value) ? $value : null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function _format_number($value){
|
||||
return preg_replace("/[^0-9,]/", "", $value);
|
||||
}
|
||||
|
||||
public function setMarginAttribute( $value ) {
|
||||
$value = $this->_format_number($value);
|
||||
$this->attributes['margin'] = floatval(str_replace(',', '.', $value));
|
||||
}
|
||||
|
||||
public function getFormattedMargin()
|
||||
{
|
||||
if(!isset($this->attributes['margin'])){
|
||||
return "";
|
||||
}
|
||||
if(\App::getLocale() === "en"){
|
||||
return number_format($this->attributes['margin'], 2, '.', ',');
|
||||
}
|
||||
return number_format($this->attributes['margin'], 2, ',', '.');
|
||||
}
|
||||
|
||||
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, ', ');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue