Skip to content

Commit

Permalink
Ref #141: add ingredients info on grocery list
Browse files Browse the repository at this point in the history
  • Loading branch information
LucileDT committed Jan 23, 2023
1 parent 425278b commit d138dbc
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 8 deletions.
25 changes: 25 additions & 0 deletions src/Service/GroceryListService.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public static function generateFormattedGroceryList(ArrayCollection $mealLists)
$item = [
'id' => $ingredientId,
'label' => $ingredient->getLabel(),
'brand' => $ingredient->getBrand(),
'quantity' => $quantity,
'unitQuantity' => $unitQuantity,
'unitSize' => $unitSize,
Expand Down Expand Up @@ -89,6 +90,30 @@ public static function generateFormattedGroceryList(ArrayCollection $mealLists)
$groceryList[$storeId]['checkNotNeeded'][$ingredientId]['unitQuantity'] += $unitQuantity;
}
}

if ($ingredient->hasStockCheckNeededBeforeBuying()) {
$groceryList[$storeId]['checkNeeded'][$ingredientId]['recipes'][$ingredientQuantityForRecipe->getRecipe()->getId()] = [
'id' => $ingredientQuantityForRecipe->getRecipe()->getId(),
'label' => $ingredientQuantityForRecipe->getRecipe()->getName(),
'mealCount' => $mealQuantity,
'quantity' => $quantity,
'unitQuantity' => $unitQuantity,
'unitSize' => $unitSize,
'measureType' => $ingredient->getMeasureType(),
'isMeasuredByUnit' => $isMeasuredByUnit,
];
} else {
$groceryList[$storeId]['checkNotNeeded'][$ingredientId]['recipes'][$ingredientQuantityForRecipe->getRecipe()->getId()] = [
'id' => $ingredientQuantityForRecipe->getRecipe()->getId(),
'label' => $ingredientQuantityForRecipe->getRecipe()->getName(),
'mealCount' => $mealQuantity,
'quantity' => $quantity,
'unitQuantity' => $unitQuantity,
'unitSize' => $unitSize,
'measureType' => $ingredient->getMeasureType(),
'isMeasuredByUnit' => $isMeasuredByUnit,
];
}
}
}
}
Expand Down
88 changes: 80 additions & 8 deletions templates/grocery_list/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,48 @@
{% if grocery.isMeasuredByUnit %}
({{ grocery.quantity }} {{ grocery.measureType }})
{% endif %}
<a href="{{ path('ingredient_show', {'id': grocery.id}) }}"
target="_blank"
class="text-muted">
<small>Voir la fiche ingrédient</small>
<a
class="btn btn-sm btn-info"
href="{{ path('ingredient_show', {'id': grocery.id}) }}"
target="_blank"
data-bs-toggle="tooltip"
title="Voir la fiche ingrédient"
>
<i class="ri-eye-fill"></i>
</a>
<button
type="button"
class="btn btn-sm btn-secondary"
title="Voir les détails"
data-bs-toggle="collapse"
data-bs-target="#details-{{ grocery.id }}"
>
<i class="ri-question-fill"></i>
</button>
</label>
<div class="collapse" id="details-{{ grocery.id }}">
<div class="card card-body border-0 mt-2">
<span><b>Marque :</b> {{ grocery.brand ?: 'générique' }}</span>
<b>Quantités :</b>
<ul>
{% for recipe in grocery.recipes %}
<li>
<a href="{{ path('recipe_show', { 'id': recipe.id }) }}">
{{ recipe.mealCount }} * {{ recipe.label }} :
</a>
{% if recipe.isMeasuredByUnit %}
{{ recipe.unitQuantity }}
{% else %}
{{ recipe.quantity }} {{ recipe.measureType }}
{% endif %}
{% if recipe.isMeasuredByUnit %}
({{ recipe.quantity }} {{ recipe.measureType }})
{% endif %}
</li>
{% endfor %}
</ul>
</div>
</div>
</div>
</div>
{% endfor %}
Expand All @@ -78,12 +114,48 @@
{% if grocery.isMeasuredByUnit %}
({{ grocery.quantity }} {{ grocery.measureType }})
{% endif %}
<a href="{{ path('ingredient_show', {'id': grocery.id}) }}"
target="_blank"
class="text-muted">
<small>Voir la fiche ingrédient</small>
<a
class="btn btn-sm btn-info"
href="{{ path('ingredient_show', {'id': grocery.id}) }}"
target="_blank"
data-bs-toggle="tooltip"
title="Voir la fiche ingrédient"
>
<i class="ri-eye-fill"></i>
</a>
<button
type="button"
class="btn btn-sm btn-secondary"
title="Voir les détails"
data-bs-toggle="collapse"
data-bs-target="#details-{{ grocery.id }}"
>
<i class="ri-question-fill"></i>
</button>
</label>
<div class="collapse" id="details-{{ grocery.id }}">
<div class="card card-body border-0 mt-2">
<span><b>Marque :</b> {{ grocery.brand ?: 'générique' }}</span>
<b>Quantités :</b>
<ul>
{% for recipe in grocery.recipes %}
<li>
<a href="{{ path('recipe_show', { 'id': recipe.id }) }}">
{{ recipe.mealCount }} * {{ recipe.label }} :
</a>
{% if recipe.isMeasuredByUnit %}
{{ recipe.unitQuantity }}
{% else %}
{{ recipe.quantity }} {{ recipe.measureType }}
{% endif %}
{% if recipe.isMeasuredByUnit %}
({{ recipe.quantity }} {{ recipe.measureType }})
{% endif %}
</li>
{% endfor %}
</ul>
</div>
</div>
</div>
</div>
{% endfor %}
Expand Down

0 comments on commit d138dbc

Please sign in to comment.