Recettes : BO, rajout de l'ajax

This commit is contained in:
2021-05-07 14:02:09 +02:00
parent 16bfe33efd
commit 5e1fe56d56
36 changed files with 1331 additions and 58 deletions

View File

@@ -3,21 +3,28 @@
namespace Recettes\Controller;
use Exception;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\Exception\PropelException;
use Propel\Runtime\Propel;
use Recettes\Form\RecetteCreateForm;
use Recettes\Model\Recipe;
use Recettes\Model\RecipeProducts;
use Recettes\Model\RecipeProductsQuery;
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\JsonResponse;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Form\BaseForm;
use Thelia\Model\AttributeCombinationQuery;
use Thelia\Model\ContentI18nQuery;
use Thelia\Model\ContentQuery;
use Thelia\Model\Map\ProductI18nTableMap;
use Thelia\Model\Map\ProductTableMap;
use Thelia\Model\ProductQuery;
use Thelia\Tools\URL;
@@ -47,16 +54,12 @@ class BackController extends BaseAdminController
$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();
@@ -71,26 +74,7 @@ class BackController extends BaseAdminController
$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));
return new RedirectResponse(URL::getInstance()->absoluteUrl("/admin/content/update/" . $contentId . "#recipe"));
}
} catch (\Exception $e) {
$error = $e->getMessage();
@@ -99,4 +83,77 @@ class BackController extends BaseAdminController
return new RedirectResponse(URL::getInstance()->absoluteUrl("/admin/content"));
}
public function removeProduct($recipeId, $pseId, $contentId)
{
RecipeProductsQuery::create()->filterByRecipeId($recipeId)->filterByPseId($pseId)->delete();
return new RedirectResponse(URL::getInstance()->absoluteUrl("/admin/content/update/" . $contentId . "#recipe"));
}
public function searchProduct()
{
$locale = $this->getCurrentEditionLocale();
$ref = $this->getRequest()->get('query', null);
$result = [];
if (! empty($ref)) {
$data = ProductQuery::create()
->filterByRef("%$ref%", Criteria::LIKE)
->orderByRef()
->useI18nQuery($locale)
->withColumn(ProductI18nTableMap::COL_TITLE, 'title')
->endUse()
->limit(15)
->select([
ProductTableMap::COL_ID,
ProductTableMap::COL_REF,
'title'
])
->find();
foreach ($data as $item) {
$combinations = AttributeCombinationQuery::create()
->filterByProductSaleElementsId($item->getId())
$item
$result[] = [
'id' => $item[ProductTableMap::COL_ID],
'ref' => $item[ProductTableMap::COL_REF],
'title' => $item['title'],
'combinations' => []
];
}
}
return JsonResponse::create($result);
}
public function searchCombination()
{
$locale = $this->getCurrentEditionLocale();
$ref = $this->getRequest()->get('query', null);
$result = [];
return JsonResponse::create($result);
}
/*
public function addProduct($contentId)
{
$productId = (int) $this->getRequest()->get('product_id');
(new AgendaRelatedProduct())
->setProductId($productId)
->setContentId($contentId)
->save();
return $this->render('ajax/related-products', [ 'content_id' => $contentId ]);
}
*/
}