124 lines
4.2 KiB
PHP
124 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Casts\AllegationCast;
|
|
use App\Casts\NutrionalValuesCast;
|
|
use App\Casts\PortionAmountCast as CastsNbPortion;
|
|
use App\Enums\XmlInco\PortionType;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* XmlInco
|
|
*
|
|
* @property-read integer $id Arcadia Id.
|
|
* @property-read string $name Product name or part of description.
|
|
*
|
|
* @property-read string|null $description The product description.
|
|
* @property-read string|null $tips Tips about the product.
|
|
* @property-read string|null $preparation_advices Preparation advices for the product.
|
|
* @property-read string|null $sell_arguments Selling argumentary for the product.
|
|
*
|
|
* @property-read \App\Lib\XmlInco\Allegations $allegations List allegations by types.
|
|
* @property-read array<string|integer,string[]> $ingredient_list List of ingredient and content warnings.
|
|
* @property-read array<integer,string> $allergen_list List of allergens.
|
|
* @property-read \App\Lib\XmlInco\NutritionalValues $nutritional_values Tableau des valeurs nutritionelles.
|
|
*
|
|
* @property-read \App\Lib\XmlInco\PortionAmount $portion_amount The portion amount for the product,
|
|
* could be exact or approximative.
|
|
* @property-read \App\Enums\XmlInco\PortionType $portion_type The portion type.
|
|
* @property-read boolean $is_seasonal The product is specific of a season.
|
|
* @property-read integer $arcadia_brand_id Arcadia brand Id.
|
|
*
|
|
* * RELATIONS
|
|
* @property-read \App\Models\ArcadiaBrand $arcadiaBrand The ArcadiaBrand that owns the XmlInco.
|
|
*/
|
|
class XmlInco extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
/**
|
|
* Indicates if an exception should be thrown instead of silently discarding non-fillable attributes.
|
|
*
|
|
* ! Override this to simplify xml parse job
|
|
*
|
|
* @var boolean
|
|
*/
|
|
protected static $modelsShouldPreventSilentlyDiscardingAttributes = false;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'id',
|
|
'name',
|
|
'description',
|
|
'tips',
|
|
'preparation_advices',
|
|
'sell_arguments',
|
|
'allegations',
|
|
'ingredient_list',
|
|
'allergen_list',
|
|
'nutritional_values',
|
|
'portion_amount',
|
|
'portion_type',
|
|
'is_seasonal',
|
|
'arcadia_brand_id',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be cast.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $casts = [
|
|
'ingredient_list' => 'array',
|
|
'allergen_list' => 'array',
|
|
'is_seasonal' => 'boolean',
|
|
'portion_amount' => CastsNbPortion::class,
|
|
'portion_type' => PortionType::class,
|
|
'allegations' => AllegationCast::class,
|
|
'nutritional_values' => NutrionalValuesCast::class,
|
|
];
|
|
|
|
/**
|
|
* Perform any actions required after the model boots.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected static function booted()
|
|
{
|
|
static::creating(function (self $model) {
|
|
// * Make sure portion type is coherent
|
|
if (!\is_null($model->portion_amount)) {
|
|
$model->portion_type = $model->portion_amount->getType();
|
|
} else {
|
|
$model->portion_type = null;
|
|
}
|
|
});
|
|
static::updating(function (self $model) {
|
|
// * Make sure portion type is coherent
|
|
if (!\is_null($model->portion_amount)) {
|
|
$model->portion_type = $model->portion_amount->getType();
|
|
} else {
|
|
$model->portion_type = null;
|
|
}
|
|
});
|
|
}
|
|
|
|
// * RELATIONS
|
|
|
|
/**
|
|
* Get the ArcadiaBrand that owns the XmlInco
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function arcadiaBrand(): BelongsTo
|
|
{
|
|
return $this->belongsTo(ArcadiaBrand::class);
|
|
}
|
|
}
|