<?php
class ResMenu
{
    public $id;
    public $name;
    public $price;
    public $category_id;
    public $photo;
    public function __construct($_id, $_name, $_price, $_category_id, $_photo)
    {
        $this->id = $_id;
        $this->name = $_name;
        $this->price = $_price;
        $this->category_id = $_category_id;
        $this->photo = $_photo;
    }
    public static function readAll()
    {
        global $db;
        $result = $db->query("select m.*,c.name as category from res_menu m, res_menu_categories c where m.categories_id = c.id");
        return $result->fetch_all(MYSQLI_ASSOC);
    }
public function create()
{
    global $db;
    $result = $db->query("CALL proc_menu_create('$this->name', $this->category_id, $this->price)");

    if ($result) {
        
    return "Data saved successfully!";
    }



}


public static function readCategories() {
    global $db;

    $result = $db->query("SELECT * FROM res_menu_categories");

    if ($result) {
        return $result->fetch_all(MYSQLI_ASSOC);
    }else{
        return $db->error;
    }
}

}
