Module Recettes

This commit is contained in:
2021-04-02 20:54:04 +02:00
parent 8d8ca3fe2f
commit 99f3749535
11 changed files with 348 additions and 124 deletions

View File

@@ -4,47 +4,14 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd">
<loops>
<!-- sample definition
<loop name="MySuperLoop" class="Recettes\Loop\MySuperLoop" />
-->
</loops>
<forms>
<!--
<form name="MyFormName" class="Recettes\Form\MySuperForm" />
-->
<form name="recette_create_form" class="Recettes\Form\RecetteCreateForm" />
</forms>
<commands>
<!--
<command class="Recettes\Command\MySuperCommand" />
-->
</commands>
<!--
<services>
</services>
-->
<!--
<hooks>
<hook id="recettes.hook" class="Recettes\Hook\MySuperHook">
<tag name="hook.event_listener" event="main.body.bottom" type="front|back|pdf|email" method="onMainBodyBottom" />
<hook id="recettes.hook" class="Recettes\Hook\HookManager">
<tag name="hook.event_listener" event="content.tab" type="back" method="onEditTab" />
</hook>
</hooks>
-->
<!--
<exports>
</exports>
-->
<!--
<imports>
</imports>
-->
</config>

View File

@@ -4,18 +4,11 @@
xsi:schemaLocation="http://thelia.net/schema/dic/module http://thelia.net/schema/dic/module/module-2_2.xsd">
<fullnamespace>Recettes\Recettes</fullnamespace>
<descriptive locale="en_US">
<title>Automatically generated module - please update module.xml file</title>
<!--
<subtitle></subtitle>
<description></description>
<postscriptum></postscriptum>
-->
<title>Esay way to display a recipe using Thelia's content feature</title>
</descriptive>
<descriptive locale="fr_FR">
<title>Module généré automatiquement - éditez le fichier module.xml</title>
<title>Permet de mettre ne page facilement une recette de cuisine via les contenus Thelia</title>
</descriptive>
<!-- <logo></logo> -->
<!--<images-folder>images</images-folder>-->
<languages>
<language>en_US</language>
<language>fr_FR</language>
@@ -23,19 +16,11 @@
<version></version>
<authors>
<author>
<name></name>
<email></email>
<name>Laurent LE CORRE</name>
<email>laurent@thecoredev.fr</email>
</author>
</authors>
<type>classic</type>
<!--
module dependencies
<required>
<module version="&gt;=0.1">Front</module>
<module version="~1.0">HookCart</module>
<module version="&gt;0.2">HookSearch</module>
</required>
-->
<thelia>2.4.3</thelia>
<stability>other</stability>
<mandatory>0</mandatory>

View File

@@ -4,28 +4,8 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
<!--
if a /admin/module/recettes/ route is provided, a "Configuration" button will be displayed
for the module in the module list. Clicking this button will invoke this route.
<route id="my_route_id" path="/admin/module/recettes">
<default key="_controller">Recettes\Full\Class\Name\Of\YourConfigurationController::methodName</default>
<route id="recipe.save" path="/admin/module/Recettes/save" methods="post">
<default key="_controller">Recettes\Controller\MainController::saveRecipe</default>
</route>
<route id="my_route_id" path="/admin/module/recettes/route-name">
<default key="_controller">Recettes\Full\Class\Name\Of\YourAdminController::methodName</default>
</route>
<route id="my_route_id" path="/my/route/name">
<default key="_controller">Recettes\Full\Class\Name\Of\YourOtherController::methodName</default>
</route>
...add as many routes as required.
<route>
...
</route>
-->
</routes>

View 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));
}
}

View File

