Пример #1
0
 static function findByKeyword($dbh, $keyWord)
 {
     $keyWords = explode(" ", $keyWord);
     // Split the string.
     $strStmt = "select * from " . Recipe::$tableName . " where ";
     for ($i = 0; $i < sizeof($keyWords); $i++) {
         // Add the number of keyWords the user want to search.
         if ($i > 0) {
             $strStmt .= "AND ";
         }
         $strStmt .= "(Name LIKE :keyWord_" . $i . " OR Description LIKE :keyWord_" . $i . ")";
         $keyWords[$i] = "%" . $keyWords[$i] . "%";
     }
     $stmt = $dbh->prepare($strStmt);
     for ($i = 0; $i < sizeof($keyWords); $i++) {
         $stmt->bindParam(":keyWord_" . $i, $keyWords[$i]);
     }
     $stmt->execute();
     $result = array();
     while ($row = $stmt->fetch()) {
         $r = new Recipe();
         $r->copyFromRow($row);
         $result[] = $r;
     }
     return $result;
 }
Пример #2
0
 function findByName($dbh, $keyword)
 {
     $stmt = $dbh->prepare("select * from " . Recipe::$tableName . " WHERE name LIKE  '%" . $keyword . "%'");
     $stmt->execute();
     $row = $stmt->fetch();
     $p = new Recipe();
     $p->copyFromRow($row);
     return $p;
 }
Пример #3
0
 static function findByKeyword($dbh, $searchOne)
 {
     $stmt = $dbh->prepare("SELECT * FROM " . Recipe::$nameTable . " WHERE Name LIKE '%" . $searchOne . "%' AND Description LIKE '%" . $searchOne . "%'");
     $stmt->execute();
     $newResult = array();
     while ($row = $stmt->fetch()) {
         $r = new Recipe();
         $r->copyFromRow($row);
         $newResult[] = $r;
     }
     return $newResult;
 }
Пример #4
0
 static function findAll($dbh)
 {
     $stmt = $dbh->prepare("select * from " . Recipe::$nameTable);
     $stmt->execute();
     $result = array();
     while ($row = $stmt->fetch()) {
         $r = new Recipe();
         $r->copyFromRow($row);
         $result[] = $r;
     }
     return $result;
 }
Пример #5
0
<?php

require_once "models/db.php";
require_once "models/Recipe.php";
$recipe = new Recipe();
if ($_POST) {
    $recipe->copyFromRow($_POST);
    if ($recipe->validate()) {
        $recipe->save($dbh);
        echo "save successfully";
        die;
    }
}
// default route, show page for adding
require_once "views/view_recipe.php";
$newRecipe->Name = "Soup";
$newRecipe->ID = 1000;
$newRecipe->Description = "It's Hot";
$newRecipe->Image = "haha no";
$newRecipe->Prep = "10:25";
$newRecipe->Total = "20:00";
$newRecipe->Rating = 5;
print $newRecipe;
?>
<br>
<br>
<?php 
// copyFromRow testing
$thisArray = ['ID' => 1001, 'Name' => "Bread", 'Description' => "It's Soft", 'Image' => "haha no", 'Prep' => "00:25", 'Total' => "05:00", 'Rating' => 4];
$recipe2 = new Recipe();
$recipe2->copyFromRow($thisArray);
print $recipe2;
?>
<br>
<br>
<?php 
// find testing
require_once "models/DB.php";
$recipe3 = new Recipe();
//$recipe3->ID = 1;
$recipe3->find(1, $dbh);
print $recipe3;
?>
<br>
<br>
<?php 
Пример #7
0
 function findByKeyword($dbh, $keyword)
 {
     $stmt = $dbh->prepare("select * from " . Recipe::$tableName . " WHERE name LIKE  '%" . $keyword . "%' OR description LIKE '%" . $keyword . "%'");
     $stmt->execute();
     $result = array();
     while ($row = $stmt->fetch()) {
         $p = new Recipe();
         $p->copyFromRow($row);
         $result[] = $p;
     }
     return $result;
 }
Пример #8
0
$u = Unit::findAll($dbh);
$ing = Ingredient::findAll($dbh);
// Route 1: user comes here to add a new recipe, show them a blank form
$add = true;
// Route 2: user comes here to edit a specific recipe
//   (you'll need to grab that id from the query string)
if (isset($_GET['id'])) {
    $add = false;
    $recipes->find($_GET['id'], $dbh);
}
// Route 3a: user entered a new recipe details and is trying to save it
//   create an object, set values, validate and save, just like in the lab
//   if all is well, send to ShowRecipe to see the added recipe
//   otherwise, back to the edit view with errors!
if ($_POST && !$_GET) {
    $recipes->copyFromRow($_POST);
    if ($recipes->validate()) {
        $recipes->save($dbh);
        header('Location: RecipeList.php?id=' . $recipes->id);
    }
}
// Route 3b: user updated an existing recipe details and is trying to save it
//   create an object, inflate to the proper id, update values, validate and save
//   if all is well, send to ShowRecipe to see the added recipe
//   otherwise, back to the edit view with errors!
if ($_POST && $_GET) {
    $recipes->copyFromRow($_POST);
    if ($recipes->validate()) {
        $recipes->save($dbh);
        header('Location: RecipeList.php?id=' . $recipes->id);
    }