コード例 #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
ファイル: user.php プロジェクト: leanne-abarro/getInMyBelly
 public function load($iUserID)
 {
     $connection = new Connection();
     $sSQL = "SELECT UserID, FirstName, LastName, Username, Address, Email, Telephone, Password, Admin\n                     FROM tbuser\n                     WHERE UserID=" . $iUserID;
     $resultSet = $connection->query($sSQL);
     $row = $connection->fetch_array($resultSet);
     //store data into attributes:
     $this->iUserID = $row['UserID'];
     $this->sFirstName = $row['FirstName'];
     $this->sLastName = $row['LastName'];
     $this->sUsername = $row['Username'];
     $this->sAddress = $row['Address'];
     $this->sEmail = $row['Email'];
     $this->iTelephone = $row['Telephone'];
     $this->sPassword = $row['Password'];
     $this->iAdmin = $row['Admin'];
     // get all recipe ids of each user:
     $sSQL = "SELECT RecipeID\n                     FROM tbrecipe\n                     WHERE UserID=" . $iUserID;
     $resultSet = $connection->query($sSQL);
     while ($row = $connection->fetch_array($resultSet)) {
         $iRecipeID = $row["RecipeID"];
         $oRecipe = new Recipe();
         $oRecipe->load($iRecipeID);
         $this->aRecipes[] = $oRecipe;
     }
     $connection->close_connection();
 }
コード例 #3
0
 function testIfObjectRetunsListOfRecipes()
 {
     $recipe = new Recipe(1);
     $user = new User(1);
     $starredRecipe = new StarredRecipe($user->id(), $recipe->id());
     $this->assertTrue(!empty($starredRecipe->recipes()));
 }
コード例 #4
0
 public function starRating($recipeId, $id = null, $value = null)
 {
     $session = Zend_Registry::get('session');
     $log = Zend_Registry::get('log');
     // fetch the rating
     $ra = new Rating();
     $rating = $ra->getRating($recipeId);
     // If were passing through a value we already know what to display and are probably read only
     if (isset($value)) {
         return $this->displayRating($value, $id);
     }
     // Logged in?
     if (!$session->user) {
         return $this->displayRating($rating);
     }
     //$log->debug( $session->user['name'] . ' is logged in' );
     $r = new Recipe();
     if ($r->isOwner($recipeId)) {
         return $this->displayRating($rating);
     }
     //$log->debug( $session->user['name'] . ' is not the owner' );
     // Has this user already rated?
     $db = Zend_Registry::get('db');
     $select = $db->select()->from('ratings', array("numberOfRatings" => "COUNT(*)"))->where("recipe_id = ?", $recipeId)->where("user_id = ?", $session->user['id']);
     //$log->debug( $select->__toString() );
     //$log->debug( $db->fetchOne( $select ) );
     // If we get a result show the user the overall rating
     if ($db->fetchOne($select) > 0) {
         return $this->displayRating($rating);
     }
     //$log->debug( $session->user['name'] . ' has not already rated this' );
     // Otherwise show the rating but make it clickable
     return $this->displayRating($rating, null, false);
 }
コード例 #5
0
ファイル: RecipeTest.php プロジェクト: y2khjh/test1
 public function testRecipeWhenValid()
 {
     $name = 'bread with butter';
     $ingredients = array(new Ingredient('bread', 1, 'slices', new DateTime('+30 day')), new Ingredient('butter', 1, 'slices', new DateTime('+15 day')));
     $recipe = new Recipe($name, $ingredients);
     $this->assertEquals($recipe->getName(), $name);
     $this->assertEquals($recipe->getIngredients(), $ingredients);
     $this->assertEquals($recipe->getEarliestUsedBy(), new DateTime('+15 day'));
 }
コード例 #6
0
ファイル: Step.php プロジェクト: xavidram/RecipeListPHP
 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;
 }
コード例 #7
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;
 }
コード例 #8
0
function SemanticRecipeGraphFunction_Render($parser, $param1 = '')
{
    $mProject = new Recipe($param1);
    $dotStr = $mProject->retrieveAndGetCode();
    doDot($param1, $dotStr);
    $ret = htmlForImage($param1, 'recipe');
    if ($ret == null) {
    }
    return array($ret, 'isHTML' => true);
    //testing:
    //return "<pre>$hgtext</pre>";
}
コード例 #9
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;
 }