@@ -0,0 +1,131 @@
<?php
namespace Recettes\Form;
use Recettes\Recettes;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Core\Translation\Translator;
use Thelia\Form\BaseForm;
/**
* Class RecetteCreateForm
* @package Recettes\Form
*/
class RecetteCreateForm extends BaseForm
{
/** @var Translator $translator */
protected $translator;
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return 'recette_create_form';
}
protected function buildForm()
{
$this
->formBuilder
->add(
"content_id",
"integer",
[
"label" => $this->trans("Content Id"),
"constraints" => [
new NotBlank()
]
]
)
->add(
"title",
"text",
[
"label" => $this->trans("Title"),
"label_attr" => [
"for" => "attr-title"
],
"constraints" => [
new NotBlank()
]
]
)
->add(
"difficulty",
"integer",
[
"label" => $this->trans("Difficulty"),
"label_attr" => [
"for" => "attr-difficulty"
],
"constraints" => [
new NotBlank()
]
]
)
->add(
"people",
"integer",
[
"label" => $this->trans("Number of people"),
"label_attr" => [
"for" => "attr-difficulty"
],
"constraints" => [
new NotBlank()
]
]
)
->add(
"preparation_time",
"text",
[
"label" => $this->trans("Preparation time"),
"label_attr" => [
"for" => "attr-preparation-time",
"help" => "ex : 1h15 ou 45 minutes"
],
"constraints" => [
new NotBlank()
]
]
)
->add(
"cooking_time",
"text",
[
"label" => $this->trans("Cooking time"),
"label_attr" => [
"for" => "attr-cooking-time",
"help" => "ex : 1h15 ou 45 minutes"
],
"required" => false
]
)
->add(
"steps",
"text",
[
"label" => $this->trans("Steps"),
"label_attr" => [
"for" => "attr-recipe"
],
"constraints" => [
new NotBlank()
]
]
);
}
protected function trans($id, $parameters = [])
{
if (null === $this->translator) {
$this->translator = Translator::getInstance();
}
return $this->translator->trans($id, $parameters, Recettes::MESSAGE_DOMAIN);
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace Recettes\Hook;
use Recettes\Recettes;
use Thelia\Core\Event\Hook\HookRenderBlockEvent;
use Thelia\Core\Hook\BaseHook;
/**
* Class BackHook
* @package Recettes\Hook
*/
class HookManager extends baseHook
{
public function onEditTab(HookRenderBlockEvent $event)
{
$event->add(
[
"id" => 'admin-comment',
"title" => 'Recette',
"content" => ($this->render('recette.html'))
]
);
}
}

View File

@@ -1,4 +1,11 @@
<?php
return array(
// 'an english string' => 'La traduction française de la chaine',
'Steps' => 'Préparation',
'Title' => 'Titre de la recette',
'Preparation time' => 'Temps de préparation',
'Cooking time' => 'Temps de cuisson',
'Difficulty' => 'Difficulté',
'Number of people' => 'Nombre de personnes',
'Product' => 'Produit',
'Quantity' => 'Quantité',
);

View File

@@ -1,14 +1,4 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Recettes;
@@ -17,12 +7,7 @@ use Thelia\Module\BaseModule;
class Recettes extends BaseModule
{
/** @var string */
const DOMAIN_NAME = 'recettes';
const DOMAIN_NAME = 'recettes';
const MESSAGE_DOMAIN = 'recettes';
/*
* You may now override BaseModuleInterface methods, such as:
* install, destroy, preActivation, postActivation, preDeactivation, postDeactivation
*
* Have fun !
*/
}

View File

@@ -0,0 +1,109 @@
<div id="wrapper" class="container">
<div class="row">
{form name="recette_create_form"}
<form id="admin-comment-form" method="post" action="{url path='/admin/module/Recettes/save'}" {form_enctype form=$form}>
{form_hidden_fields form=$form}
{form_field form=$form field="content_id"}
<input type="hidden" name="{$name}" value="{$content_id}">
{/form_field}
<div class="col-md-8">
{form_field form=$form field="title"}
<div class="form-group form-inline">
<label class="control-label" for="{$label_attr.for}">
{intl l=$label d='recettes'}
{if $required}<span class="required">*</span>{/if}
</label>
<input type="text" id="{$label_attr.for}" class="form-control large" name="{$name}" value="" {if $required}required{/if} />&nbsp
</div>
{form_error form=$form field="title"}{$message}{/form_error}
{/form_field}
{form_field form=$form field="difficulty"}
<div class="form-group form-inline">
<label class="control-label" for="{$label_attr.for}">
{intl l=$label d='recettes'}
{if $required}<span class="required">*</span>{/if}
</label>
<select id="{$label_attr.for}" name="{$name}">
<option value=0>Facile</option>
<option value=1>Moyen</option>
<option value=2>Difficile</option>
</select>
</div>
{form_error form=$form field="difficulty"}{$message}{/form_error}
{/form_field}
{form_field form=$form field="people"}
<div class="form-group form-inline">
<label class="control-label" for="{$label_attr.for}">
{intl l=$label d='recettes'}
{if $required}<span class="required">*</span>{/if}
</label>
<input type="text" id="{$label_attr.for}" class="form-control etroit" name="{$name}" value="" {if $required}required{/if} />&nbsp
</div>
{form_error form=$form field="people"}{$message}{/form_error}
{/form_field}
{form_field form=$form field="preparation_time"}
<div class="form-group form-inline">
<label class="control-label" for="{$label_attr.for}">
{intl l=$label d='recettes'}
{if $required}<span class="required">*</span>{/if}
</label>
<input type="text" id="{$label_attr.for}" class="form-control etroit" name="{$name}" value="" {if $required}required{/if} />&nbsp
<span class="help-block">{$label_attr.help}</span>
</div>
{form_error form=$form field="preparation_time"}{$message}{/form_error}
{/form_field}
{form_field form=$form field="cooking_time"}
<div class="form-group form-inline">
<label class="control-label" for="{$label_attr.for}">
{intl l=$label d='recettes'}
</label>
<input type="text" id="{$label_attr.for}" class="form-control etroit" name="{$name}" value="" />&nbsp
<span class="help-block">{$label_attr.help}</span>
</div>
{form_error form=$form field="cooking_time"}{$message}{/form_error}
{/form_field}
{form_field form=$form field="steps"}
<div class="form-group form-inline">
<label class="control-label" for="{$label_attr.for}">
{intl l=$label d='recettes'}
</label>
{if $required}<span class="required">*</span>{/if}
<textarea id="attr-recipe" name="{$name}" rows="10" class="form-control wysiwyg">{$value}</textarea>
</div>
{form_error form=$form field="steps"}{$message}{/form_error}
{/form_field}
</div>
<div class="col-md-4">
<table class="table table-striped">
<thead>
<th>{intl l="Product" d="recettes"}</th>
<th>{intl l="Quantity" d="recettes"}</th>
</thead>
<tbody></tbody>
</table>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">{intl l="Save" d="recettes"}</button>
</div>
</form>
{/form}
</div>
</div>

View File

@@ -1,10 +0,0 @@
<div class="row">
<div class="col-md-12">
{render_form_field field='titre'}
{render_form_field field='difficulte'}
{render_form_field field='temps_preparation'}
{render_form_field field='temps_cuisson'}
{render_form_field field='ingredients'}
{render_form_field field="description" extra_class="wysiwyg"}
</div>
</div>

View File

@@ -9,15 +9,6 @@
{block name="page-title"}{intl l='Edit content'}{/block}
{assign var="recette" value=false}
{loop name="my_folder_path" type="folder-path" visible="*" folder=$folder_id}
{if $TITLE|strstr:"recettes"}
{assign var="recette" value=true}
{/if}
{/loop}
{block name="main-content"}
<div class="content edit-content">
<div id="wrapper" class="container">
@@ -92,9 +83,6 @@
<li><a href="#documents" data-toggle="tab">{intl l="Documents"}</a></li>
{$smarty.capture.content_tab_tab nofilter}
<li><a href="#modules" data-toggle="tab">{intl l="Modules"}</a></li>
{if $recette}
<li><a href="#recette" data-toggle="tab">{intl l="Recette"}</a></li>
{/if}
</ul>
<div class="tab-content">
@@ -224,12 +212,6 @@
{* ugly fix : {hook name="content.tab-content" id="{$content_id}" view="content"} *}
{include file="includes/module-tab-content.html" hook="content.tab-content" location="content-edit" id="{$content_id}" view="content"}
</div>
{if $recette}
<div class="tab-pane fade" id="recette">
{hook name="hook-recette" content_id=$content_id}
</div>
{/if}
</div>
</div>
</div>