From ed279cb3cf7b9a003f3411413f24bd7d054676bb Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 21 Sep 2016 00:17:20 +0100 Subject: [PATCH] Begin work on retrieval of recipe data --- modules/ORB/System/Recipe.pm | 47 ++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/modules/ORB/System/Recipe.pm b/modules/ORB/System/Recipe.pm index 5d7d60f..d67ed0b 100644 --- a/modules/ORB/System/Recipe.pm +++ b/modules/ORB/System/Recipe.pm @@ -231,6 +231,23 @@ sub set_status { } +# ============================================================================ +# Recipe retrieval + +sub get_recipe { + my $self = shift; + my $recipeid = shift; + + + + + +sub find { + +} + + + # ============================================================================== # Private methods @@ -299,8 +316,8 @@ sub _add_recipe_ingredients { # Add the specified tags to a recipe. # # @param recipeid The id of the recipe to add the tags to. -# @param tags A string containing a comma-delimited list of tags, or a reference to an -# array of tag names. +# @param tags A string containing a comma-delimited list of tags, or a +# reference to an array of tag names. # @return true on success, undef on error sub _add_recipe_tags { my $self = shift; @@ -348,6 +365,32 @@ sub _add_recipe_tags { } +## @method private $ _get_recipe_ingredients($recipeid) +# Fetch the ingredients for the specified recipe, along with any separators +# in the ingredient list +# +# @param recipeid The ID of the recipe to fetch the ingredients for. +# @return An arrayref of ingredient hashes on success, undef on error. +sub _get_recipe_ingredients { + my $self = shift; + my $recipeid = shift; + + $self -> clear_error(); + + my $ingh = $self -> {"dbh"} -> prepare("SELECT `ri`.*, `i`.`name` + FROM `".$self -> {"settings"} -> {"database"} -> {"recipeing"}."` AS `ri` + `".$self -> {"settings"} -> {"database"} -> {"recipeing"}."` AS `i` + WHERE `i`.`id` = `ri`.`ingred_id` + AND `ri`.`recipe_id` = ? + ORDER BY `ri`.`position`"); + $ingh -> execute($recipeid) + or return $self -> self_error("Ingredient lookup for '$recipeid' failed: ".$self -> {"dbh"} -> errstr()); + + return $ingh -> fetchall_arrayref({}); +} + + + ## @method private $ _renumber_recipe($sourceid) # Given a recipe ID, move the recipe to a new ID at the end of the recipe # table. This will move the recipe and all relations involving it, to