65 lines
1.8 KiB
PHP
65 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class IncoNutritionalValues extends Model
|
|
{
|
|
protected $fillable = [
|
|
'energy',
|
|
'energy_kj',
|
|
'protein',
|
|
'carbohydrates',
|
|
'sugar',
|
|
'fat',
|
|
'saturated_fatty_acids',
|
|
'dietary_fiber',
|
|
'salt',
|
|
'energy_percent',
|
|
'energy_kj_percent',
|
|
'protein_percent',
|
|
'carbohydrates_percent',
|
|
'sugar_percent',
|
|
'fat_percent',
|
|
'saturated_fatty_acids_percent',
|
|
'dietary_fiber_percent',
|
|
'salt_percent'
|
|
];
|
|
|
|
public static function convertTranslateXmlInco(array $xmlInco): array
|
|
{
|
|
$cvt = [
|
|
'val_energ_kcal_r' => 'energy',
|
|
'val_energ_kcal_p' => 'energy_percent',
|
|
'val_energ_kj_r' => 'energy_kj',
|
|
'pourcent_apport_ref_kjo_r' => 'energy_kj_percent',
|
|
'proteine_r' => 'protein',
|
|
'pourcent_apport_ref_pro_r' => 'protein_percent',
|
|
'sucre_r' => 'sugar',
|
|
'pourcent_apport_ref_sugar_r' => 'sugar_percent',
|
|
'mat_grass_r' => 'fat',
|
|
'pourcent_apport_ref_fat_r' => 'fat_percent',
|
|
'fib_alim_r' => 'dietary_fiber',
|
|
'pourcent_apport_ref_fibtg_r' => 'dietary_fiber_percent',
|
|
'glucides_r' => 'carbohydrates',
|
|
'glucides_p' => 'carbohydrates_percent',
|
|
'ags_r' => 'saturated_fatty_acids',
|
|
'pourcent_ags' => 'saturated_fatty_acids_percent',
|
|
'sel_r' => 'salt',
|
|
'pourcent_apport_ref_salteq_r' => 'salt_percent'
|
|
];
|
|
$o = [];
|
|
|
|
foreach ($cvt as $k => $t) {
|
|
$o[$t] = $xmlInco[$k] ?? null;
|
|
}
|
|
|
|
return $o;
|
|
}
|
|
|
|
public function product()
|
|
{
|
|
return $this->belongsTo(Products::class, 'product_id');
|
|
}
|
|
}
|