public function organizeRecipe(array $recipe_array, $carbs_per_recipe, $protein_per_recipe, $fat_per_recipe) { $recipe_num = sizeof($recipe_array); $return = array(); $return['refs'] = array(); $return['macros'] = array(); $total['kcals'] = 0; $total['protein'] = 0; $total['carbs'] = 0; $total['fats'] = 0; foreach ($recipe_array as $recipe) { $recipe_description = $this->calcSingleRecipe($carbs_per_recipe, $protein_per_recipe, $fat_per_recipe, $recipe); $tmp_alimentos = array(); foreach ($recipe_description as $items) { foreach ($items as $item) { if (is_array($item)) { array_push($tmp_alimentos, array('name' => $item['name'], 'quantity' => $item['quantity'])); } } } $recipe_info = MfrUserRecipes::find($recipe)[0]; $tmp_ref = array('name' => $recipe_info->name, 'image' => $recipe_info->thumbnail, 'description' => $recipe_info->instructions, 'alimentos' => $tmp_alimentos, 'macros' => array(array('name' => Lang::get('kcals'), 'quantity' => ($recipe_description['macros']['carbs'] + $recipe_description['macros']['protein']) * 4 + $recipe_description['macros']['fats'] * 9), array('name' => Lang::get('protein'), 'quantity' => $recipe_description['macros']['protein']), array('name' => Lang::get('carbs'), 'quantity' => $recipe_description['macros']['carbs']), array('name' => Lang::get('fats'), 'quantity' => $recipe_description['macros']['fats']))); $total['kcals'] = $total['kcals'] + ($recipe_description['macros']['carbs'] + $recipe_description['macros']['protein']) * 4 + $recipe_description['macros']['fats'] * 9; $total['protein'] = $total['protein'] + $recipe_description['macros']['protein']; $total['carbs'] = $total['carbs'] + $recipe_description['macros']['carbs']; $total['fats'] = $total['fats'] + $recipe_description['macros']['fats']; array_push($return['refs'], $tmp_ref); } $return['macros'] = array(array('name' => Lang::get('kcals'), 'quantity' => $total['kcals']), array('name' => Lang::get('protein'), 'quantity' => $total['protein']), array('name' => Lang::get('carbs'), 'quantity' => $total['carbs']), array('name' => Lang::get('fats'), 'quantity' => $total['fats'])); return $return; }