ldc-loue/app/Models/IncoNutritionalValue.php
Jérémy Munsch aadb5c0acc Sprint2
2022-07-18 08:24:42 +00:00

72 lines
1.5 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class IncoNutritionalValue extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'weight',
'energy',
'energy_kj',
'protein',
'carbohydrates',
'sugar',
'fat',
'saturated_fatty_acids',
'dietary_fiber',
'salt',
];
// * METHODS
/**
* Inherited from LG, will use for arcadia stream inbound
*
* @param array $xmlInco
* @return array
*/
public static function convertTranslateXmlInco(array $xmlInco): array
{
$cvt = [
'' => 'weight',
'val_energ_kcal_r' => 'energy',
'val_energ_kj_r' => 'energy_kj',
'proteine_r' => 'protein',
'sucre_r' => 'sugar',
'mat_grass_r' => 'fat',
'fib_alim_r' => 'dietary_fiber',
'glucides_r' => 'carbohydrates',
'ags_r' => 'saturated_fatty_acids',
'sel_r' => 'salt'
];
$o = [];
foreach ($cvt as $k => $t) {
$o[$t] = $xmlInco[$k] ?? null;
}
return $o;
}
// * RELATIONSHIPS
/**
* BelongsTo product relation
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function product()
{
return $this->belongsTo(Product::class);
}
}