Module Recettes
This commit is contained in:
60
local/modules/Recettes/Controller/MainController.php
Executable file
60
local/modules/Recettes/Controller/MainController.php
Executable file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Recettes\Controller;
|
||||
|
||||
use Exception;
|
||||
use Propel\Runtime\Exception\PropelException;
|
||||
use Propel\Runtime\Propel;
|
||||
use Recettes\Form\RecetteCreateForm;
|
||||
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)
|
||||
{
|
||||
$productsList = [];
|
||||
|
||||
$con = Propel::getConnection();
|
||||
$error = "";
|
||||
|
||||
$form = new RecetteCreateForm($request);
|
||||
try {
|
||||
$formValidate = $this->validateForm($form);
|
||||
$data = $formValidate->getData();
|
||||
|
||||
$content_id = $data['content_id'];
|
||||
$title = $data['title'];
|
||||
$difficulty = $data['difficulty'];
|
||||
$numberPeople = $data['people'];
|
||||
$preparationTime = $data['preparation_time'];
|
||||
$cookingTime = $data['cooking_time'];
|
||||
$steps = $data['steps'];
|
||||
|
||||
if (null !== $title && null !== $preparationTime) {
|
||||
$content = ContentI18nQuery::create()->filterByLocale('fr_FR')->findOneById($content_id);
|
||||
|
||||
$encodedData = json_encode($data);
|
||||
$content->setDescription($encodedData);
|
||||
$content->save($con);
|
||||
$con->commit();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
|
||||
return new RedirectResponse(URL::getInstance()->absoluteUrl("/admin/content/update/" . $content_id));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user