validateForm($form); $data = $formValidate->getData(); $contentId = $data['content_id']; $title = $data['title']; $summary = $data['summary']; $difficulty = $data['difficulty']; $numberPeople = $data['people']; $preparationTime = $data['preparation_time']; $cookingTime = $data['cooking_time']; $otherIngredients = $data['other_ingredients']; // $steps = $data['steps']; if (null !== $title && null !== $contentId && null !== $difficulty && null !== $numberPeople && null !== $preparationTime) { $recipe = RecipeQuery::create()->findOneByContentId($contentId); if (null === $recipe) { $nouvelleRecette = true; $recipe = new Recipe(); } else $recipeId = $recipe->getId(); $recipe->setContentId($contentId); $recipe->setSummary($summary); $recipe->setTitle($title); $recipe->setDifficulty($difficulty); $recipe->setPeople($numberPeople); $recipe->setPreparationTime($preparationTime); $recipe->setCookingTime($cookingTime); $recipe->setOtherIngredients($otherIngredients); $recipe->save($con); $con->commit(); if (!$nouvelleRecette) { // On supprime les étapes pour les recréer par la suite. // $steps = RecipeStepsQuery::create()->findByRecipeId($recipeId); // $steps->delete($con); // $con->commit(); } /* foreach ($steps as $step) { $recipeSteps = new RecipeSteps(); $recipeSteps->setRecipeId($recipeId); $recipeSteps->setStep($step['id']); $recipeSteps->setDescription($step['description']); $recipeSteps->save(); $con->commit(); } */ // A rajouter : les produits et les étapes return new RedirectResponse(URL::getInstance()->absoluteUrl("/admin/content/update/" . $contentId)); } } catch (\Exception $e) { $error = $e->getMessage(); } return new RedirectResponse(URL::getInstance()->absoluteUrl("/admin/content")); } }