summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcos <cos>2011-08-11 13:09:05 +0200
committercos <cos>2011-08-11 13:09:05 +0200
commit515898d79ed8e608e411a4d65f2de4c8d3e1fb9f (patch)
treed8ab07389c02efc9578799c41ae9a735306a86d8
parentf2f4a79bbed64372811e60d3f90714b6d26855ab (diff)
downloadmat-515898d79ed8e608e411a4d65f2de4c8d3e1fb9f.zip
Added states to planned meals.
-rwxr-xr-xmat47
1 files changed, 46 insertions, 1 deletions
diff --git a/mat b/mat
index 63c6a73..0aef88a 100755
--- a/mat
+++ b/mat
@@ -123,6 +123,38 @@ sub cmd_setmeal {
return 0;
}
+sub cmd_setstate {
+ my ( $date, $state ) = @_;
+ my $mealtype = "lunch";
+
+ if ($date =~ /^Mon|Tue|Wed|Thu|Fri|Sat|Sun/) {
+ my $wday;
+ $wday = 1 if ($date =~ /^Mon/);
+ $wday = 2 if ($date =~ /^Tue/);
+ $wday = 3 if ($date =~ /^Wed/);
+ $wday = 4 if ($date =~ /^Thu/);
+ $wday = 5 if ($date =~ /^Fri/);
+ $wday = 6 if ($date =~ /^Sat/);
+ $wday = 7 if ($date =~ /^Sun/);
+
+ my $dt = DateTime->now();
+ while ($dt->wday() != $wday) {
+ $dt->add(days => 1);
+ }
+
+ $date = $dt->ymd();
+ }
+ return unless $date =~ "^[0-9]{4}-[0-9]{2}-[0-9]{2}\$";
+
+ return -1 unless $state =~ "^frozen|ready|sourced|idea\$";
+ if (1) { #FIXME Verify that entry exists ?
+ my $sql = "UPDATE plan SET state=".$db->quote($state)." WHERE date='$date';";
+ $db->do($sql);
+ }
+
+ return 0;
+}
+
sub cmd_randmeal {
my ( $date ) = @_;
my $recipe_id = get_random_recipe();
@@ -154,6 +186,15 @@ sub cmd_postpone {
}
}
+sub get_plan_state {
+ my ( $date ) = @_;
+
+ my $sql = "SELECT state FROM plan WHERE date=".$db->quote($date).";";
+ my ( $state ) = $db->selectrow_array($sql);
+ $state = 'u' unless $state;
+ return $state;
+}
+
sub cmd_showplan {
my ( $date ) = @_;
my $mealtype = "lunch";
@@ -171,7 +212,8 @@ sub cmd_showplan {
"' and mealtype='$mealtype';";
my @ids = $db->selectrow_array($sql);
if ($ids[0]) {
- printf "%9s %3s %s, %s\n", $dt->ymd(), $ids[0], get_recipe_name($ids[0]),
+ printf "%9s %3s [%s] %s, %s\n", $dt->ymd(), $ids[0],
+ substr(get_plan_state($dt->ymd()), 0, 1), get_recipe_name($ids[0]),
get_recipe_uri($ids[0]);
}
$dt->add(days => 1);
@@ -327,6 +369,9 @@ if ($ARGV[0]) {
if ( $ARGV[0] eq "setmeal") {
print "Command failed!\n" unless (cmd_setmeal($ARGV[1], $ARGV[2]) >= 0);
}
+ if ( $ARGV[0] eq "setstate") {
+ print "Command failed!\n" unless (cmd_setstate($ARGV[1], $ARGV[2]) >= 0);
+ }
if ( $ARGV[0] eq "randmeal") {
print "Command failed!\n" unless (cmd_randmeal($ARGV[1]) >= 0);
}