Module Recettes : on avance... un peu...

This commit is contained in:
2021-04-29 19:05:43 +02:00
parent 8ccce53560
commit 30a5848cf9
12 changed files with 105 additions and 36 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 232 KiB

View File

@@ -4,10 +4,12 @@
<column name="id" autoIncrement="true" primaryKey="true" required="true" type="INTEGER" />
<column name="content_id" type="INTEGER" />
<column name="title" required="true" type="VARCHAR" />
<column name="summary" required="false" type="VARCHAR" />
<column name="people" required="true" type="INTEGER" />
<column name="difficulty" required="true" type="INTEGER" />
<column name="preparation_time" required="true" type="VARCHAR" />
<column name="cooking_time" required="false" type="VARCHAR" />
<column name="other_ingredients" required="false" type="VARCHAR" />
<foreign-key foreignTable="content" name="fk_content_content_id">
<reference foreign="id" local="content_id" />
@@ -15,8 +17,8 @@
</table>
<table name="recipe_steps">
<column name="recipe_id" required="true" type="INTEGER" />
<column name="step" required="true" type="INTEGER" />
<column name="recipe_id" required="true" primaryKey="true" type="INTEGER" />
<column name="step" required="true" primaryKey="true" type="INTEGER" />
<column name="description" required="true" type="VARCHAR" />
<foreign-key foreignTable="recipe" name="fk_recipesteps_recipe_id">
@@ -25,9 +27,10 @@
</table>
<table name="recipe_products">
<column name="recipe_id" required="true" type="INTEGER" />
<column name="pse_id" required="true" type="INTEGER" />
<column name="quantity" required="true" type="INTEGER" />
<column name="recipe_id" required="true" primaryKey="true" type="INTEGER" />
<column name="pse_id" required="true" primaryKey="true" type="INTEGER" />
<column name="nb_of_products" required="true" type="INTEGER" />
<column name="quantity" required="true" type="VARCHAR" />
<foreign-key foreignTable="recipe" name="fk_recipeproducts_recipe_id">
<reference foreign="id" local="recipe_id" />

View File

