43 lines
1.0 KiB
PHP
43 lines
1.0 KiB
PHP
<?php
|
|
|
|
class Recipes {
|
|
// function __construct($recipeID = 0){
|
|
|
|
static function getAll(): array{
|
|
global $user_id, $db;
|
|
$return = array();
|
|
|
|
$sql = "SELECT * FROM recipe WHERE public = 1 OR author = $user_id;";
|
|
$res = $db->query($sql);
|
|
while($row = $res->fetch_assoc()){
|
|
$return[$row['recipe_id']] = $row;
|
|
|
|
|
|
// $return[$row['recipe_id']]['items'] = ;
|
|
}
|
|
|
|
if(empty($return)){
|
|
$return[] = "No recipes found";
|
|
}
|
|
|
|
return $return;
|
|
}
|
|
|
|
static function createRecipe($name, $portions = 1, $public = 0) {
|
|
global $user_id, $db;
|
|
|
|
if($portions == null){
|
|
$portions = 1;
|
|
}
|
|
|
|
if(strlen($name) <= 200 && is_numeric($public)){
|
|
$createRecipeSQL = "INSERT INTO `recipe` (name, author, portions, public) VALUES ('$name', $user_id, $portions, $public);";
|
|
if($db->query($createRecipeSQL)){
|
|
return $db->insert_id;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|