Allow user to specify their bmr and override our computation

This commit is contained in:
Diogo Peralta Cordeiro 2025-01-03 18:25:43 +00:00
parent 20133867f3
commit 4256e5d315
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0

View File

@ -98,6 +98,10 @@
</select>
<br>
<label for="bmr">Meta de Calorias (opcional):</label>
<input type="number" name="bmr" id="bmr" value="<?php echo isset($_GET['bmr']) ? $_GET['bmr'] : ''; ?>">
<br>
<button type="submit">Gerar plano alimentar</button>
<button type="submit" name="rand">Forçar uma nova ementa</button>
</form>
@ -372,9 +376,9 @@ function getWeeksOfCurrentMonth() {
return $weeks;
}
function generateMonthPlan($includeWeekends, $is_female, $weight, $height, $age, $activity_level) {
function generateMonthPlan($includeWeekends, $is_female, $weight, $height, $age, $activity_level, $bmr = null) {
global $ingredientNutrition, $mealOptionsAndIngredients;
$bmr = calculateBMR($is_female, $weight, $height, $age, $activity_level);
$bmr = is_null($bmr) ? calculateBMR($is_female, $weight, $height, $age, $activity_level) : $bmr;
// https://www.healthline.com/nutrition/best-macronutrient-ratio
// These ranges are recommended by the Institute of Medicine and are widely accepted in nutritional science.
// https://www.nal.usda.gov/programs/fnic
@ -465,6 +469,7 @@ if ($_SERVER['REQUEST_METHOD'] != 'GET' || !isset($_GET['is_female'], $_GET['wei
$height = (int) $_GET['height'];
$age = (int) $_GET['age'];
$activity_level = (float) $_GET['activity_level'];
$bmr = (isset($_GET['bmr']) && !empty($_GET['bmr'])) ? (int) $_GET['bmr'] : null;
echo generateMonthPlan($includeWeekends, $is_female, $weight, $height, $age, $activity_level);
echo generateMonthPlan($includeWeekends, $is_female, $weight, $height, $age, $activity_level, $bmr);
}