mivita/app/User.php
2019-11-23 15:02:41 +01:00

259 lines
8.3 KiB
PHP
Executable file

<?php
namespace App;
use Carbon\Carbon;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Support\Facades\Mail;
use App\Mail\MailResetPassword;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* App\User
*
* @property int $id
* @property string $name
* @property string $email
* @property string $password
* @property string|null $remember_token
* @property string|null $token
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection|\Illuminate\Notifications\DatabaseNotification[] $notifications
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereEmail($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User wherePassword($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereRememberToken($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereToken($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereUpdatedAt($value)
* @mixin \Eloquent
* @property int $confirmed
* @property string|null $confirmation_code
* @property string|null $confirmation_date
* @property string|null $confirmation_code_to
* @property int $confirmation_code_remider
* @property int $active
* @property string|null $active_date
* @property string|null $agreement
* @property int $admin
* @property string $lang
* @property string|null $notes
* @property string|null $last_login
* @property \Illuminate\Support\Carbon|null $deleted_at
* @property-read \App\Models\Account $account
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\UserUpdateEmail[] $user_update_email
* @method static bool|null forceDelete()
* @method static \Illuminate\Database\Query\Builder|\App\User onlyTrashed()
* @method static bool|null restore()
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereActive($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereActiveDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereAdmin($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereAgreement($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereConfirmationCode($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereConfirmationCodeRemider($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereConfirmationCodeTo($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereConfirmationDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereConfirmed($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereDeletedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereLang($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereLastLogin($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereNotes($value)
* @method static \Illuminate\Database\Query\Builder|\App\User withTrashed()
* @method static \Illuminate\Database\Query\Builder|\App\User withoutTrashed()
* @property int|null $account_id
* @method static \Illuminate\Database\Eloquent\Builder|\App\User newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\User newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\User query()
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereAccountId($value)
* @property int|null $wizard
* @property int|null $blocked
* @property string|null $payment_account
* @property string|null $payment_shop
* @property-read int|null $notifications_count
* @property-read \App\Models\UserShop $shop
* @property-read int|null $user_update_email_count
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereBlocked($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User wherePaymentAccount($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User wherePaymentShop($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereWizard($value)
*/
class User extends Authenticatable
{
use Notifiable;
use SoftDeletes;
protected $dates = ['deleted_at'];
protected $table = 'users';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'email', 'password', 'token',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token', 'token',
];
public function account()
{
return $this->belongsTo('App\Models\UserAccount', 'account_id');
}
public function shop()
{
return $this->hasOne('App\Models\UserShop', 'user_id', 'id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function user_update_email()
{
return $this->hasMany('App\Models\UserUpdateEmail', 'user_id', 'id');
}
/**
* @return bool
*/
public function isPasswort(){
if($this->password == env('APP_KEY')){
return false;
}
return true;
}
/**
* @return bool
*/
public function isAdmin()
{
if($this->admin >= 1){
return true;
}
return false;
}
/**
* @return bool
*/
public function isSuperAdmin()
{
if($this->admin >= 2){
return true;
}
return false;
}
/**
* @return bool
*/
public function isSySAdmin()
{
if($this->admin >= 3){
return true;
}
return false;
}
/**
* @return bool
*/
public function showSideNav()
{
if($this->active == 1 && $this->blocked == 0 && $this->wizard >= 10){
return true;
}
return false;
}
/**
* @return string
*/
public function getConfirmationDateFormat(){
if(!$this->attributes['confirmation_date']){ return ""; }
return Carbon::parse($this->attributes['confirmation_date'])->format(\Util::formatDateTimeDB());
}
/**
* @return string
*/
public function getActiveDateFormat(){
if(!$this->attributes['active_date']){ return ""; }
return Carbon::parse($this->attributes['active_date'])->format(\Util::formatDateTimeDB());
}
/**
* @return string
*/
public function getAgreementFormat(){
if(!$this->attributes['agreement']){ return ""; }
return Carbon::parse($this->attributes['agreement'])->format(\Util::formatDateTimeDB());
}
public function getPaymentAccountDateFormat(){
if(!$this->attributes['payment_account']){ return ""; }
return Carbon::parse($this->attributes['payment_account'])->format(\Util::formatDateTimeDB());
}
public function getPaymentShopDateFormat(){
if(!$this->attributes['payment_shop']){ return ""; }
return Carbon::parse($this->attributes['payment_shop'])->format(\Util::formatDateTimeDB());
}
/**
* @return string
*/
public function getLandByCountry(){
if($this->account && $this->account->country_id){
$code = $this->account->country->code;
if($code == "FR"){
return 'fr';
}
if($code == "CH"){
return 'de';
}
if($code == "NL"){
return 'nl';
}
if($code == "DE"){
return 'de';
}
}
return "de";
}
/**
* Send the password reset notification.
*
* @param string $token
* @return void
*/
public function sendPasswordResetNotification($token)
{
Mail::to($this->email)->send(new MailResetPassword($token, $this));
// $this->notify(new ResetPasswordNotification($token));
}
}