L'ajout des étapes de recette fonctionne.
Reste à faire : - suppression d'étape - déplacement d'étape
This commit is contained in:
@@ -24,5 +24,8 @@
|
|||||||
<default key="_controller">Recettes\Controller\BackController::addProduct</default>
|
<default key="_controller">Recettes\Controller\BackController::addProduct</default>
|
||||||
<requirement key="contentId">\d+</requirement>
|
<requirement key="contentId">\d+</requirement>
|
||||||
</route>
|
</route>
|
||||||
|
<route id="recipe.add_step" path="/admin/module/Recettes/add-step" methods="post">
|
||||||
|
<default key="_controller">Recettes\Controller\BackController::addStep</default>
|
||||||
|
</route>
|
||||||
|
|
||||||
</routes>
|
</routes>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use Propel\Runtime\ActiveQuery\Criteria;
|
|||||||
use Propel\Runtime\Exception\PropelException;
|
use Propel\Runtime\Exception\PropelException;
|
||||||
use Propel\Runtime\Propel;
|
use Propel\Runtime\Propel;
|
||||||
use Recettes\Form\RecetteCreateForm;
|
use Recettes\Form\RecetteCreateForm;
|
||||||
|
use Recettes\Form\StepCreateForm;
|
||||||
use Recettes\Model\Recipe;
|
use Recettes\Model\Recipe;
|
||||||
use Recettes\Model\RecipeProducts;
|
use Recettes\Model\RecipeProducts;
|
||||||
use Recettes\Model\RecipeProductsQuery;
|
use Recettes\Model\RecipeProductsQuery;
|
||||||
@@ -181,4 +182,36 @@ class BackController extends BaseAdminController
|
|||||||
return $this->render('includes/related-products', [ 'content_id' => $contentId ]);
|
return $this->render('includes/related-products', [ 'content_id' => $contentId ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function addStep(Request $request)
|
||||||
|
{
|
||||||
|
$form = new StepCreateForm($request);
|
||||||
|
$errorUrl = "";
|
||||||
|
try {
|
||||||
|
$formValidate = $this->validateForm($form);
|
||||||
|
$data = $formValidate->getData();
|
||||||
|
|
||||||
|
$recipeId = $data['recipe_id'];
|
||||||
|
$step = $data['step'];
|
||||||
|
$description = $data['description'];
|
||||||
|
$errorUrl = $data['error_url'];
|
||||||
|
$successUrl = $data['success_url'];
|
||||||
|
if ($recipeId && $step && $description) {
|
||||||
|
(new RecipeSteps())
|
||||||
|
->setRecipeId($recipeId)
|
||||||
|
->setStep($step)
|
||||||
|
->setDescription($description)
|
||||||
|
->save();
|
||||||
|
|
||||||
|
return new RedirectResponse(URL::getInstance()->absoluteUrl($successUrl));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return new RedirectResponse(URL::getInstance()->absoluteUrl($errorUrl));
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$error = $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace Recettes\Form;
|
namespace Recettes\Form;
|
||||||
|
|
||||||
|
use Recettes\Recettes;
|
||||||
|
use Thelia\Core\Translation\Translator;
|
||||||
use Thelia\Form\BaseForm;
|
use Thelia\Form\BaseForm;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16,12 +18,18 @@ class StepCreateForm extends BaseForm
|
|||||||
protected function buildForm()
|
protected function buildForm()
|
||||||
{
|
{
|
||||||
$this->formBuilder
|
$this->formBuilder
|
||||||
|
->add(
|
||||||
|
"recipe_id",
|
||||||
|
"integer",
|
||||||
|
[
|
||||||
|
"required" => true
|
||||||
|
])
|
||||||
->add(
|
->add(
|
||||||
"step",
|
"step",
|
||||||
"number",
|
"integer",
|
||||||
[
|
[
|
||||||
"required" => true,
|
"required" => true,
|
||||||
"label" => "Step",
|
"label" => $this->trans("Step"),
|
||||||
"label_attr" => ['for' => 'step']
|
"label_attr" => ['for' => 'step']
|
||||||
])
|
])
|
||||||
->add(
|
->add(
|
||||||
@@ -29,8 +37,8 @@ class StepCreateForm extends BaseForm
|
|||||||
"textarea",
|
"textarea",
|
||||||
[
|
[
|
||||||
"required" => true,
|
"required" => true,
|
||||||
"label" => "Description",
|
"label" => $this->trans("Description"),
|
||||||
"label_attr" => ['for' => 'description']
|
"label_attr" => ['for' => 'description'],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,4 +49,14 @@ class StepCreateForm extends BaseForm
|
|||||||
{
|
{
|
||||||
return "recette-step-create";
|
return "recette-step-create";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function trans($id, $parameters = [])
|
||||||
|
{
|
||||||
|
if (null === $this->translator) {
|
||||||
|
$this->translator = Translator::getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->translator->trans($id, $parameters, Recettes::MESSAGE_DOMAIN);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,4 +26,6 @@ return array(
|
|||||||
'Created on' => 'Rédigée le',
|
'Created on' => 'Rédigée le',
|
||||||
'Save recipe' => 'Sauvegarder la recette',
|
'Save recipe' => 'Sauvegarder la recette',
|
||||||
'Create a new step' => 'Ajouter une étape à votre recette',
|
'Create a new step' => 'Ajouter une étape à votre recette',
|
||||||
|
'No need to step number' => 'Inutile de saisir le numéro de l\'étape dans la description ci-dessus : il sera automatiquement rajouté !',
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
<th colspan="2">{intl l="Detail" d="recettes"}</th>
|
<th colspan="2">{intl l="Detail" d="recettes"}</th>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{assign var="last_step" value="0"}
|
|
||||||
{loop name="steps-loop" type="recipe_steps" recipe_id=$recipe_id}
|
{loop name="steps-loop" type="recipe_steps" recipe_id=$recipe_id}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
@@ -15,12 +14,11 @@
|
|||||||
{if $LOOP_COUNT < $LOOP_TOTAL}
|
{if $LOOP_COUNT < $LOOP_TOTAL}
|
||||||
<a href="{url path='/admin/module/Recettes/update-position?mode=down&step=%step' step=$STEP}" class="u-position-down"><i class="glyphicon glyphicon-arrow-down"></i></a>
|
<a href="{url path='/admin/module/Recettes/update-position?mode=down&step=%step' step=$STEP}" class="u-position-down"><i class="glyphicon glyphicon-arrow-down"></i></a>
|
||||||
{/if}</td>
|
{/if}</td>
|
||||||
<td>{$DESCRIPTION}</td>
|
<td>{$DESCRIPTION|unescape:"html" nofilter}</td>
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
<a href="{url path='/admin/module/Recettes/remove-step/%recipeId/%step/%contentId' recipeId=$recipe_id step=$STEP contentId=$content_id}" class="delete-step"><i class="glyphicon glyphicon-trash"></i></a>
|
<a href="{url path='/admin/module/Recettes/remove-step/%recipeId/%step/%contentId' recipeId=$recipe_id step=$STEP contentId=$content_id}" class="delete-step"><i class="glyphicon glyphicon-trash"></i></a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{if $LOOP_COUNT=$LOOP_TOTAL}{assign var="last_step" value="$STEP"}{/if}
|
|
||||||
{/loop}
|
{/loop}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
@@ -30,22 +28,3 @@
|
|||||||
data-target="#add-step-modal" data-toggle="modal">
|
data-target="#add-step-modal" data-toggle="modal">
|
||||||
<i class="glyphicon glyphicon-plus-sign"></i>
|
<i class="glyphicon glyphicon-plus-sign"></i>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
{form name="recette-step-create"}
|
|
||||||
{capture "step_create"}
|
|
||||||
{include file="modal/step-edit.html" form_name="recette-step-create" next_step=($last_step+1)}
|
|
||||||
{/capture}
|
|
||||||
|
|
||||||
{include file="includes/generic-create-dialog.html"
|
|
||||||
|
|
||||||
dialog_id = "add-step-modal"
|
|
||||||
dialog_title = {intl l="Create a new step" d="recettes"}
|
|
||||||
dialog_body = {$smarty.capture.step_create nofilter}
|
|
||||||
|
|
||||||
dialog_ok_label = {intl l="Create"}
|
|
||||||
dialog_cancel_label = {intl l="Cancel"}
|
|
||||||
|
|
||||||
form_action = {$current_url}
|
|
||||||
form_enctype = {form_enctype form=$form}
|
|
||||||
}
|
|
||||||
{/form}
|
|
||||||
@@ -2,12 +2,19 @@
|
|||||||
|
|
||||||
{form_hidden_fields form=$form}
|
{form_hidden_fields form=$form}
|
||||||
|
|
||||||
{render_form_field form=$form field="success_url" value={$success_url|default:{url path="/admin/content/update/$contentId?current_tab=recipe"}}}
|
{render_form_field form=$form field="success_url" value={url path="/admin/content/update/$content_id?current_tab=recipe"}}
|
||||||
|
{render_form_field form=$form field="error_url" value={url path="/admin/content/update/$content_id?current_tab=recipe"}}
|
||||||
|
|
||||||
|
{form_field form=$form field="recipe_id"}
|
||||||
|
<div class="form-group hidden">
|
||||||
|
<input type="hidden" class="form-control" name="{$name}" id="{$label_attr.for}" value="{$recipe_id}">
|
||||||
|
</div>
|
||||||
|
{/form_field}
|
||||||
|
|
||||||
{form_field form=$form field="step"}
|
{form_field form=$form field="step"}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="control-label" for="{$label_attr.for}">{intl l=$label d="recettes"}</label>
|
<label class="control-label" for="{$label_attr.for}">{intl l=$label d="recettes"}</label>
|
||||||
<input type="text" class="etroit" name="{$name}" id="{$label_attr.for}" value="{$next_step}" disabled />
|
<input type="text" class="form-control etroit" name="{$name}" id="{$label_attr.for}" value="{$next_step}" readonly />
|
||||||
</div>
|
</div>
|
||||||
{/form_field}
|
{/form_field}
|
||||||
|
|
||||||
@@ -17,9 +24,9 @@
|
|||||||
{intl l=$label d="recettes"}
|
{intl l=$label d="recettes"}
|
||||||
{if $required}<span class="required">*</span>{/if}
|
{if $required}<span class="required">*</span>{/if}
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
{form_error form=$form field="description"}{$message}{/form_error}
|
{form_error form=$form field="description"}{$message}{/form_error}
|
||||||
<textarea id="attr-description" name="{$name}" rows="10" class="form-control wysiwyg">{$DESCRIPTION}</textarea>
|
<textarea id="{$name}" name="{$name}" rows="10" class="form-control wysiwyg">{$DESCRIPTION}</textarea>
|
||||||
|
<span class="help-block">{intl l="No need to step number" d="recettes"}</span>
|
||||||
</div>
|
</div>
|
||||||
{/form_field}
|
{/form_field}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,12 @@
|
|||||||
{assign var="other_ingredients" value=$OTHER_INGREDIENTS}
|
{assign var="other_ingredients" value=$OTHER_INGREDIENTS}
|
||||||
{/loop}
|
{/loop}
|
||||||
|
|
||||||
|
{assign var="last_step" value="0"}
|
||||||
|
{loop name="steps-loop" type="recipe_steps" recipe_id=$recipe_id}
|
||||||
|
{if $LOOP_COUNT=$LOOP_TOTAL}{assign var="last_step" value="$STEP"}{/if}
|
||||||
|
{/loop}
|
||||||
|
|
||||||
|
|
||||||
<div class="form-container">
|
<div class="form-container">
|
||||||
{form name="recette_create_form"}
|
{form name="recette_create_form"}
|
||||||
<form id="admin-comment-form" method="post" action="{url path='/admin/module/Recettes/save'}" {form_enctype form=$form} class="clearfix">
|
<form id="admin-comment-form" method="post" action="{url path='/admin/module/Recettes/save'}" {form_enctype form=$form} class="clearfix">
|
||||||
@@ -130,3 +136,20 @@
|
|||||||
</form>
|
</form>
|
||||||
{/form}
|
{/form}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{* CREATE Modal *}
|
||||||
|
{form name="recette-step-create"}
|
||||||
|
{capture "step_create"}
|
||||||
|
{include file="modal/step-edit.html" form_name="recette-step-create" next_step=($last_step+1) recipe_id=$recipe_id content_id=$content_id}
|
||||||
|
{/capture}
|
||||||
|
|
||||||
|
{include file="includes/generic-create-dialog.html"
|
||||||
|
dialog_id = "add-step-modal"
|
||||||
|
dialog_title = {intl l="Create a new step" d="recettes"}
|
||||||
|
dialog_body = {$smarty.capture.step_create nofilter}
|
||||||
|
dialog_ok_label = {intl l="Create"}
|
||||||
|
dialog_cancel_label = {intl l="Cancel"}
|
||||||
|
form_action = {url path="/admin/module/Recettes/add-step"}
|
||||||
|
form_enctype = {form_enctype form=$form}
|
||||||
|
}
|
||||||
|
{/form}
|
||||||
@@ -348,3 +348,6 @@ span.product-categorie {
|
|||||||
line-height: 1rem !important;
|
line-height: 1rem !important;
|
||||||
height: 1.5rem;
|
height: 1.5rem;
|
||||||
}
|
}
|
||||||
|
.autres-ingredients {
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
@@ -99,7 +99,7 @@
|
|||||||
{loop type="recipe_steps" name="steps-loop" recipe_id=$ID}
|
{loop type="recipe_steps" name="steps-loop" recipe_id=$ID}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="number">{$STEP}</td>
|
<td class="number">{$STEP}</td>
|
||||||
<td class="description">{$DESCRIPTION}</td>
|
<td class="description">{$DESCRIPTION|unescape:"html" nofilter}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{/loop}
|
{/loop}
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
Reference in New Issue
Block a user