コード例 #10
0
 function startElement($parser, $tagName, $attrs)
 {
     $this->tag = $tagName;
     switch ($tagName) {
         case "RECIPE":
             $recipe = new Recipe();
             $recipe->parse($parser, $this);
             $this->recipes[] = $recipe;
             break;
         default:
             break;
     }
 }
コード例 #11
0
 public static function getAllRecipes()
 {
     $aAllRecipes = array();
     $connection = new Connection();
     $sSQL = "SELECT RecipeID\n                     FROM tbrecipe\n                     ORDER BY CreatedAt DESC\n                     ";
     $resultSet = $connection->query($sSQL);
     while ($row = $connection->fetch_array($resultSet)) {
         $iRecipeID = $row['RecipeID'];
         $oRecipe = new Recipe();
         $oRecipe->load($iRecipeID);
         $aAllRecipes[] = $oRecipe;
     }
     $connection->close_connection();
     return $aAllRecipes;
 }
コード例 #12
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function getEdit($id)
 {
     // get the recipe
     $recipe = Recipe::find($id);
     // show the edit form and pass the recipe
     return View::make('recipe.edit')->with('recipe', $recipe);
 }
コード例 #13
0
 public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 10) as $index) {
         Recipe::create([]);
     }
 }
コード例 #14
0
 /**
  * getById function. Get Recipe Object by id in array. In fact it is only to use a more modern and convenient way to access data. For the sake of coherence !
  *
  * @access public
  * @static
  * @param int id - $id
  * @return Recipe Object
  */
 public static function getById($id)
 {
     if (Recipe::getDataAt($id)) {
         return new Recipe($id);
     }
     return null;
 }
コード例 #15
0
 public static function sandbox()
 {
     $first = Recipe::find(1);
     $recipes = Recipe::all();
     Kint::dump($recipes);
     Kint::dump($first);
 }
コード例 #16
0
ファイル: recipes.php プロジェクト: rubygeek/rubygeek
  function show_recipe() {

    $id = $this->uri->segment(3, NULL);
    $recipe = new Recipe();
    $data['page_title'] = "- View a Recipe";
    $data['recipe'] = $recipe->get_by_id($id);
    $data['tags'] = $recipe->tag->all;
    // Header
    $this->load->view("header", $data);

    // Body of page
		$this->load->view('recipes/show_recipe');

    // Footer
    $this->load->view('footer');

  }
コード例 #17
0
 public static function sandbox()
 {
     // Testaa koodiasi täällä
     // View::make('helloworld.html');
     $indi = Recipe::find(1);
     $indis = Recipe::all();
     Kint::dump($indi);
     Kint::dump($indis);
 }
コード例 #18
0
 /**
 	Loads all of the recipes we are going to export into the $exportRecipes
 	array.
 	@param $id The recipe id to be exported, if set to 0 then export all recipes
 */
 function getData($id)
 {
     global $DB_LINK, $db_table_recipes;
     if ($id == 0) {
         $this->exportAll = true;
         // recursively call for all the recipes in the database
         $sql = "SELECT recipe_id FROM {$db_table_recipes}";
         $rc = $DB_LINK->Execute($sql);
         DBUtils::checkResult($rc, NULL, NULL, $sql);
         while (!$rc->EOF) {
             $this->getData($rc->fields['recipe_id']);
             $rc->MoveNext();
         }
     } else {
         $recipeObj = new Recipe($id);
         $recipeObj->loadRecipe();
         $this->exportRecipes[] = $recipeObj;
     }
 }
コード例 #19
0
 public function megaCookieWithCalories($teaspoons, $calories)
 {
     $megaCookie = null;
     $ingredientNames = $this->larder->ingredients();
     foreach ($this->combinations->generate($teaspoons) as $combination) {
         $quantities = [];
         foreach ($combination as $k => $amount) {
             $ingredient = $ingredientNames[$k];
             $quantities[$ingredient] = $amount;
         }
         $recipe = new Recipe($this->larder, $teaspoons, $quantities);
         if ($recipe->totalScoreForProperty("calories") != $calories) {
             continue;
         }
         if (!$megaCookie || $recipe->totalScoreForRecipe() > $megaCookie->totalScoreForRecipe()) {
             $megaCookie = $recipe;
         }
     }
     return $megaCookie;
 }
