summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcos <cos>2012-08-12 15:38:52 +0200
committercos <cos>2012-12-17 21:12:07 +0100
commit5ea0c3dfdaa1417ec70e3621fa16f8b85b1cb583 (patch)
tree7274e1402361045422bc42d7e3e9bb104a4bbc5c
parente3c174987cfa92be1ee7054cefbea33d8d156637 (diff)
downloadmat-5ea0c3dfdaa1417ec70e3621fa16f8b85b1cb583.zip
Initial support for showing comments in mealplan.
-rwxr-xr-xmat41
1 files changed, 31 insertions, 10 deletions
diff --git a/mat b/mat
index 20f065d..f73b35a 100755
--- a/mat
+++ b/mat
@@ -15,6 +15,7 @@ my $db = DBI->connect("dbi:SQLite:recipe.db", "", "", {RaiseError => 1,
my @recipes;
my @ingredients;
my @contents;
+my @comments;
sub ceiling {
my ( $num ) = @_;
@@ -44,6 +45,12 @@ sub read_recipe_db {
$recipes[$id]->{'uri'} = @$row[2];
}
+ $all = $db->selectall_arrayref("SELECT * FROM comments");
+ foreach my $row (@$all) {
+ my ($id) = @$row;
+ $comments[$id]->{'comment'} = @$row[1];
+ }
+
read_ingredients;
$all = $db->selectall_arrayref("SELECT * FROM contents");
foreach my $row (@$all) {
@@ -79,6 +86,16 @@ sub get_recipe_uri ($) {
}
}
+sub get_comment ($) {
+ my ( $id ) = @_;
+
+ if ($comments[$id]->{'comment'}) {
+ return $comments[$id]->{'comment'};
+ } else {
+ return "NULL";
+ }
+}
+
my @schedule = (
{
day => "MÃ¥ndag",
@@ -235,15 +252,19 @@ sub cmd_showplan {
}
for (my $i = 0; $i < 28; $i++) {
- my $sql = "SELECT recipe_id, mealtype FROM plan WHERE date='".$dt->ymd().
- "';";
+ my $sql = "SELECT recipe_id, mealtype, comment_id FROM plan WHERE date='".
+ $dt->ymd()."';";
my @ids = $db->selectrow_array($sql);
print $weekend_padding;
- if ($ids[0]) {
- printf "%9s %-10s %3s|%s %s, %s\n", $dt->ymd(), $ids[1], $ids[0],
- substr(get_plan_state($dt->ymd()), 0, 1), get_recipe_name($ids[0]),
- get_recipe_uri($ids[0]);
+ 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();
}
@@ -450,10 +471,10 @@ sub cmd_shoppinglist {
# print $i, "\n";
# }
- my $entries = $db->selectall_arrayref("SELECT recipe_id FROM plan WHERE date ".
- "BETWEEN '".$startdate."' and '".$enddate."' and ".
- "IFNULL(state, 'null') != 'frozen' and ".
- "IFNULL(state, 'null') != 'ready' and ".
+ my $entries = $db->selectall_arrayref("SELECT recipe_id FROM plan WHERE recipe_id AND date ".
+ "BETWEEN '".$startdate."' AND '".$enddate."' AND ".
+ "IFNULL(state, 'null') != 'frozen' AND ".
+ "IFNULL(state, 'null') != 'ready' AND ".
"IFNULL(state, 'null') != 'sourced'", { Slice => {} });
my %recipe_count;
for my $entry ( @$entries ) {