HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/csb.komma.pro/vendor/komma/kms/src/Users/Models/KmsUser.php
<?php

namespace Komma\KMS\Users\Models;

use Komma\KMS\ActionLog\Models\ActionLog;
use Komma\KMS\Core\Attributes\Models\Traits\HasThumbnailInterface;
use Komma\KMS\Core\Attributes\Models\Traits\HasThumbnailTrait;
use Komma\KMS\Core\Entities\DisplayNameInterface;
use Komma\KMS\Core\Entities\DisplayNameTrait;
use Komma\KMS\Core\HasEmptyPasswordTrait;
use Komma\KMS\Documents\Kms\DocumentableInterface;
use Komma\KMS\Documents\Models\Document;
use Komma\KMS\Documents\DocumentsTrait;
use Komma\KMS\ActionLog\HasActionLogs;
use Komma\KMS\Core\Entities\HasSearchableAttributesForSidebarInterface;
use Komma\KMS\Notifications\KmsResetPasswordNotification;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Mollie\Api\Resources\Order;

/**
 * Class KmsUser
 *
 * @package App\Users\Models
 * @property int $id
 * @property string $password
 * @property string $email
 * @property string|null $first_name
 * @property string|null $last_name
 * @property \Carbon\Carbon $last_login_attempt
 * @property int $failed_login_attempts
 * @property int $telephone
 * @property string $culture
 * @property string $city
 * @property string $postal_code
 * @property int $house_number
 * @property string $street
 * @property int $company_vat_number_validated
 * @property string $company_vat_number
 * @property string $company_country
 * @property string $company_zip_code
 * @property string $company_city
 * @property string $company_house_number
 * @property string $company_street
 * @property string $chamber_of_commerce
 * @property string $company_name
 * @property \Carbon\Carbon|null $created_at
 * @property \Carbon\Carbon|null $updated_at
 * @property string|null $remember_token
 * @property-read \Illuminate\Notifications\DatabaseNotificationCollection|\Illuminate\Notifications\DatabaseNotification[] $notifications
 * @property int $role
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser whereChamberOfCommerce($value)
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser whereCity($value)
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser whereCompanyCity($value)
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser whereCompanyCountry($value)
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser whereCompanyHouseNumber($value)
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser whereCompanyName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser whereCompanyStreet($value)
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser whereCompanyVatNumber($value)
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser whereCompanyVatNumberValidated($value)
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser whereCompanyZipCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser whereCountry($value)
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser whereEmail($value)
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser whereFailedLoginAttempts($value)
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser whereFirstName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser whereHouseNumber($value)
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser whereLastLoginAttempt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser whereLastName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser wherePassword($value)
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser whereRememberToken($value)
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser whereRole($value)
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser whereStreet($value)
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser whereTelephone($value)
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser whereZipCode($value)
 * @mixin \Eloquent
 * @property string $company_postal_code
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser whereCompanyPostalCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser wherePostalCode($value)
 * @property-read \Illuminate\Database\Eloquent\Collection|Order[] $orders
 * @property-read \Illuminate\Database\Eloquent\Collection|ActionLog[] $actions
 * @property-read \Illuminate\Database\Eloquent\Collection|Document[] $documents
 * @property-read \Illuminate\Database\Eloquent\Collection|Document[] $images
 * @property-read \Illuminate\Database\Eloquent\Collection|Component[] $components
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser query()
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser whereCulture($value)
 * @property int $gender
 * @method static \Illuminate\Database\Eloquent\Builder|KmsUser whereGender($value)
 */
final class KmsUser extends Authenticatable implements DocumentableInterface, DisplayNameInterface, HasThumbnailInterface, HasSearchableAttributesForSidebarInterface {
    use Notifiable;
    use HasActionLogs;
    use DocumentsTrait;
    use DisplayNameTrait;
    use HasThumbnailTrait;
    use HasEmptyPasswordTrait;

    public const USERNAME_COLUMN_NAME = 'email';
    public const PASSWORD_COLUMN_NAME = 'password';

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = array('password', 'remember_token');

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['role', 'email', 'password', 'first_name', 'last_name', 'failed_login_attempts', 'culture', 'gender'];

    /**
     * The attributes that should be mutated to dates.
     *
     * @var array
     */
    protected $dates = ['created_at', 'updated_at', 'last_login_attempt'];

    /**
     * Returns an array containing model attributes with their values,
     * that will be used to search trough in the sidebar.
     *
     * @return array
     */
    public function searchableAttributesForSidebar(): array
    {
        return [
            'email' => $this->email
        ];
    }

    /**
     * @return MorphMany
     */
    public function documents():MorphMany
    {
        return $this->morphMany(Document::class, 'documentable');
    }

    /**
     * Send the password reset notification.
     *
     * @param  string $token
     * @return void
     */
    public function sendPasswordResetNotification($token)
    {
        //Send kms reset mail
        $this->notify(new KmsResetPasswordNotification($this, $token));
    }

    public function getAuthIdentifierName()
    {
        return $this->getKeyName();
    }

    /**
     * @return null|string
     */
    public function getDisplayName():?string
    {
        // If it is a new model the section name will filled by model.section.new
        if(!$this->exists) return null;
        return $this->first_name . ' ' . $this->last_name;
    }

    /**
     * @param $value
     */
    public function setGenderAttribute($value)
    {
        $this->attributes['gender'] = empty($value) ? 0 : $value;
    }

    /**
     * Checks if the user is at least a certain role
     *
     * @param int $role
     * @return bool
     * @see KmsUserRole
     */
    public function isAtLeast(int $role = null): bool
    {
        if(!$role) return true;
        if(!KmsUserRole::isValidItem($role)) throw new \InvalidArgumentException('The given role is not valid.');
        return ($this->role && $this->role <= $role);
    }

    /**
     * @param int $role
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public static function whereRoleIsAtLeast(int $role)
    {
        return self::query()->where('role', '<=', $role);
    }
}