From 7fca2e6d78237ada0d1bf12a4fcaeaee7dd248f4 Mon Sep 17 00:00:00 2001
From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com>
Date: Wed, 25 Jan 2023 23:07:45 +0100
Subject: [PATCH 1/5] loop over difficulties
---
Views/recipe/edit.php | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/Views/recipe/edit.php b/Views/recipe/edit.php
index f9a3833..3903c8c 100644
--- a/Views/recipe/edit.php
+++ b/Views/recipe/edit.php
@@ -39,10 +39,11 @@ if ($O_recipe === null) {
From 300f11bb06344db338216aa2437c2cb61d10f4e6 Mon Sep 17 00:00:00 2001
From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com>
Date: Wed, 25 Jan 2023 23:07:59 +0100
Subject: [PATCH 2/5] rename getRecipeByID() to getByID()
---
Controllers/RecipeController.php | 2 +-
Models/RecipeModel.php | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/Controllers/RecipeController.php b/Controllers/RecipeController.php
index 788b025..1d0fe51 100644
--- a/Controllers/RecipeController.php
+++ b/Controllers/RecipeController.php
@@ -126,7 +126,7 @@ final class RecipeController
if (count($A_urlParams) !== 1 ) throw new HTTPSpecialCaseException(404);
- $O_recipe = RecipeModel::getRecipeByID($A_urlParams[0]);
+ $O_recipe = RecipeModel::getByID($A_urlParams[0]);
header("Content-Type: image");
if (isset($O_recipe)) {
diff --git a/Models/RecipeModel.php b/Models/RecipeModel.php
index bad69af..9ac5d90 100644
--- a/Models/RecipeModel.php
+++ b/Models/RecipeModel.php
@@ -73,7 +73,7 @@ final class RecipeModel
return $O_recipe;
}
- public static function getRecipeByID($I_id)
+ public static function getByID($I_id)
{
$O_model = Model::get();
$stmt = $O_model->prepare("SELECT * FROM RECIPE WHERE ID=:id");
@@ -157,7 +157,7 @@ final class RecipeModel
public static function getFullRecipeById($I_id)
{
- $O_recipe = self::getRecipeByID($I_id);
+ $O_recipe = self::getByID($I_id);
$O_recipe->getFullRecipe();
return $O_recipe;
}
From 3160b12455b5376ed98f53a93d9f967a09316ce6 Mon Sep 17 00:00:00 2001
From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com>
Date: Wed, 25 Jan 2023 23:11:53 +0100
Subject: [PATCH 3/5] pass recipe ID to edit in URL param
---
Controllers/RecipeController.php | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/Controllers/RecipeController.php b/Controllers/RecipeController.php
index 1d0fe51..96a0049 100644
--- a/Controllers/RecipeController.php
+++ b/Controllers/RecipeController.php
@@ -41,7 +41,7 @@ final class RecipeController
}
}
- View::show("recipe/edit", array("POST_URI" => "/recipe/update", "RECIPE" => $O_recipe));
+ View::show("recipe/edit", array("POST_URI" => "/recipe/update/".$O_recipe->I_ID, "RECIPE" => $O_recipe));
}
public function newAction(Array $A_urlParams = null, Array $A_postParams = null)
@@ -79,9 +79,13 @@ final class RecipeController
public function updateAction(Array $A_urlParams = null, Array $A_postParams = null)
{
+ if(count($A_urlParams)!=1){
+ throw new HTTPSpecialCaseException(404);
+ }
+
Session::login_or_die();
- $O_recipe = RecipeModel::getByID(Utils::getOrDie($A_postParams, "recipeID"));
+ $O_recipe = RecipeModel::getByID(Utils::intOrDie($A_urlParams[0]));
if ($O_recipe->I_AUTHOR_ID !== $_SESSION["ID"]) {
if(!Session::is_admin()){
From 83b3cd0bd5e6eddf6a5a01d3795c44fd58b2c25e Mon Sep 17 00:00:00 2001
From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com>
Date: Wed, 25 Jan 2023 23:12:02 +0100
Subject: [PATCH 4/5] fix ID variable
---
Models/DifficultyModel.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Models/DifficultyModel.php b/Models/DifficultyModel.php
index 1813cba..d2efb3f 100644
--- a/Models/DifficultyModel.php
+++ b/Models/DifficultyModel.php
@@ -55,7 +55,7 @@ final class DifficultyModel
if ($row === false) return null;
$O_diff = new DifficultyModel($row["NAME"]);
- $O_diff->I_ID = $I_id;
+ $O_diff->I_ID = $row["ID"];
return $O_diff;
}
public static function deleteByID($I_id)
From 00e62b7a3e8f333398d8e7eb3a40113e790d5281 Mon Sep 17 00:00:00 2001
From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com>
Date: Wed, 25 Jan 2023 23:12:08 +0100
Subject: [PATCH 5/5] fix typo in SQL query
---
Models/RecipeModel.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Models/RecipeModel.php b/Models/RecipeModel.php
index 9ac5d90..3909728 100644
--- a/Models/RecipeModel.php
+++ b/Models/RecipeModel.php
@@ -50,7 +50,7 @@ final class RecipeModel
public function update()
{
$O_model = Model::get();
- $stmt = $O_model->prepare("UPDATE RECIPE SET NAME=:name, TIME=:time, DESCR=:descr, RECIPE:recipe, DIFFICULTY_ID=:difficulty_id, AUTHOR_ID=:author_id WHERE ID=:id");
+ $stmt = $O_model->prepare("UPDATE RECIPE SET NAME=:name, TIME=:time, DESCR=:descr, RECIPE=:recipe, DIFFICULTY_ID=:difficulty_id, AUTHOR_ID=:author_id WHERE ID=:id");
$stmt->bindParam("id", $this->I_ID);
$stmt->bindParam("name", $this->S_NAME);
$stmt->bindParam("time", $this->I_TIME);