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; }
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(); }
function testIfObjectRetunsListOfRecipes() { $recipe = new Recipe(1); $user = new User(1); $starredRecipe = new StarredRecipe($user->id(), $recipe->id()); $this->assertTrue(!empty($starredRecipe->recipes())); }
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); }
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')); }
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; }
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; }
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>"; }
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; }
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; } }
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; }
/** * 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); }
public function run() { $faker = Faker::create(); foreach (range(1, 10) as $index) { Recipe::create([]); } }
/** * 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; }
public static function sandbox() { $first = Recipe::find(1); $recipes = Recipe::all(); Kint::dump($recipes); Kint::dump($first); }
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'); }
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); }
/** 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; } }
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; }
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(); }
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; } }
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')); }
/** * 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'); }
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')); } }
/** * 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; }
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; }
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)); }
/** * 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); }
/** * @param Recipe $recipe */ public function addRecipe(Recipe $recipe) { $this->recipes[$recipe->getName()] = $recipe; }
<?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(); }