summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 ) {