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/Neopoints/momsecurity.be/app/Komma/Kms/Core/AbstractTranslationModel.php
<?php
namespace App\Komma\Kms\Core;

use App\Komma\Kms\Core\Entities\DisplayNameTrait;
use App\Komma\Languages\Models\Language;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
 * Represents a translation for a AbstractTranslatableModel implementation
 *
 * @property string title
 * @property string description
 *
 * @note make sure that the implementation has a name attribute and not a title attribute
 * @see AbstractTranslatableModel
 */
abstract class AbstractTranslationModel extends Model
{
    use DisplayNameTrait;

    /**
     * @return BelongsTo relation That resolves to a TranslatableModelInterface
     * @see AbstractTranslatableModel
     */
    abstract public function translatable(): BelongsTo;

    /**
     * @return belongsTo relation That resolves to a Language model
     * @see Language
     */
    public function language():BelongsTo {
        return $this->belongsTo(Language::class);
    }

    /**
     * Returns the 2 character length iso 2 code of the language of the model
     *
     * @return string
     */
    public function getLanguageIso(){
        return $this->language()->first()->iso_2;
    }

    /**
     * Returns true or false depending on whether or not the translation can be considered empty
     *
     * @return bool
     */
    public function isEmpty():bool
    {
        $empty = true;

        foreach($this->attributes as $attributeName => $value)
        {
            if(substr($attributeName, -3) == '_id') continue;
            if($value != "" && $value != "[]") {
                $empty = false;
                break;
            }
        }

        return $empty;
    }
}