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/SBogers47/leden.ehbocranendonck.nl/app/KommaApp/Competences/Models/Competence.php
<?php

namespace App\KommaApp\Competences\Models;

use App\KommaApp\Courses\Models\Course;
use App\KommaApp\DisplayNameTrait;
use App\KommaApp\Documents\Kms\DocumentableInterface;
use App\KommaApp\Documents\Models\Document;
use App\KommaApp\Images\Models\Image;
use App\KommaApp\Kms\Core\AbstractTranslatableModel;
use App\KommaApp\Users\Models\User;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;


/**
 * App\KommaApp\Competences\Models\Competence
 *
 * @property int $id
 * @property int $active
 * @property string $date
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\KommaApp\Documents\Models\Document[] $documents
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\KommaApp\Images\Models\Image[] $images
 * @property-read \App\KommaApp\Competences\Models\CompetenceTranslation $translation
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\KommaApp\Competences\Models\CompetenceTranslation[] $translations
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Competences\Models\Competence whereActive($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Competences\Models\Competence whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Competences\Models\Competence whereDate($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Competences\Models\Competence whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Competences\Models\Competence whereUpdatedAt($value)
 * @mixin \Eloquent
 * @property int $renew_interval
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\KommaApp\Courses\Models\Course[] $courses
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\KommaApp\Users\Models\User[] $users
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Competences\Models\Competence whereRenewInterval($value)
 */
class Competence extends AbstractTranslatableModel implements DocumentableInterface {
    use DisplayNameTrait;

    protected $kmsClass = Competence::class;

    const RenewEachHalfYear = 1;
    const RenewEachYear = 2;
    const RenewEachTwoYear = 3;

    //Competences status related to the current authenticated user
    const StatusUnknown = 'unknown';
    const StatusMissing = 'missing';
    const StatusValid = 'valid';
    const StatusExpired = 'expired';
    const StatusAlmostExpired = 'almost_expired';

    const sortOrder = [
        self::StatusValid => 1,
        self::StatusAlmostExpired => 2,
        self::StatusExpired => 3,
        self::StatusMissing => 4,
        self::StatusUnknown => 5,
    ];

    /*
    * Transient properties on Eloquent models
    * These are not saved to database.
    */
    public $thumbnail = false;

    /** @var string $authUserCompetenceStatus to keep track of the competence status for the current authenticated user. Used by the course service */
    public $authUserCompetenceStatus = self::StatusUnknown;

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

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'Competences';

    protected $fillable = ['active', 'renew_interval'];

    /**
     * The relations to eager load on every query.
     *
     * @var array
     */
    protected $with = ['users'];

    /**
     * Get the images from the current Competence
     *
     * @return \Illuminate\Database\Eloquent\Relations\hasMany
     */
    public function images()
    {
        /**
         * On the Image model is an MorphTo relation
         * By using a hasMany relation:
         * where the imageable_type is filled in with the KmsClass
         * And the imageable_id is set as the foreign_id,
         * we can collect the images of the given model directly.
         *
         */
        return $this->hasMany(Image::class, 'imageable_id')
            ->where('imageable_type', '=', $this->kmsClass);
    }

    public function __get($key)
    {
        if($key == 'title' && $this->exists) {
            return $this->translations->first()->name;
        }
        self::$translationKeyNew = 'kms/competences.new';

        return parent::__get($key); // TODO: Change the autogenerated stub
    }

    /**
     * Gets the translation models for this model
     *
     * @return HasMany that resolves to AbstractTranslationModel instances
     */
    public function translations(): HasMany
    {
        return $this->hasMany(CompetenceTranslation::class);
    }


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

    public function users(): BelongsToMany
    {
        return $this->belongsToMany(User::class);
    }

    public function courses(): BelongsToMany
    {
        return $this->belongsToMany(Course::class);
    }

}