mirror of https://github.com/kcal-app/kcal.git
Improve serving name handling for recipes and journal entries
This commit is contained in:
parent
c909d3b535
commit
bb3f1a2e1d
|
@ -144,7 +144,15 @@ class JournalEntryController extends Controller
|
|||
}
|
||||
|
||||
// Update summary
|
||||
$unit = $item->serving_unit_formatted ?? $ingredient['unit'];
|
||||
if (empty($item->serving_unit) && empty($item->serving_unit_name)) {
|
||||
$unit = null;
|
||||
}
|
||||
elseif (!empty($item->serving_unit_name)) {
|
||||
$unit = $item->serving_unit_formatted;
|
||||
}
|
||||
else {
|
||||
$unit = $ingredient['unit'];
|
||||
}
|
||||
$entries[$entry_key]->summary .= (!empty($entries[$entry_key]->summary) ? ', ' : null);
|
||||
$entries[$entry_key]->summary .= "{$ingredient['amount']} {$unit} {$item->name}";
|
||||
}
|
||||
|
|
|
@ -136,9 +136,13 @@ final class Food extends Model
|
|||
* Get the "formatted" serving unit (for custom unit support).
|
||||
*/
|
||||
public function getServingUnitFormattedAttribute(): ?string {
|
||||
$unit = $this->serving_unit;
|
||||
if (empty($unit)) {
|
||||
$unit = $this->serving_unit_name ?? null;
|
||||
// No unit or unit name can be used for e.g. "bell pepper" or "onion" so
|
||||
// the food name will be displayed directly.
|
||||
if (empty($this->serving_unit) && empty($this->serving_unit_name)) {
|
||||
$unit = null;
|
||||
}
|
||||
else {
|
||||
$unit = $this->serving_unit_name ?? $this->serving_unit ?? 'serving';
|
||||
}
|
||||
return $unit;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue