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;
}
}