rename 'recipe' to 'instructions'

This commit is contained in:
Thomas Rubini 2023-01-26 22:34:13 +01:00
parent 6bac400a23
commit d6cf92b7da
No known key found for this signature in database
GPG Key ID: C7D287C8C1CAC373
4 changed files with 18 additions and 18 deletions

View File

@ -65,13 +65,13 @@ final class RecipeController
$O_recipe->I_DIFFICULTY_ID = $O_difficulty->I_ID; $O_recipe->I_DIFFICULTY_ID = $O_difficulty->I_ID;
$O_recipe->I_AUTHOR_ID = $_SESSION["ID"]; $O_recipe->I_AUTHOR_ID = $_SESSION["ID"];
$S_recipe = ""; $S_instructions = "";
$i = 0; $i = 0;
foreach(Utils::getOrDie($A_postParams, "recipeInstructions") as $S_instr) { foreach(Utils::getOrDie($A_postParams, "recipeInstructions") as $S_instr) {
$S_recipe.= "\n\n".$S_instr; $S_instructions.= "\n\n".$S_instr;
$i++; $i++;
} }
$O_recipe->S_RECIPE = substr($S_recipe, 2); $O_recipe->S_INSTRUCTIONS = substr($S_instructions, 2);
} }
public function createAction(Array $A_urlParams = null, Array $A_postParams = null) public function createAction(Array $A_urlParams = null, Array $A_postParams = null)

View File

