'array', 'nutritional_values' => 'array', ]; /** * The Laravel disk name * * @var string */ protected $disk = 'inco'; /** * Storage path * * @var string */ protected $imagesPath = 'images'; /** * The files to ignore * * @var array */ protected $ignoreFiles = [ '.gitignore', '.gitkeep' ]; /** * retrieve a collection of medias * * @return Collection */ public function getMediasAttribute() { /** @var Filesystem */ $disk = $this->getDisk(); $files = $disk->files($this->imagesPath); $collFiles = new Collection(); // /** @var File */ foreach ($files as $file) { $pi = \pathinfo($file, \PATHINFO_BASENAME); if (in_array($pi, $this->ignoreFiles)) { continue; } if (!in_array($pi, array($this->id))) { continue; } $image = base64_encode($disk->get($file)); $element = array( "filename" => $pi, "imgdata" => $image ); $collFiles->add($element); } return $collFiles; } /** * Get the concerned disk * * @return Filesystem */ protected function getDisk(): Filesystem { return Storage::disk($this->disk); } /** * getter * * @return string */ public function getNiceStringAttribute() { return sprintf('%s - %s', $this->id, $this->descriptif); } /** * update local info * * @return void */ public function updateLocalProductInfo() { $foodProduct = FoodProduct::where('no_art', $this->id)->first(); if (!empty($foodProduct)) { /** Info produits à suggerer lors de l'édition * this->descriptif (doit aller dans la table products) * $table->text('preparation')->nullable(); => $this->conseil_prepa * $table->text('selling_argument')->nullable(); => $this->arg_vente * infos produit maj automatique */ $foodProduct->ingredients = $this->lst_ing; $foodProduct->allergens = $this->lib_allergene; /** Les types de correspondent pas * numeric ($foodProduct->servings) = string (exemple this->nb_portion = '1/2'). */ $nutri_values = $this->nutritional_values; if (!empty($nutri_values)) { // Maj des info nutri locales. // Pour la ref. $foodProduct->nv_ref_weight_g = $nutri_values["taille_ref"]; // Energie Kj. $foodProduct->nv_kj = $nutri_values["val_energ_kj_r"]; // Energie Kcal. $foodProduct->nv_kcal = $nutri_values["val_energ_kcal_r"]; // Graisses. $foodProduct->nv_fat_g = $nutri_values["mat_grass_r"]; // Dont acides gras saturés. $foodProduct->nv_sat_fat_g = $nutri_values["ags_r"]; // Glucides. $foodProduct->nv_carb_g = $nutri_values["glucides_r"]; // Dont sucres. $foodProduct->nv_sugar_g = $nutri_values["sucre_r"]; // Fibres alimentaires. $foodProduct->nv_fiber_g = $nutri_values["fib_alim_r"]; // Protéines. $foodProduct->nv_protein_g = $nutri_values["proteine_r"]; // Sel. $foodProduct->nv_salt_g = $nutri_values["sel_r"]; /** Autres valeurs dispos * $nutri_values["sodium_r"]; * $nutri_values["ener_e14_r"]; * $nutri_values["fruits_r"]; * $nutri_values["fruits_coque_sech_r"]; * $nutri_values["ener_kjo_r"]; * $nutri_values["fatsat_r"]; * $nutri_values["choval_r"]; * $nutri_values["sugar_r"]; * $nutri_values["fibtg_r"]; * $nutri_values["pro_r"]; * $nutri_values["salteq_r"]; */ // Valeurs nutritionnelles par portion. // Taille portion en grammes. $foodProduct->nv_serving_size_g = $nutri_values["taille_port"]; // Energie Kj. $foodProduct->nv_serving_kj = $nutri_values["val_energ_kj_p"]; // Energie Kcal. $foodProduct->nv_serving_kcal = $nutri_values["val_energ_kcal_p"]; // Graisses. $foodProduct->nv_serving_fat_g = $nutri_values["mat_grass_p"]; // Dont acides gras saturés. $foodProduct->nv_serving_sat_fat_g = $nutri_values["ags_p"]; // Glucides. $foodProduct->nv_serving_carb_g = $nutri_values["glucides_p"]; // Dont sucres. $foodProduct->nv_serving_sugar_g = $nutri_values["sucre_p"]; // Fibres alimentaires. $foodProduct->nv_serving_fiber_g = $nutri_values["fib_alim_p"]; // Protéines. $foodProduct->nv_serving_protein_g = $nutri_values["proteine_p"]; // Sel. $foodProduct->nv_serving_salt_g = $nutri_values["sel_p"]; /** * autres valeurs disponibles * $nutri_values["sodium_p"]; * $nutri_values["fruits_p"]; */ // Apports journaliers. // Energie % recommandé. $foodProduct->nv_daily_energy = $nutri_values["pourcent_apport_ref_kjo_r"]; // Graisses. $foodProduct->nv_daily_fat = $nutri_values["pourcent_apport_ref_fat_r"]; // Dont acides gras saturés. $foodProduct->nv_daily_sat_fat = $nutri_values["pourcent_apport_ref_fatsat_r"]; // Glucides. $foodProduct->nv_daily_carb = $nutri_values["pourcent_apport_ref_choval_r"]; // Dont sucres. $foodProduct->nv_daily_sugar = $nutri_values["pourcent_apport_ref_sugar_r"]; // Fibres alimentaires. $foodProduct->nv_daily_fiber = $nutri_values["pourcent_apport_ref_fibtg_r"]; // Protéines. $foodProduct->nv_daily_protein = $nutri_values["pourcent_apport_ref_pro_r"]; // Sel. $foodProduct->nv_daily_salt = $nutri_values["pourcent_apport_ref_salteq_r"]; // Autre valeur dispo $nutri_values["pourcent_apport_ref_e14_r"] . // Nutriscore. $foodProduct->nutriscore = $nutri_values["classement"]; /** * Infos n'ayant pas de mapping * * $nutri_values["val_energ_kj_nut"]; * $nutri_values["val_energ_kcal_nut"]; * $nutri_values["mat_grass_nut"]; * $nutri_values["ags_nut"]; * $nutri_values["glucides_nut"]; * $nutri_values["sucre_nut"]; * $nutri_values["sucre_r"]; * $nutri_values["fib_alim_nut"]; * $nutri_values["proteine_nut"]; * $nutri_values["sel_nut"]; * $nutri_values["apport_ref"]; * $nutri_values["fruits_coque_sech_p"]; * $nutri_values["ener_e14_p"]; * $nutri_values["pourcent_apport_ref_e14_p"]; * $nutri_values["ener_kjo_p"]; * $nutri_values["pourcent_apport_ref_kjo_p"]; * $nutri_values["fat_p"]; * $nutri_values["pourcent_apport_ref_fat_p"]; * $nutri_values["fatsat_p"]; * $nutri_values["pourcent_apport_ref_fatsat_p"]; * $nutri_values["choval_p"]; * $nutri_values["pourcent_apport_ref_choval_p"]; * $nutri_values["sugar_p"]; * $nutri_values["pourcent_apport_ref_sugar_p"]; * $nutri_values["fibtg_p"]; * $nutri_values["pourcent_apport_ref_fibtg_p"]; * $nutri_values["pro_p"]; * $nutri_values["pourcent_apport_ref_pro_p"]; * $nutri_values["salteq_p"]; * $nutri_values["pourcent_apport_ref_salteq_p"]; * $nutri_values["apport_port"]; * $nutri_values["part_p"]; * $nutri_values["part_g"]; * $nutri_values["part_l"]; * $nutri_values["p_sur_l"]; * $nutri_values["pourcent_ags"]; * $nutri_values["pourcent_agi"]; * $nutri_values["pourcent_ss"]; * $nutri_values["pourcent_amidon"]; * $nutri_values["composante_n"]; * $nutri_values["composante_p"]; * $nutri_values["pourcent_fruits"]; * $nutri_values["mat_grass_r_prec"]; * $nutri_values["ags_r_prec"]; * $nutri_values["glucides_r_prec"]; * $nutri_values["sucre_r_prec"]; * $nutri_values["fib_alim_r_prec"]; * $nutri_values["proteine_r_prec"]; * $nutri_values["sel_r_prec"]; * $nutri_values["sodium_r_prec"]; * $nutri_values["fruits_r_prec"]; * $nutri_values["fruits_coque_sech_r_prec"]; * $nutri_values["score_nutri"]; */ }//end if $foodProduct->save(); }//end if } }