コード例 #1
0
 static function findAllForRecipe($recipe_id, $dbh)
 {
     $sql = "SELECT riu.*, i.name as iname, u.name as uname FROM recipe_ingredients_units riu, ingredients i,\r\n     \tunits_of_measure u WHERE riu.ingredient_id = i.id AND riu.unit_id = u.id AND recipe_id = :recipe_id;";
     $stmt = $dbh->prepare($sql);
     $stmt->bindParam(":recipe_id", $recipe_id);
     $stmt->execute();
     $result = array();
     while ($row = $stmt->fetch()) {
         $iu = new RecipeIngredientUnit();
         $iu->copyFromRow($row);
         $result[] = $iu;
     }
     return $result;
 }
コード例 #2
0
 function getRecipeIngUnit($dbh)
 {
     $this->riu = RecipeIngredientUnit::findAllForRecipe($this->id, $dbh);
 }
コード例 #3
0
ファイル: ShowRecipe.php プロジェクト: xavidram/RecipeListPHP
<?php

require_once "models/DB.php";
require_once "models/Recipe.php";
require_once "models/Ingredient.php";
require_once "models/units_of_measure.php";
require_once "models/RecipeIngredientUnit.php";
require_once "models/IngredientLayout.php";
require_once "models/Step.php";
// Route 1: user comes here to see a specific recipe
//   get the id of the recipe they want from the query string,
//   inflate a recipe model, and show them the detail view
//make new recipy and find it based on the ID of the selected anchor
$details = new Recipe();
$details->find($viewID, $dbh);
$steps = Step::findAllSteps($dbh, $details->id);
$riu = RecipeIngredientUnit::findAllForRecipe($details->id, $dbh);
$ingredients = array();
foreach ($riu as $i) {
    //$p = new IngredientLayout();
    //$p->amount = $i->amount;
    //$p->ingredient = Ingredient::findName($i->ingredient_id,$dbh);
    //$p->unit= units_of_measure::findName($i->unit_id,$dbh);
    //$ingredients[] = $p;
}
print_r($ingredients);
require_once "views/view_recipe.php";
コード例 #4
0
ファイル: saveRecipe.php プロジェクト: xavidram/RecipeListPHP
$recipe->description = $_POST['description'];
$recipe->img_url = $_POST['img_url'];
$recipe->prep_time = $_POST['prep_time'];
$recipe->total_time = $_POST['total_time'];
$recipe->save($dbh);
$recipeID = Recipe::getLastInsertId($dbh);
$stepsInsert = $_POST['step'];
$stepcounter = 1;
foreach ($stepsInsert as $text) {
    $S = new Step();
    $S->recipe_id = $recipeID;
    $S->stepno = $stepcounter;
    $S->text = $text;
    $stepcounter += 1;
    $S->insertStep($dbh);
}
$amount = $_POST['amount'];
$unitid = $_POST['unitid'];
$ingredientid = $_POST['ingredientid'];
$length = count($ingredientid);
for ($i = 0; $i < $length; $i++) {
    if ($amount[$i] != 0) {
        $I = new RecipeIngredientUnit();
        $I->recipe_id = $recipeID;
        $I->ingredient_id = $ingredientid[$i];
        $I->unit_id = $unitid[$i];
        $I->amount = $amount[$i];
        $I->insert($dbh);
    }
}
require_once "../views/view_recipes.php";