@@ -14,10 +14,12 @@ CREATE TABLE `recipe`
`id` INTEGER NOT NULL AUTO_INCREMENT,
`content_id` INTEGER,
`title` VARCHAR(255) NOT NULL,
`summary` VARCHAR(255),
`people` INTEGER NOT NULL,
`difficulty` INTEGER NOT NULL,
`preparation_time` VARCHAR(255) NOT NULL,
`cooking_time` VARCHAR(255),
`other_ingredients` VARCHAR(255),
PRIMARY KEY (`id`),
INDEX `fi_content_content_id` (`content_id`),
CONSTRAINT `fk_content_content_id`
@@ -36,7 +38,7 @@ CREATE TABLE `recipe_steps`
`recipe_id` INTEGER NOT NULL,
`step` INTEGER NOT NULL,
`description` VARCHAR(255) NOT NULL,
INDEX `fi_recipesteps_recipe_id` (`recipe_id`),
PRIMARY KEY (`recipe_id`,`step`),
CONSTRAINT `fk_recipesteps_recipe_id`
FOREIGN KEY (`recipe_id`)
REFERENCES `recipe` (`id`)
@@ -52,8 +54,9 @@ CREATE TABLE `recipe_products`
(
`recipe_id` INTEGER NOT NULL,
`pse_id` INTEGER NOT NULL,
`quantity` INTEGER NOT NULL,
INDEX `fi_recipeproducts_recipe_id` (`recipe_id`),
`nb_of_products` INTEGER NOT NULL,
`quantity` VARCHAR(255) NOT NULL,
PRIMARY KEY (`recipe_id`,`pse_id`),
INDEX `fi_recipeproducts_pse_id` (`pse_id`),
CONSTRAINT `fk_recipeproducts_recipe_id`
FOREIGN KEY (`recipe_id`)

View File

@@ -40,11 +40,13 @@ class MainController extends BaseAdminController
$contentId = $data['content_id'];
$title = $data['title'];
$summary = $data['summary'];
$difficulty = $data['difficulty'];
$numberPeople = $data['people'];
$preparationTime = $data['preparation_time'];
$cookingTime = $data['cooking_time'];
$steps = $data['steps'];
$otherIngredients = $data['other_ingredients'];
// $steps = $data['steps'];
if (null !== $title && null !== $contentId && null !== $difficulty && null !== $numberPeople && null !== $preparationTime) {
@@ -58,20 +60,22 @@ class MainController extends BaseAdminController
$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();
// $steps = RecipeStepsQuery::create()->findByRecipeId($recipeId);
// $steps->delete($con);
// $con->commit();
}
/*
foreach ($steps as $step) {

View File

@@ -53,6 +53,17 @@ class RecetteCreateForm extends BaseForm
"required" => true
]
)
->add(
"summary",
"textarea",
[
"label" => $this->trans("Summary"),
"label_attr" => [
"for" => "summary"
],
"required" => false
]
)
->add(
"difficulty",
"integer",
@@ -106,13 +117,15 @@ class RecetteCreateForm extends BaseForm
]
)
->add(
"steps",
"other_ingredients",
"textarea",
[
"label" => $this->trans("Steps"),
"label" => $this->trans("Other ingredients"),
"label_attr" => [
"for" => "steps"
"for" => "other_ingredients"
]
,
"required" => false
]
);
}

View File

@@ -28,7 +28,7 @@ class HookManager extends baseHook
[
"id" => 'recipe',
"title" => 'Recette',
"content" => ($this->render('recette-tab.html'))
"content" => ($this->render('recette-tab.html'))
]
);
}

View File

@@ -5,10 +5,9 @@ return array(
'Preparation time' => 'Temps de préparation',
'Cooking time' => 'Temps de cuisson',
'Difficulty' => 'Difficulté',
'Number of people' => 'Nombre de personnes',
'Number of people' => 'Nombre de couverts',
'Product' => 'Produit',
'Quantity' => 'Quantité',
'Preparation time' => 'Préparation ',
'Cooking time' => 'Cuisson ',
'Difficulty' => 'Niveau ',
'Summary' => 'Description de la recette',
'Other ingredients' => 'Ingrédients supplémentaires',
);

View File

@@ -34,10 +34,12 @@ class GeneralLoop extends BaseLoop implements PropelSearchLoopInterface
->set("ID", $recipe->getId())
->set("CONTENT_ID", $recipe->getContentId())
->set("TITLE", $recipe->getTitle())
->set("SUMMARY", $recipe->getSummary())
->set("PEOPLE", $recipe->getPeople())
->set("DIFFICULTY", $recipe->getDifficulty())
->set("PREPARATION_TIME", $recipe->getPreparationTime())
->set("COOKING_TIME", $recipe->getCookingTime())
->set("OTHER_INGREDIENTS", $recipe->getOtherIngredients())
;
$loopResult->addRow($loopResultRow);
}

View File

@@ -9,6 +9,8 @@ use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Element\PropelSearchLoopInterface;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Model\ProductI18nQuery;
use Thelia\Model\ProductSaleElementsQuery;
/**
* Class ProductsLoop
@@ -29,10 +31,14 @@ class ProductsLoop extends BaseLoop implements PropelSearchLoopInterface
{
foreach ($loopResult->getResultDataCollection() as $product) {
$pse = ProductSaleElementsQuery::create()->findOneById($product->getPseId());
$productLabel = ProductI18nQuery::create()->findOneById($pse->getProductId())->getTitle();
$loopResultRow = new LoopResultRow($product);
$loopResultRow
->set("RECIPE_ID", $product->getId())
->set("RECIPE_ID", $product->getRecipeId())
->set("PSE_ID", $product->getPseId())
->set("PRODUCT_LABEL", $productLabel)
->set("QUANTITY", $product->getQuantity())
;
$loopResult->addRow($loopResultRow);
@@ -57,8 +63,8 @@ class ProductsLoop extends BaseLoop implements PropelSearchLoopInterface
{
$products = RecipeProductsQuery::create();
if (null != $id = $this->getRecipeId()) {
$products->filterById($id);
if (null != $recipeId = $this->getRecipeId()) {
$products->filterByRecipeId($recipeId);
}
return $products;

View File

@@ -1,9 +1,11 @@
{loop type="recipe" name="recipe-loop" content_id=$content_id limit="1"}
{assign var="title" value=$TITLE}
{assign var="summary" value=$SUMMARY}
{assign var="people" value=$PEOPLE}
{assign var="difficulty" value=$DIFFICULTY}
{assign var="preparation_time" value=$PREPARATION_TIME}
{assign var="cooking_time" value=$COOKING_TIME}
{assign var="other_ingredients" value=$OTHER_INGREDIENTS}
{/loop}
<div id="wrapper" class="container">
@@ -31,6 +33,16 @@
{form_error form=$form field="title"}{$message}{/form_error}
{/form_field}
{form_field form=$form field="summary"}
<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="summary" name="{$name}" rows="10" class="form-control wysiwyg">{$summary}</textarea>
</div>
{form_error form=$form field="summary"}{$message}{/form_error}
{/form_field}
{form_field form=$form field="difficulty"}
<div class="form-group form-inline">
@@ -77,22 +89,24 @@
<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" name="{$name}" value="{$cooking_time}" />&nbsp
<input type="text" id="{$label_attr.for}" class="form-control" name="{$name}" value="{$cooking_time}" {if $required}required{/if} />&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"}
{form_field form=$form field="other_ingredients"}
<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>
{if $required}<span class="required">*</span>{/if}
<textarea id="attr-recipe" name="{$name}" rows="10" class="form-control wysiwyg">{$steps}</textarea>
<textarea id="attr-recipe" name="{$name}" rows="10" class="form-control wysiwyg">{$other_ingredients}</textarea>
</div>
{form_error form=$form field="steps"}{$message}{/form_error}
{form_error form=$form field="other_ingredients"}{$message}{/form_error}
{/form_field}
</div>

View File

@@ -4,6 +4,7 @@ article#recette {
display: flex;
flex-direction: column;
align-items: normal;
margin: auto;
}
div.entete {
@@ -28,3 +29,7 @@ div.entete span {
div.entete span b {
color: #0e0e0e;
}
.photo-principale img {
width: 250px;
box-shadow: 10px 10px 15px gray;
}

View File

@@ -29,31 +29,51 @@
{block name="main-content"}
{if $content_id}
<div class="main row">
<article id="recette" class="col-md-12" role="main">
<div class="container">
<article id="recette" role="main">
{loop type="recipe" name="recipe-loop" content_id=$content_id limit="1"}
{if $DIFFICULTY eq 0}{assign var="label_difficulty" value="Facile"}{/if}
{if $DIFFICULTY eq 1}{assign var="label_difficulty" value="Moyen"}{/if}
{if $DIFFICULTY eq 2}{assign var="label_difficulty" value="Difficile"}{/if}
<h1 class="titre-recette">{$TITLE}</h1>
<div class="entete col-md-12">
<div class="entete">
<span class="preparation"><b>{intl l='Preparation time' d='recettes'}</b><img src="{image file='assets/img/timer.svg' source='Recettes'}" alt="Preparation time">{$PREPARATION_TIME}</span>
<span class="cuisson"><b>{intl l='Cooking time' d='recettes'}</b><img src="{image file='assets/img/thermometer.svg' source='Recettes'}" alt="Cooking time">{$COOKING_TIME}</span>
<span class="difficulte"><b>{intl l='Difficulty' d='recettes'}</b><img src="{image file='assets/img/cellular.svg' source='Recettes'}" alt="Difficulty">{$label_difficulty}</span>
</div>
<br>
<div class="row">
<div class="col-md-6">
{loop type="image" name="image-loop" content=$content_id}
<img src="{$IMAGE_URL}">
<div class="photo-principale col-md-4">
{loop type="image" name="image-loop" content=$content_id visible=true}
<img src="{$IMAGE_URL}" alt="Photo principale">
{/loop}
</div>
<div class="col-md-6"></div>
<div class="col-md-8">
<h3>{intl l='Nos produits' d='recettes'}</h3>
<table class="products-needed">
<thead>
<th>{intl l="Ingredient" d="recettes"}</th>
<th>{intl l="Quantity needed" d="recettes"}</th>
<th>{intl l="Choose this product" d="recettes"}</th>
</thead>
<tbody>
{loop type="recipe_products" name="products-loop" recipe_id=$ID}
<tr>
<td class="cellule-produit">{$PRODUCT_LABEL}</td>
<td class="cellule-quantite">{$QUANTITY}</td>
<td><input type="checkbox" id="product-{$PSE_ID}" class="cellule-checkbox"></td>
</tr>
{/loop}
</tbody>
</table>
<br>
<h3>{intl l='Autres ingrédients' d='recettes'}</h3>
<label class="autres-ingredients">{$OTHER_INGREDIENTS}</label>
</div>
</div>
<br>
{/loop}