Recettes : presque OK sur addToCart
This commit is contained in:
102
local/modules/Recettes/Controller/BackController.php
Executable file
102
local/modules/Recettes/Controller/BackController.php
Executable file
@@ -0,0 +1,102 @@
|
||||
<?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\Form\BaseForm;
|
||||
use Thelia\Model\ContentI18nQuery;
|
||||
use Thelia\Model\ContentQuery;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
|
||||
/**
|
||||
* Class BackController
|
||||
* @package Recettes\Controller
|
||||
*/
|
||||
class BackController 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"));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user