@ -6,7 +6,7 @@ final class RecipeModel
public $S_NAME = null; public $S_NAME = null;
public $I_TIME = null; public $I_TIME = null;
public $S_DESCR = null; public $S_DESCR = null;
public $S_RECIPE = null; public $S_INSTRUCTIONS = null;
public $I_DIFFICULTY_ID = null; public $I_DIFFICULTY_ID = null;
public $I_AUTHOR_ID = null; public $I_AUTHOR_ID = null;
@ -22,13 +22,13 @@ final class RecipeModel
return new RecipeModel(); return new RecipeModel();
} }
public static function createFull($S_NAME, $I_TIME, $S_DESCR, $S_RECIPE, $I_DIFFICULTY_ID, $I_AUTHOR_ID) public static function createFull($S_NAME, $I_TIME, $S_DESCR, $S_INSTRUCTIONS, $I_DIFFICULTY_ID, $I_AUTHOR_ID)
{ {
$O_recipe = new RecipeModel(); $O_recipe = new RecipeModel();
$O_recipe->S_NAME = $S_NAME; $O_recipe->S_NAME = $S_NAME;
$O_recipe->I_TIME = $I_TIME; $O_recipe->I_TIME = $I_TIME;
$O_recipe->S_DESCR = $S_DESCR; $O_recipe->S_DESCR = $S_DESCR;
$O_recipe->S_RECIPE = $S_RECIPE; $O_recipe->S_INSTRUCTIONS = $S_INSTRUCTIONS;
$O_recipe->I_DIFFICULTY_ID = $I_DIFFICULTY_ID; $O_recipe->I_DIFFICULTY_ID = $I_DIFFICULTY_ID;
$O_recipe->I_AUTHOR_ID = $I_AUTHOR_ID; $O_recipe->I_AUTHOR_ID = $I_AUTHOR_ID;
return $O_recipe; return $O_recipe;
@ -37,11 +37,11 @@ final class RecipeModel
public function insert() public function insert()
{ {
$O_model = Model::get(); $O_model = Model::get();
$stmt = $O_model->prepare("INSERT INTO RECIPE (NAME, TIME, DESCR, RECIPE ,DIFFICULTY_ID, AUTHOR_ID) VALUES(:name, :time, :descr, :recipe, :difficulty_id, :author_id)"); $stmt = $O_model->prepare("INSERT INTO RECIPE (NAME, TIME, DESCR, INSTRUCTIONS ,DIFFICULTY_ID, AUTHOR_ID) VALUES(:name, :time, :descr, :instructions, :difficulty_id, :author_id)");
$stmt->bindParam("name", $this->S_NAME); $stmt->bindParam("name", $this->S_NAME);
$stmt->bindParam("time", $this->I_TIME); $stmt->bindParam("time", $this->I_TIME);
$stmt->bindParam("descr", $this->S_DESCR); $stmt->bindParam("descr", $this->S_DESCR);
$stmt->bindParam("recipe", $this->S_RECIPE); $stmt->bindParam("instructions", $this->S_INSTRUCTIONS);
$stmt->bindParam("difficulty_id", $this->I_DIFFICULTY_ID); $stmt->bindParam("difficulty_id", $this->I_DIFFICULTY_ID);
$stmt->bindParam("author_id", $this->I_AUTHOR_ID); $stmt->bindParam("author_id", $this->I_AUTHOR_ID);
$stmt->execute(); $stmt->execute();
@ -51,12 +51,12 @@ final class RecipeModel
public function update() public function update()
{ {
$O_model = Model::get(); $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, INSTRUCTIONS=:instructions, DIFFICULTY_ID=:difficulty_id, AUTHOR_ID=:author_id WHERE ID=:id");
$stmt->bindParam("id", $this->I_ID); $stmt->bindParam("id", $this->I_ID);
$stmt->bindParam("name", $this->S_NAME); $stmt->bindParam("name", $this->S_NAME);
$stmt->bindParam("time", $this->I_TIME); $stmt->bindParam("time", $this->I_TIME);
$stmt->bindParam("descr", $this->S_DESCR); $stmt->bindParam("descr", $this->S_DESCR);
$stmt->bindParam("recipe", $this->S_RECIPE); $stmt->bindParam("instructions", $this->S_INSTRUCTIONS);
$stmt->bindParam("difficulty_id", $this->I_DIFFICULTY_ID); $stmt->bindParam("difficulty_id", $this->I_DIFFICULTY_ID);
$stmt->bindParam("author_id", $this->I_AUTHOR_ID); $stmt->bindParam("author_id", $this->I_AUTHOR_ID);
$stmt->execute(); $stmt->execute();
@ -166,8 +166,8 @@ final class RecipeModel
return $this->A_APPRS; return $this->A_APPRS;
} }
public function getSteps(){ public function getSplitInstructions(){
return explode("\n\n", str_replace("\r", "", $this->S_RECIPE)); return explode("\n\n", str_replace("\r", "", $this->S_INSTRUCTIONS));
} }
//TODO: return array object //TODO: return array object

View File

@ -5,7 +5,7 @@ if ($O_recipe === null) {
$S_name = null; $S_name = null;
$I_time = null; $I_time = null;
$S_descr = null; $S_descr = null;
$A_steps = array(); $A_instructions = array();
$S_difficultyName = null; $S_difficultyName = null;
$A_parts = array(); $A_parts = array();
$A_ingredients = array(); $A_ingredients = array();
@ -13,7 +13,7 @@ if ($O_recipe === null) {
$S_name = $O_recipe->S_NAME; $S_name = $O_recipe->S_NAME;
$I_time = $O_recipe->I_TIME; $I_time = $O_recipe->I_TIME;
$S_descr = $O_recipe->S_DESCR; $S_descr = $O_recipe->S_DESCR;
$A_steps = $O_recipe->getSteps(); $A_instructions = $O_recipe->getSplitInstructions();
$S_difficultyName = $O_recipe->getDifficulty()->S_NAME; $S_difficultyName = $O_recipe->getDifficulty()->S_NAME;
$A_parts = array(); // TODO $A_parts = array(); // TODO
$A_ingredients = $O_recipe->getIngredients(); $A_ingredients = $O_recipe->getIngredients();
@ -110,7 +110,7 @@ if ($O_recipe === null) {
<ol class="recipeInstructions"> <ol class="recipeInstructions">
<?php <?php
if (count($A_steps) === 0) { if (count($A_instructions) === 0) {
echo '<li> echo '<li>
<label for="recipeInstruction1">Étape 1&nbsp;:</label> <label for="recipeInstruction1">Étape 1&nbsp;:</label>
<input type="text" name="recipeInstructions[]" id="recipeInstruction1" placeholder="Battre les oeufs et la farine dans un grand saladier."> <input type="text" name="recipeInstructions[]" id="recipeInstruction1" placeholder="Battre les oeufs et la farine dans un grand saladier.">
@ -120,10 +120,10 @@ if ($O_recipe === null) {
$numberOfInstructions = 1; $numberOfInstructions = 1;
} else { } else {
$i = 1; $i = 1;
foreach($A_steps as $S_step) { foreach($A_instructions as $S_instr) {
echo '<li> echo '<li>
<label for="recipeInstruction'.$i.'">Étape '.$i.'&nbsp;:</label> <label for="recipeInstruction'.$i.'">Étape '.$i.'&nbsp;:</label>
<input type="text" name="recipeInstructions[]" id="recipeInstruction'.$i.'" placeholder="Battre les oeufs et la farine dans un grand saladier." value="'.$S_step.'"> <input type="text" name="recipeInstructions[]" id="recipeInstruction'.$i.'" placeholder="Battre les oeufs et la farine dans un grand saladier." value="'.$S_instr.'">
</li>'; </li>';
$i++; $i++;
} }

View File

@ -29,7 +29,7 @@ $O_recipe = $A_view["RECIPE"];
<h2>Préparation</h2> <h2>Préparation</h2>
<ol> <ol>
<?php <?php
foreach($O_recipe->getSteps() as $S_instr) foreach($O_recipe->getSplitInstructions() as $S_instr)
echo "<li>".$S_instr."</li>"; echo "<li>".$S_instr."</li>";
?> ?>
</ol> </ol>