summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcos <cos>2015-02-05 22:53:39 +0100
committercos <cos>2015-02-05 22:53:39 +0100
commit341364c7a7882a5e05a0fb6a13efb4a51df3772a (patch)
tree2a18115dc251126976c06d5b6d8e00e419b15060
parent9db2116061714eb2f654f7683ded5390533a03a2 (diff)
downloadmat-341364c7a7882a5e05a0fb6a13efb4a51df3772a.zip
Hack cmd_showplan to display multiple dishes per meal.
-rwxr-xr-xmat52
1 files changed, 28 insertions, 24 deletions
diff --git a/mat b/mat
index e69f74b..dfd3d21 100755
--- a/mat
+++ b/mat
@@ -407,33 +407,37 @@ sub cmd_showplan {
}
for (my $i = 0; $i < $days; $i++) {
- my $sql = "SELECT recipe_id, mealtype, comment_id FROM plan WHERE date='".
- $dt->ymd()."';";
- my $ids = $db->selectall_hashref($sql, 'mealtype');
+ my $sql = "SELECT recipe_id, p.mealtype, comment_id FROM plan AS p JOIN ".
+ "mealtypes AS m ON p.mealtype=m.mealtype WHERE date='".$dt->ymd().
+ "' ORDER by m.id;";
+ my $plan = $db->selectall_arrayref($sql);
print $weekend_padding;
- for my $mealtype ('frukost', 'elvakaffe', 'lunch', 'fruktstund', 'middag') { # FIXME fetch from database
- if ($ids->{$mealtype}{'recipe_id'}) {
-
- printf "%-10s %-10s %3s|%s (%s)\n", ($mealtype eq "frukost" ? $dt->ymd() : # FIXME remove hard coded mealtype
- ($mealtype eq "elvakaffe" ? $dt->day_name() : "")), # FIXME remove hard coded mealtype
- $mealtype,
- ($ids->{$mealtype}{'recipe_id'} ? substr(get_plan_state($ids->{$mealtype}{'recipe_id'}, $dt->ymd()), 0, 1) : " "),
- get_recipe_name($ids->{$mealtype}{'recipe_id'}),
-# ($portions_left > 0) ? $portions_left : 'u',
- $ids->{$mealtype}{'recipe_id'},
-# get_recipe_uri($ids->{$mealtype}{'recipe_id'}),
-# "apa", "lemur", "katt", "hund";
- } elsif ($ids->{$mealtype}{'comment_id'}) {
- printf "%-10s %-13s |%s\n",
- ($mealtype eq "frukost" ? $dt->ymd() : # FIXME remove hard coded mealtype
- ($mealtype eq "elvakaffe" ? $dt->day_name() : "")), $mealtype, # FIXME remove hard coded mealtype
- get_comment($ids->{$mealtype}{'comment_id'});
+ my $last_mealtype = "";
+ for my $meal ( @$plan ) {
+ my $mealtype = $meal->[1];
+ if ( $mealtype ne $last_mealtype ) {
+ print "\n";
+ if ($meal->[0]) {
+ printf "%-10s %-10s %3s|%s (%s)", ($last_mealtype eq "" ? $dt->ymd() :
+ ($mealtype eq "elvakaffe" ? $dt->day_name() : "")), # FIXME remove hard coded mealtype
+ $mealtype,
+ ($meal->[0] ? substr(get_plan_state($meal->[0], $dt->ymd()), 0, 1) : " "),
+ get_recipe_name($meal->[0]),
+ $meal->[0],
+ } elsif ($meal->[2]) {
+ printf "%-10s %-13s |%s",
+ ($last_mealtype eq "" ? $dt->ymd() :
+ ($mealtype eq "elvakaffe" ? $dt->day_name() : "")), $mealtype, # FIXME remove hard coded mealtype
+ get_comment($meal->[2]);
+ } else {
+ printf "%-10s %-13s | ",
+ ($last_mealtype eq "" ? $dt->ymd() :
+ ($mealtype eq "elvakaffe" ? $dt->day_name() : "")), $mealtype; # FIXME remove hard coded mealtype
+ }
} else {
- printf "%-10s %-13s | \n",
- ($mealtype eq "frukost" ? $dt->ymd() : # FIXME remove hard coded mealtype
- ($mealtype eq "elvakaffe" ? $dt->day_name() : "")), $mealtype; # FIXME remove hard coded mealtype
-# printf "%-24s | \n", $dt->ymd();
+ print " + ", get_recipe_name($meal->[0]), " (", $meal->[0], ")";
}
+ $last_mealtype = $mealtype;
}
print "\n";
$dt->add(days => 1);