diff options
author | cos <cos> | 2015-02-05 17:58:16 +0100 |
---|---|---|
committer | cos <cos> | 2015-02-05 17:58:16 +0100 |
commit | c7672c8168bd9dea41e77c1f17572cf099e06ec6 (patch) | |
tree | 70eaa2cc4af033f7ba29d724d84e716975497b52 | |
parent | f1020f3096ecff934ad93bb78ba597ff4249e068 (diff) | |
download | mat-c7672c8168bd9dea41e77c1f17572cf099e06ec6.zip |
Make cmd_setmeal and cmd_showplan handle several mealtypes per day.
-rwxr-xr-x | mat | 43 |
1 files changed, 25 insertions, 18 deletions
@@ -124,8 +124,7 @@ my @schedule = ( ); sub cmd_setmeal { - my ( $date, $recipe_id ) = @_; - my $mealtype = "lunch"; + my ( $date, $mealtype, $recipe_id ) = @_; if ($date =~ /^Mon|Tue|Wed|Thu|Fri|Sat|Sun/) { my $wday; @@ -144,6 +143,7 @@ sub cmd_setmeal { $date = $dt->ymd(); } + return unless $mealtype =~ "^(frukost)|(elvakaffe)|(lunch)|(fruktstund)|(middag)\$"; return unless $date =~ "^[0-9]{4}-[0-9]{2}-[0-9]{2}\$"; return -1 unless $recipe_id =~ "^[0-9]+\$"; @@ -421,27 +421,34 @@ sub cmd_showplan { return -1 unless $date =~ "^[0-9]{4}-[0-9]{2}-[0-9]{2}\$"; $dt = DateTime::Format::ISO8601->parse_datetime( $date ); } else { - $dt = DateTime->now(); + $dt = DateTime->now(locale => "sv_SE"); # FIXME Don't hårdkoda svenska, tack! # FIXME now() is not start of day, set hour, minute and such to 0 } - for (my $i = 0; $i < 14; $i++) { + for (my $i = 0; $i < 7; $i++) { my $sql = "SELECT recipe_id, mealtype, comment_id FROM plan WHERE date='". $dt->ymd()."';"; - my @ids = $db->selectrow_array($sql); - + my $ids = $db->selectall_hashref($sql, 'mealtype'); print $weekend_padding; - if ($ids[0]||$ids[2]) { - printf "%9s %-10s %3s|%s %s%s%s%s\n", $dt->ymd(), $ids[1], - (defined($ids[0]) ? $ids[0] : ""), - (defined($ids[0]) ? substr(get_plan_state($dt->ymd()), 0, 1) : " "), - (defined($ids[0]) ? get_recipe_name($ids[0]).", " : ""), - (defined($ids[0]) ? get_recipe_uri($ids[0]) : ""), - (defined($ids[0]) && defined($ids[2]) ? ", " : ""), - (defined($ids[2]) ? get_comment($ids[2]) : ""); - } else { - printf "%-24s | \n", $dt->ymd(); + for my $mealtype ('frukost', 'elvakaffe', 'lunch', 'fruktstund', 'middag') { # FIXME fetch from database + if ($ids->{$mealtype}{'recipe_id'}) { + printf "%10s %-10s %3s|%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'}, + get_recipe_name($ids->{$mealtype}{'recipe_id'}), +# get_recipe_uri($ids->{$mealtype}{'recipe_id'}), +# get_comment($ids->{$mealtype}{'recipe_id'}); +# "apa", "lemur", "katt", "hund"; +## substr(get_plan_state($dt->ymd()), 0, 1) : " "), + } 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 "\n"; $dt->add(days => 1); if($dt->day_of_week == 1) { $weekend_padding = "\n"; @@ -474,7 +481,7 @@ sub cmd_help() { print "editrecipe <recipe_id>\n"; print "showrecipe <recipe_id>\n"; print "movemeal <source_date> <destination_date>\n"; - print "setmeal <date> <meal_id>\n"; + print "setmeal <date> <mealtype> <meal_id>\n"; print "setstate <date> <idea|sourced|frozen|ready>\n"; print "randmeal <date>\n"; print "showplan [date]\n"; @@ -835,7 +842,7 @@ if ($ARGV[0]) { } elsif ( $ARGV[0] eq "movemeal") { print "Command failed!\n" unless (cmd_movemeal($ARGV[1], $ARGV[2]) >= 0); } elsif ( $ARGV[0] eq "setmeal") { - print "Command failed!\n" unless (cmd_setmeal($ARGV[1], $ARGV[2]) >= 0); + print "Command failed!\n" unless (cmd_setmeal($ARGV[1], $ARGV[2], $ARGV[3]) >= 0); } elsif ( $ARGV[0] eq "setstate") { print "Command failed!\n" unless (cmd_setstate($ARGV[1], $ARGV[2]) >= 0); } elsif ( $ARGV[0] eq "randmeal") { |