102 lines
3.4 KiB
PHP
Executable File
102 lines
3.4 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Recettes\Controller;
|
|
|
|
use Exception;
|
|
use Propel\Runtime\Exception\PropelException;
|
|
use Propel\Runtime\Propel;
|
|
use Recettes\Form\RecetteCreateForm;
|
|
use Recettes\Model\Recipe;
|
|
use Recettes\Model\RecipeProducts;
|
|
use Recettes\Model\RecipeQuery;
|
|
use Recettes\Model\RecipeSteps;
|
|
use Recettes\Model\RecipeStepsQuery;
|
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
|
use Thelia\Controller\Admin\BaseAdminController;
|
|
use Thelia\Core\Event\Content\ContentUpdateEvent;
|
|
use Thelia\Core\HttpFoundation\Request;
|
|
use Thelia\Model\ContentI18nQuery;
|
|
use Thelia\Model\ContentQuery;
|
|
use Thelia\Tools\URL;
|
|
|
|
|
|
/**
|
|
* Class MainController
|
|
* @package Recettes\Controller
|
|
*/
|
|
class MainController extends BaseAdminController
|
|
{
|
|
|
|
public function saveRecipe(Request $request)
|
|
{
|
|
$error = "";
|
|
$con = Propel::getConnection();
|
|
$nouvelleRecette = false;
|
|
|
|
$form = new RecetteCreateForm($request);
|
|
try {
|
|
$formValidate = $this->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"));
|
|
}
|
|
|
|
}
|