function loadRecipes($userId) { $result_fields = array("recipe_id"); $table = "Starred"; $eid = new stdClass(); $eid->column = "user_id"; $eid->compare = "="; $eid->logical = ""; $eid->value = $userId; $query_params = array($eid); $con1 = new SQLconnection(); $obj = $con1->pdo_query_wparam($result_fields, $table, $query_params); if (!empty($obj)) { foreach ($obj->results as $key => $rec) { $recipe = new Recipe($rec->recipe_id); array_push($this->recipes, $recipe); } } else { array_push($this->recipes, new Recipe(0)); } }
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) } }
<?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); }