Custom Price / Land / User Order Homeparty

This commit is contained in:
Kevin Adametz 2021-08-20 18:22:21 +02:00
parent d46824a4ac
commit 51d81d8ec6
55 changed files with 1951 additions and 681 deletions

View file

@ -7,8 +7,10 @@
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use App\Models\Country;
use Illuminate\Database\Eloquent\Model;
use PHPUnit\Framework\Constraint\Count;
use Illuminate\Database\Eloquent\Collection;
/**
* Class Homeparty
@ -66,12 +68,15 @@ class Homeparty extends Model
'pos' => 'int',
'completed' => 'int',
'status' => 'int',
'step' => 'int',
'country_id' => 'int',
'order_to' => 'bool',
'active' => 'bool',
'default' => 'bool',
'token_active' => 'bool',
'settings' => 'array',
'order' => 'array'
'order' => 'array',
'card_info' => 'array',
];
protected $dates = [
@ -87,24 +92,33 @@ class Homeparty extends Model
'date',
'name',
'place',
'country_id',
'description',
'pos',
'completed',
'status',
'step',
'order_to',
'active',
'default',
'token',
'token_active',
'settings',
'order'
'order',
'card_info'
];
private $user_country;
public function auth_user()
{
return $this->belongsTo('App\User', 'auth_user_id');
}
public function country()
{
return $this->belongsTo('App\Models\Country', 'country_id');
}
public function homeparty_users()
{
return $this->hasMany('App\Models\HomepartyUser', 'homeparty_id');
@ -141,5 +155,32 @@ class Homeparty extends Model
public function getTokenLink(){
return url('homeparty/'.$this->token);
}
public function getCardInfo($key)
{
return isset($this->card_info[$key]) ? $this->card_info[$key] : null;
}
public function getUserCountry(){
if(!$this->user_country){
if($user_country_id = $this->getCardInfo('user_country_id')){
$this->user_country = Country::findOrFail($user_country_id);
}
}
return $this->user_country;
}
public function isPriceCurrency()
{
$user_country = $this->getUserCountry();
return ($user_country && $user_country->currency) ? true : false;
}
public function getPriceCurrencyUnit()
{
$user_country = $this->getUserCountry();
return ($user_country && $user_country->currency) ? $user_country->currency_unit : false;
}
}