diff --git a/apps/Recipes/Controllers/CatalogController.php b/apps/Recipes/Controllers/CatalogController.php new file mode 100644 index 0000000..4bcbc7b --- /dev/null +++ b/apps/Recipes/Controllers/CatalogController.php @@ -0,0 +1,10 @@ + 'int', + 'name' => 'string', + ]; + public static function init_table() + { + $result = db_query('CREATE TABLE ' . static::$table_name . ' ( + id INT AUTO_INCREMENT PRIMARY KEY, + + name VARCHAR(255) NOT NULL + );'); + return $result; + } } \ No newline at end of file diff --git a/apps/Recipes/Models/IngredientInRecipeModel.php b/apps/Recipes/Models/IngredientInRecipeModel.php index 97bc415..1082ad9 100644 --- a/apps/Recipes/Models/IngredientInRecipeModel.php +++ b/apps/Recipes/Models/IngredientInRecipeModel.php @@ -5,5 +5,29 @@ use Lycoreco\Includes\Model\BaseModel; class IngredientInRecipeModel extends BaseModel { + public $field_ingredient_id; + public $field_receipt_id; + public $field_amount; + static protected $table_name = 'recipe_ingredients'; + static protected $table_fields = [ + 'id' => 'int', + 'ingredient_id' => 'int', + 'receipt_id' => 'int', + 'amount' => 'int' + ]; + public static function init_table() + { + $result = db_query('CREATE TABLE ' . static::$table_name . ' ( + id INT AUTO_INCREMENT PRIMARY KEY, + + ingredient_id INT NOT NULL, + receipt_id INT NOT NULL, + amount INT NOT NULL, + + FOREIGN KEY (ingredient_id) REFERENCES ingredients(id) ON DELETE CASCADE, + FOREIGN KEY (receipt_id) REFERENCES recipes(id) ON DELETE CASCADE + );'); + return $result; + } } \ No newline at end of file diff --git a/apps/Recipes/Models/IngredientModel.php b/apps/Recipes/Models/IngredientModel.php index f739e45..550c3c5 100644 --- a/apps/Recipes/Models/IngredientModel.php +++ b/apps/Recipes/Models/IngredientModel.php @@ -5,5 +5,23 @@ use Lycoreco\Includes\Model\BaseModel; class IngredientModel extends BaseModel { - + public $field_name; + public $field_unit_name; + static protected $table_name = 'ingredients'; + + static protected $table_fields = [ + 'id' => 'int', + 'name' => 'string', + 'unit_name' => 'string' + ]; + public static function init_table() + { + $result = db_query('CREATE TABLE ' . static::$table_name . ' ( + id INT AUTO_INCREMENT PRIMARY KEY, + + name VARCHAR(255) NOT NULL, + unit_name VARCHAR(20) NULL + );'); + return $result; + } } \ No newline at end of file diff --git a/apps/Recipes/Models/RecipeModel.php b/apps/Recipes/Models/RecipeModel.php index 97a96fe..13628ea 100644 --- a/apps/Recipes/Models/RecipeModel.php +++ b/apps/Recipes/Models/RecipeModel.php @@ -13,4 +13,33 @@ class RecipeModel extends BaseModel public $field_author_id; public $field_status; public $field_created_at; + + static protected $table_name = 'recipes'; + static protected $table_fields = [ + 'id' => 'int', + 'title' => 'string', + 'instruction' => 'string', + 'estimated_time' => 'int', + 'estimated_price' => 'int', + 'author_id' => 'int', + 'status' => 'string', + 'created_at' => 'DateTime' + ]; + public static function init_table() + { + $result = db_query('CREATE TABLE ' . static::$table_name . ' ( + id INT AUTO_INCREMENT PRIMARY KEY, + + title VARCHAR(255) NOT NULL, + instruction TEXT NOT NULL, + estimated_time INT NOT NULL, + estimated_price INT NOT NULL, + author_id INT NOT NULL, + status VARCHAR(20) NOT NULL CHECK (status IN (\'publish\', \'pending\')), + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + + FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE CASCADE + );'); + return $result; + } } \ No newline at end of file diff --git a/apps/Recipes/Templates/catalog.php b/apps/Recipes/Templates/catalog.php new file mode 100644 index 0000000..9e6c751 --- /dev/null +++ b/apps/Recipes/Templates/catalog.php @@ -0,0 +1 @@ +Catalog page \ No newline at end of file diff --git a/apps/Recipes/Templates/single.php b/apps/Recipes/Templates/single.php new file mode 100644 index 0000000..10763d4 --- /dev/null +++ b/apps/Recipes/Templates/single.php @@ -0,0 +1 @@ +Single Recipe item \ No newline at end of file diff --git a/apps/Recipes/urls.php b/apps/Recipes/urls.php index 0d50ea8..15db150 100644 --- a/apps/Recipes/urls.php +++ b/apps/Recipes/urls.php @@ -1,3 +1,9 @@ \ No newline at end of file