Merge pull request #132 from ThomasRubini/getsteps

This commit is contained in:
Thomas Rubini 2023-01-26 17:36:55 +01:00 committed by GitHub
commit e3d10e924d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 17 deletions

View File

@ -147,6 +147,10 @@ final class RecipeModel
return $this->A_APPRS;
}
public function getSteps(){
return explode("\n\n", str_replace("\r", "", $this->S_RECIPE));
}
//TODO: return array object
public static function searchRecipesByName($S_query)
{

View File

@ -5,7 +5,7 @@ if ($O_recipe === null) {
$S_name = null;
$I_time = null;
$S_descr = null;
$S_recipe = null;
$A_steps = array();
$S_difficultyName = null;
$A_parts = array();
$A_ingredients = array();
@ -13,7 +13,7 @@ if ($O_recipe === null) {
$S_name = $O_recipe->S_NAME;
$I_time = $O_recipe->I_TIME;
$S_descr = $O_recipe->S_DESCR;
$S_recipe = $O_recipe->S_RECIPE;
$A_steps = $O_recipe->getSteps();
$S_difficultyName = $O_recipe->getDifficulty()->S_NAME;
$A_parts = array(); // TODO
$A_ingredients = $O_recipe->getIngredients();
@ -109,28 +109,25 @@ if ($O_recipe === null) {
<ol class="recipeInstructions">
<?php
if(!empty($S_recipe)) {
$steps = explode("\n", $S_recipe);
$i = 1;
foreach($steps as $step) {
if (count($A_steps) === 0) {
echo '<li>
<label for="recipeInstruction1">Étape 1&nbsp;:</label>
<input type="text" name="recipeInstruction1" id="recipeInstruction1" placeholder="Battre les oeufs et la farine dans un grand saladier.">
</li>
</ol>
<button type="button" disabled="disabled" id="recipeButtonInstructionLess">-</button>';
$numberOfInstructions = 1;
} else {
foreach($A_steps as $S_step) {
echo '<li>
<label for="recipeInstruction'.$i.'">Étape '.$i.'&nbsp;:</label>
<input type="text" name="recipeInstruction'.$i.'" id="recipeInstruction'.$i.'" placeholder="Battre les oeufs et la farine dans un grand saladier." value="'.$step.'">
<input type="text" name="recipeInstruction'.$i.'" id="recipeInstruction'.$i.'" placeholder="Battre les oeufs et la farine dans un grand saladier." value="'.$S_step.'">
</li>';
$i++;
}
$numberOfInstructions = $i-1;
echo '</ol>
<button type="button" id="recipeButtonInstructionLess">-</button>';
} else {
echo '<li>
<label for="recipeInstruction1">Étape 1&nbsp;:</label>
<input type="text" name="recipeInstruction1" id="recipeInstruction1" placeholder="Battre les oeufs et la farine dans un grand saladier.">
</li>
</ol>
<button type="button" disabled="disabled" id="recipeButtonInstructionLess">-</button>';
$numberOfIngredients = 1;
$numberOfInstructions = 1;
}
?>
<button type="button" id="recipeButtonInstructionPlus">+</button>

View File

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