function loadIngredients($id) { $result_fields = array("ingredient_id", "quantity"); $table = "RecipeIngredient"; $eid = new stdClass(); $eid->column = "recipe_id"; $eid->compare = "="; $eid->logical = ""; $eid->value = $id; $query_params = array($eid); $con1 = new SQLconnection(); $obj = $con1->pdo_query_wparam($result_fields, $table, $query_params); if (!empty($obj)) { foreach ($obj->results as $ing) { $ingredient = new Ingredient($ing->ingredient_id); $ingredient->setQuantity($ing->quantity); array_push($this->ingredients, $ingredient); } } else { array_push($this->ingredients, "No Ingredients available"); } }
function loadRecipeList($var, $page = 0) { //clear current list unset($this->recipes); //reinitialize list $this->recipes = array(); $result_fields = $var->result_fields; $table = $var->table; $query_params = array($var); $con1 = new SQLconnection(); $obj = $con1->pdo_query_wparam($result_fields, $table, $query_params, $var->limit); //if there are results if (!empty($obj)) { $this->recipe_count = $obj->resultCount; foreach ($obj->results as $rec) { //add raw recipes into list $recipe = new Recipe($rec->id); array_push($this->recipes, $recipe); } //remove duplicates from the list $temp_uids = array(); $unique_results = array(); foreach ($this->recipes as $recipe) { if (!in_array($recipe->id(), $temp_uids)) { $temp_uids[] = $recipe->id(); $unique_results[] = $recipe; } } $temp = array(); foreach ($unique_results as $recipe) { $temp[] = $recipe->jsonSerialize(); } $this->recipes = $temp; unset($temp_uids, $unique_results); //prepare the recipes for cooking (jsonSerialize) } }
function unstarRecipe($usr, $recipe_id) { $con1 = new SQLconnection(); $user = new User($usr); $recipe = new Recipe($recipe_id); if ($recipe->exists()) { //$table="Starred"; //$conditions=array(); //$user_id=new stdClass(); //$user_id->column="user_id"; //$user_id->value=$user->id(); //$user_id->compare="="; //$user_id->logical="and"; //$recipe_id1=new stdClass(); //$recipe_id1->column="recipe_id"; //$recipe_id1->value=$recipe->id(); //$recipe_id1->compare="="; //$recipe_id1->logical=""; //$conditions=array($user_id,$recipe_id1); try { if (!($usr = (int) $usr)) { return; } if (!($recipe_id = (int) $recipe_id)) { return; } $con1->pdo_query(" delete from Starred where user_id = {$usr} and recipe_id={$recipe_id};"); //$con1->pdo_delete($table,$conditions); } catch (PDOException $Exception) { print_r($Exception); $res = $Exception; return $res; } } unset($this->recipes); $this->recipes = array(); $this->loadRecipes($user->id()); }
<?php session_start(); include_once 'classes/dbconnect.php'; include_once 'classes/user.php'; if (!empty($_POST['user1']) && !empty($_POST['pass1'])) { $result_fields = array("id"); $name = $_POST['user1']; $pass = $_POST['pass1']; $con = new SQLconnection(); $name = new stdClass(); $name->column = "name"; $name->compare = "="; $name->logical = "and"; $name->value = $name; $pass = new stdClass(); $pass->column = "pass"; $pass->compare = "="; $pass->logical = ""; $pass->value = $pass; $query_params = array($name, $pass); $obj = $con->pdo_query_wparam($result_fields, $table, $query_params); if (!empty($obj->results[0])) { $user = new User($obj->results[0]->id); session_regenerate_id(); } } else { $user = new User(0); }