コード例 #20
0
 public function load($iRecipeTypeID)
 {
     $connection = new Connection();
     $sSQL = "SELECT RecipeTypeID, TypeName, Description, DisplayOrder\n                     FROM tbrecipetype\n                     WHERE RecipeTypeID=" . $iRecipeTypeID;
     $resultSet = $connection->query($sSQL);
     $row = $connection->fetch_array($resultSet);
     //store into data attribues:
     $this->iRecipeTypeID = $row["RecipeTypeID"];
     $this->sTypeName = $row["TypeName"];
     $this->sDescription = $row["Description"];
     $this->iDisplayOrder = $row["DisplayOrder"];
     // get all recipe IDs of type:
     $sSQL = "SELECT RecipeID\n                     FROM tbrecipe\n                     WHERE RecipeTypeID=" . $iRecipeTypeID . "\n                     ORDER BY CreatedAt DESC";
     $resultSet = $connection->query($sSQL);
     while ($row = $connection->fetch_array($resultSet)) {
         $iRecipeID = $row['RecipeID'];
         $oRecipe = new Recipe();
         $oRecipe->load($iRecipeID);
         $this->aRecipes[] = $oRecipe;
     }
     $connection->close_connection();
 }
コード例 #21
0
ファイル: Component.php プロジェクト: armourjami/armourtake
 public static function addComponent($dishId, $recipeId, $quantity, $unitName)
 {
     if (Unit::exists($newUnit) && Recipe::exists($recipeId)) {
         $db = self::getInstance();
         if ($db->insert('DishRecipes', ['Dishes_id' => $dishId, 'Recipes_id' => $recipeId, 'quantity' => $quantity, 'unit' => $unitName])) {
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
コード例 #22
0
 public function view($recipeCategorySlug, $recipeSlug)
 {
     $recipe = Recipe::with(array('recipeCategory' => function ($query) use($recipeCategorySlug) {
         $query->where('slug', '=', $recipeCategorySlug);
     }, 'otherRecipe1', 'otherRecipe2', 'products' => function ($query) {
         $query->take(1);
     }))->where('slug', '=', $recipeSlug)->live()->first();
     if (!$recipe) {
         \App::abort(404);
     }
     $product = current(current($recipe->products));
     return \View::make(\Config::get('laravel-food::views.recipes.view'))->with(compact('recipe', 'product'));
 }
コード例 #23
0
ファイル: RecipeController.php プロジェクト: nchamp/mvc
	/**
	* Function for recipe search (From POST parameteres)
	*
	* If POST parameters are sent, then perform search
	* If no POST parameters exist in the HTTP request, display the search controls/form
	*
	* @param: None
	* @return: None
	*/
	public function search(){
		//Test if the POST parameters exist. If they don't present the user with the
		//search controls/form
		if(!isset($_POST["search"])){
			$this->template->display('search.html.php');			
		}
		
		//Get the recipe from the database
		$recipes = Recipe::search($_POST["search"]);
		//If successful and the count is equal to one (as desired)
		//set the recipe object in the template to be displayed
		$this->template->recipes = $recipes;
	
		$this->template->display('results.html.php');
	}
コード例 #24
0
 public static function show($id)
 {
     $chef = Chef::find($id);
     if ($chef) {
         $recipes = Recipe::find_by_chef_id($chef->id);
         $comments = Comment::find_by_chef_id($chef->id);
         $recipes_for_comments = array();
         foreach ($comments as $comment) {
             $recipes_for_comments[$comment->recipe_id] = Recipe::find($comment->recipe_id);
         }
         View::make('chef/show.html', array('chef' => $chef, 'recipes' => $recipes, 'comments' => $comments, 'recipes_for_comments' => $recipes_for_comments));
     } else {
         Redirect::to('/', array('error' => 'Käyttäjää ei löytynyt'));
     }
 }
コード例 #25
0
ファイル: Recipe.php プロジェクト: nchamp/mvc
   /**
    * A method for validating the data
	* 
	* @param $data An array of POSTed data.
	* @return bool Whether the data is valid or not.
	*/
   public static function validates(array &$data) {
      $errors = array();

	  if (!isset($data['Ingredients']) || empty($data['Ingredients'])) {
        $errors['Ingredients'] = 'You must provide the ingredients';
	    unset($data['Ingredients']);
      } 

      if (!preg_match("/^[0-9]+$/i", $data['ServingSize'])) {
	     $error['ServingSize'] = 'You serving size must only be numbers.';
	  }
	  if (!isset($data['ServingSize']) || empty($data['ServingSize'])) {
         $errors['ServingSize'] = 'You must provide the serving size.';
		 unset($data['ServingSize']);
	  }
	  
	  if (!preg_match("/^[0-9]+$/i", $data['CookTime'])) {
	     $error['ServingSize'] = 'You cook time must only be numbers.';
	  }
	  if (!isset($data['CookTime']) || empty($data['CookTime'])) {
         $errors['CookTime'] = 'You must provide the cook time.';
		 unset($data['CookTime']);
	  }
	  
	  if (!isset($data['Difficulty']) || empty($data['Difficulty'])) {
        $errors['Difficulty'] = 'You must provide the difficulty.';
		unset($data['Difficulty']);
	  }
	  
	  if (!isset($data['CuisineID']) || empty($data['CuisineID'])) {
        $errors['CuisineID'] = 'You must provide the cuisine id.';
		unset($data['CuisineID']);
	  }

	  if (!preg_match("/^[0-9]+$/i", $data['Rating'])) {
	     $error['Rating'] = 'You rating must only be numbers.';
	  }
	  if (!isset($data['Rating']) || empty($data['Rating'])) {
         $errors['Rating'] = 'You must provide the rating.';
		 unset($data['Rating']);
	  }
	  
	  self::$errors = $errors;
	  if (count($errors)) {
         return false;
	  }
	  return true;
   }
コード例 #26
0
ファイル: Search.class.php プロジェクト: vincenthib/cooking
 private function getResults($separator)
 {
     $where = array();
     $bindings = array();
     foreach ($this->filters as $key => $value) {
         $operator = strpos($value, '%') !== false ? 'LIKE' : '=';
         $where[] = $key . ' ' . $operator . ' :' . $key;
         $bindings[$key] = $value;
     }
     if (!empty($where)) {
         $sql = 'SELECT * FROM recipe WHERE 1 AND (' . implode(' ' . $separator . ' ', $where) . ')';
         $this->results = Recipe::select($sql, $bindings);
         $this->count = count($this->results);
     }
     return $this;
 }
コード例 #27
0
ファイル: chef.php プロジェクト: emivo/Tsoha-Bootstrap
 public function destroy()
 {
     // Poista käyttäjän reseptit
     $chefs_recipes = Recipe::find_by_chef_id($this->id);
     foreach ($chefs_recipes as $recipe) {
         /* @var $recipe Recipe */
         $recipe->destroy();
     }
     // Poista käyttäjän kommentit
     $chefs_comments = Comment::find_by_chef_id($this->id);
     foreach ($chefs_comments as $comment) {
         /* @var $comment Comment */
         $comment->delete();
     }
     $query = DB::connection()->prepare("DELETE FROM Chef WHERE id = :id");
     $query->execute(array('id' => $this->id));
 }
コード例 #28
0
 /**
  * Display a listing of the resource.
  * GET /recipes
  *
  * @return Response
  */
 public function index()
 {
     // WORKING
     //$var = Recipe::find(1)->authors()->lists('name');
     //$var = Recipe::find(1)->photos()->lists('name');
     //$var = Recipe::find(1)->categories()->lists('name');
     //$var = Country::find(1)->recipes()->lists('title');
     //
     // ----  Pour les phrases de catégories -----
     // $var = Recipe::find(1)->categoriespreparation()->lists('name','id');
     // //$var = CategoriesPreparation::find(1)->sentencesprepatation()->lists('id');
     // $varkeys = array_keys($var);
     // $var2 = CategoriesPreparation::find($varkeys[1])->sentencespreparation()->lists('name');
     // BROKEN
     $var = Recipe::find(1)->countries();
     return Response::json($var);
 }
コード例 #29
0
ファイル: Menu.php プロジェクト: rocketpastsix/OOPExample
 /**
  * @param Recipe $recipe
  */
 public function addRecipe(Recipe $recipe)
 {
     $this->recipes[$recipe->getName()] = $recipe;
 }
コード例 #30
0
ファイル: search.php プロジェクト: vincenthib/cooking
<?php

require_once 'config/config.conf.php';
try {
    $search = Recipe::Search($_GET);
    $vars = array('search' => $search);
    Model::displayTemplate('search.tpl', $vars);
} catch (Exception $e) {
    echo $e->getMessage();
}