diff --git a/local/modules/Recettes/Config/config.xml b/local/modules/Recettes/Config/config.xml
index 8afb75e5..e307a711 100644
--- a/local/modules/Recettes/Config/config.xml
+++ b/local/modules/Recettes/Config/config.xml
@@ -6,13 +6,22 @@
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/local/modules/Recettes/Config/routing.xml b/local/modules/Recettes/Config/routing.xml
index 4eb183ba..8472776c 100644
--- a/local/modules/Recettes/Config/routing.xml
+++ b/local/modules/Recettes/Config/routing.xml
@@ -8,5 +8,4 @@
Recettes\Controller\MainController::saveRecipe
-
diff --git a/local/modules/Recettes/Config/schema.xml b/local/modules/Recettes/Config/schema.xml
new file mode 100644
index 00000000..0601b34a
--- /dev/null
+++ b/local/modules/Recettes/Config/schema.xml
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/local/modules/Recettes/Config/sqldb.map b/local/modules/Recettes/Config/sqldb.map
new file mode 100644
index 00000000..63a93baa
--- /dev/null
+++ b/local/modules/Recettes/Config/sqldb.map
@@ -0,0 +1,2 @@
+# Sqlfile -> Database map
+thelia.sql=thelia
diff --git a/local/modules/Recettes/Config/thelia.sql b/local/modules/Recettes/Config/thelia.sql
new file mode 100644
index 00000000..7d3ca2e3
--- /dev/null
+++ b/local/modules/Recettes/Config/thelia.sql
@@ -0,0 +1,67 @@
+
+# This is a fix for InnoDB in MySQL >= 4.1.x
+# It "suspends judgement" for fkey relationships until are tables are set.
+SET FOREIGN_KEY_CHECKS = 0;
+
+-- ---------------------------------------------------------------------
+-- recipe
+-- ---------------------------------------------------------------------
+
+DROP TABLE IF EXISTS `recipe`;
+
+CREATE TABLE `recipe`
+(
+ `id` INTEGER NOT NULL AUTO_INCREMENT,
+ `content_id` INTEGER,
+ `title` VARCHAR(255) NOT NULL,
+ `people` INTEGER NOT NULL,
+ `difficulty` INTEGER NOT NULL,
+ `preparation_time` VARCHAR(255) NOT NULL,
+ `cooking_time` VARCHAR(255),
+ PRIMARY KEY (`id`),
+ INDEX `fi_content_content_id` (`content_id`),
+ CONSTRAINT `fk_content_content_id`
+ FOREIGN KEY (`content_id`)
+ REFERENCES `content` (`id`)
+) ENGINE=InnoDB;
+
+-- ---------------------------------------------------------------------
+-- recipe_steps
+-- ---------------------------------------------------------------------
+
+DROP TABLE IF EXISTS `recipe_steps`;
+
+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`),
+ CONSTRAINT `fk_recipesteps_recipe_id`
+ FOREIGN KEY (`recipe_id`)
+ REFERENCES `recipe` (`id`)
+) ENGINE=InnoDB;
+
+-- ---------------------------------------------------------------------
+-- recipe_products
+-- ---------------------------------------------------------------------
+
+DROP TABLE IF EXISTS `recipe_products`;
+
+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`),
+ INDEX `fi_recipeproducts_pse_id` (`pse_id`),
+ CONSTRAINT `fk_recipeproducts_recipe_id`
+ FOREIGN KEY (`recipe_id`)
+ REFERENCES `recipe` (`id`),
+ CONSTRAINT `fk_recipeproducts_pse_id`
+ FOREIGN KEY (`pse_id`)
+ REFERENCES `product_sale_elements` (`id`)
+) ENGINE=InnoDB;
+
+# This restores the fkey checks, after having unset them earlier
+SET FOREIGN_KEY_CHECKS = 1;
diff --git a/local/modules/Recettes/Controller/MainController.php b/local/modules/Recettes/Controller/MainController.php
index f54c037f..d1ebc2ce 100755
--- a/local/modules/Recettes/Controller/MainController.php
+++ b/local/modules/Recettes/Controller/MainController.php
@@ -6,6 +6,11 @@ use Exception;
use Propel\Runtime\Exception\PropelException;
use Propel\Runtime\Propel;
use Recettes\Form\RecetteCreateForm;
+use Recettes\Model\Recipe;
+use Recettes\Model\RecipeProducts;
+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;
@@ -22,26 +27,18 @@ use Thelia\Tools\URL;
class MainController extends BaseAdminController
{
- public function viewAction(Request $request)
+ public function saveRecipe(Request $request)
{
- $id = $request->get("content_id");
-
- }
-
-
- public function saveRecipe(Request $request)
- {
- $productsList = [];
-
- $con = Propel::getConnection();
$error = "";
+ $con = Propel::getConnection();
+ $nouvelleRecette = false;
$form = new RecetteCreateForm($request);
try {
$formValidate = $this->validateForm($form);
$data = $formValidate->getData();
- $content_id = $data['content_id'];
+ $contentId = $data['content_id'];
$title = $data['title'];
$difficulty = $data['difficulty'];
$numberPeople = $data['people'];
@@ -49,19 +46,52 @@ class MainController extends BaseAdminController
$cookingTime = $data['cooking_time'];
$steps = $data['steps'];
- if (null !== $title && null !== $preparationTime) {
- $content = ContentI18nQuery::create()->filterByLocale('fr_FR')->findOneById($content_id);
+ if (null !== $title && null !== $contentId && null !== $difficulty && null !== $numberPeople && null !== $preparationTime) {
- $encodedData = json_encode($data);
- $content->setDescription($encodedData);
- $content->save($con);
+ $recipe = RecipeQuery::create()->findOneByContentId($contentId);
+ if (null === $recipe)
+ {
+ $nouvelleRecette = true;
+ $recipe = new Recipe();
+ }
+ else
+ $recipeId = $recipe->getId();
+
+ $recipe->setContentId($contentId);
+ $recipe->setTitle($title);
+ $recipe->setDifficulty($difficulty);
+ $recipe->setPeople($numberPeople);
+ $recipe->setPreparationTime($preparationTime);
+ $recipe->setCookingTime($cookingTime);
+ $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));
+ }
} catch (\Exception $e) {
$error = $e->getMessage();
}
- return new RedirectResponse(URL::getInstance()->absoluteUrl("/admin/content/update/" . $content_id));
+ return new RedirectResponse(URL::getInstance()->absoluteUrl("/admin/content"));
}
}
diff --git a/local/modules/Recettes/Form/RecetteCreateForm.php b/local/modules/Recettes/Form/RecetteCreateForm.php
index beaa82a4..210d896e 100644
--- a/local/modules/Recettes/Form/RecetteCreateForm.php
+++ b/local/modules/Recettes/Form/RecetteCreateForm.php
@@ -3,7 +3,12 @@
namespace Recettes\Form;
use Recettes\Recettes;
+use Symfony\Component\Validator\Constraints\AbstractComparison;
+use Symfony\Component\Validator\Constraints\GreaterThan;
+use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
+use Symfony\Component\Validator\Constraints\LessThanOrEqual;
use Symfony\Component\Validator\Constraints\NotBlank;
+use Symfony\Component\Validator\Constraints\Range;
use Thelia\Core\Translation\Translator;
use Thelia\Form\BaseForm;
@@ -33,10 +38,7 @@ class RecetteCreateForm extends BaseForm
"content_id",
"integer",
[
- "label" => $this->trans("Content Id"),
- "constraints" => [
- new NotBlank()
- ]
+ "constraints" => [ new NotBlank() ]
]
)
->add(
@@ -45,29 +47,25 @@ class RecetteCreateForm extends BaseForm
[
"label" => $this->trans("Title"),
"label_attr" => [
- "for" => "attr-title"
+ "for" => "title"
],
- "constraints" => [
- new NotBlank()
- ]
+ "constraints" => [ new NotBlank() ],
+ "required" => true
]
)
->add(
"difficulty",
- "choice",
+ "integer",
[
- "choices" => array(
- "Facile",
- "Moyen",
- "Difficile"
- ),
"label" => $this->trans("Difficulty"),
"label_attr" => [
- "for" => "attr-difficulty"
+ "for" => "difficulty"
],
"constraints" => [
- new NotBlank()
- ]
+ new GreaterThanOrEqual(array('value' => 0)),
+ new LessThanOrEqual(array('value' => 2))
+ ],
+ "required" => true
]
)
->add(
@@ -76,11 +74,10 @@ class RecetteCreateForm extends BaseForm
[
"label" => $this->trans("Number of people"),
"label_attr" => [
- "for" => "attr-difficulty"
+ "for" => "people"
],
- "constraints" => [
- new NotBlank()
- ]
+ "constraints" => [ new GreaterThan(array('value' => 0)) ],
+ "required" => true
]
)
->add(
@@ -89,12 +86,11 @@ class RecetteCreateForm extends BaseForm
[
"label" => $this->trans("Preparation time"),
"label_attr" => [
- "for" => "attr-preparation-time",
+ "for" => "preparation_time",
"help" => "ex : 1h15 ou 45 minutes"
],
- "constraints" => [
- new NotBlank()
- ]
+ "constraints" => [ new NotBlank() ],
+ "required" => true
]
)
->add(
@@ -103,7 +99,7 @@ class RecetteCreateForm extends BaseForm
[
"label" => $this->trans("Cooking time"),
"label_attr" => [
- "for" => "attr-cooking-time",
+ "for" => "cooking_time",
"help" => "ex : 1h15 ou 45 minutes"
],
"required" => false
@@ -115,10 +111,7 @@ class RecetteCreateForm extends BaseForm
[
"label" => $this->trans("Steps"),
"label_attr" => [
- "for" => "attr-recipe"
- ],
- "constraints" => [
- new NotBlank()
+ "for" => "steps"
]
]
);
diff --git a/local/modules/Recettes/Form/RecetteUpdateForm.php b/local/modules/Recettes/Form/RecetteUpdateForm.php
deleted file mode 100644
index 6de68bb6..00000000
--- a/local/modules/Recettes/Form/RecetteUpdateForm.php
+++ /dev/null
@@ -1,30 +0,0 @@
-getArgument('id');
$parentFolderId = ContentFolderQuery::create()->findOneByContentId($contentId)->getFolderId();
$parentFolder = FolderI18nQuery::create()->findOneById($parentFolderId)->getTitle();
- if (0 != strpos($parentFolder, 'recette')) {
+ if (0 != strpos($parentFolder, Recettes::MOT_CLE_RECETTE)) {
+
$event->add(
[
- "id" => 'admin-content-recipe',
+ "id" => 'recipe',
"title" => 'Recette',
- "content" => ($this->render('recette-tab.html',
- [ "people" => "2" ]
- ))
+ "content" => ($this->render('recette-tab.html'))
]
);
}
}
+ public function onAddCss(HookRenderEvent $event)
+ {
+ $event->add($this->addCSS('assets/css/Recettes.css'));
+ }
+
}
\ No newline at end of file
diff --git a/local/modules/Recettes/I18n/fr_FR.php b/local/modules/Recettes/I18n/fr_FR.php
index d95dc47e..deee86c3 100644
--- a/local/modules/Recettes/I18n/fr_FR.php
+++ b/local/modules/Recettes/I18n/fr_FR.php
@@ -8,4 +8,7 @@ return array(
'Number of people' => 'Nombre de personnes',
'Product' => 'Produit',
'Quantity' => 'Quantité',
+ 'Preparation time' => 'Préparation ',
+ 'Cooking time' => 'Cuisson ',
+ 'Difficulty' => 'Niveau ',
);
diff --git a/local/modules/Recettes/Loop/GeneralLoop.php b/local/modules/Recettes/Loop/GeneralLoop.php
new file mode 100644
index 00000000..4c47cf0b
--- /dev/null
+++ b/local/modules/Recettes/Loop/GeneralLoop.php
@@ -0,0 +1,76 @@
+getResultDataCollection() as $recipe) {
+
+ $loopResultRow = new LoopResultRow($recipe);
+ $loopResultRow
+ ->set("ID", $recipe->getId())
+ ->set("CONTENT_ID", $recipe->getContentId())
+ ->set("TITLE", $recipe->getTitle())
+ ->set("PEOPLE", $recipe->getPeople())
+ ->set("DIFFICULTY", $recipe->getDifficulty())
+ ->set("PREPARATION_TIME", $recipe->getPreparationTime())
+ ->set("COOKING_TIME", $recipe->getCookingTime())
+ ;
+ $loopResult->addRow($loopResultRow);
+ }
+ return $loopResult;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ protected function getArgDefinitions()
+ {
+ return new ArgumentCollection(
+ Argument::createIntListTypeArgument('id'),
+ Argument::createIntListTypeArgument('content_id')
+ );
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function buildModelCriteria()
+ {
+ $recipes = RecipeQuery::create();
+
+ /* Filtrages éventuels */
+ if (null != $id = $this->getId()) {
+ $recipes->filterById($id);
+ }
+ if (null != $contentId = $this->getContentId()) {
+ $recipes->filterByContentId($contentId);
+ }
+
+ return $recipes;
+ }
+
+}
diff --git a/local/modules/Recettes/Loop/ProductsLoop.php b/local/modules/Recettes/Loop/ProductsLoop.php
new file mode 100644
index 00000000..5864b05f
--- /dev/null
+++ b/local/modules/Recettes/Loop/ProductsLoop.php
@@ -0,0 +1,67 @@
+getResultDataCollection() as $product) {
+
+ $loopResultRow = new LoopResultRow($product);
+ $loopResultRow
+ ->set("RECIPE_ID", $product->getId())
+ ->set("PSE_ID", $product->getPseId())
+ ->set("QUANTITY", $product->getQuantity())
+ ;
+ $loopResult->addRow($loopResultRow);
+ }
+ return $loopResult;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ protected function getArgDefinitions()
+ {
+ return new ArgumentCollection(
+ Argument::createIntListTypeArgument('recipe_id')
+ );
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function buildModelCriteria()
+ {
+ $products = RecipeProductsQuery::create();
+
+ if (null != $id = $this->getRecipeId()) {
+ $products->filterById($id);
+ }
+
+ return $products;
+ }
+
+}
diff --git a/local/modules/Recettes/Loop/StepsLoop.php b/local/modules/Recettes/Loop/StepsLoop.php
new file mode 100644
index 00000000..eb908c57
--- /dev/null
+++ b/local/modules/Recettes/Loop/StepsLoop.php
@@ -0,0 +1,67 @@
+getResultDataCollection() as $step) {
+
+ $loopResultRow = new LoopResultRow($step);
+ $loopResultRow
+ ->set("RECIPE_ID", $step->getId())
+ ->set("STEP", $step->getContentId())
+ ->set("DESCRIPTION", $step->getTitle())
+ ;
+ $loopResult->addRow($loopResultRow);
+ }
+ return $loopResult;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ protected function getArgDefinitions()
+ {
+ return new ArgumentCollection(
+ Argument::createIntListTypeArgument('recipe_id')
+ );
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function buildModelCriteria()
+ {
+ $steps = RecipeStepsQuery::create();
+
+ if (null != $id = $this->getRecipeId()) {
+ $steps->filterById($id);
+ }
+
+ return $steps;
+ }
+
+}
diff --git a/local/modules/Recettes/Model/Recipe.php b/local/modules/Recettes/Model/Recipe.php
new file mode 100644
index 00000000..84545ea9
--- /dev/null
+++ b/local/modules/Recettes/Model/Recipe.php
@@ -0,0 +1,20 @@
+getWrappedConnection());
+ $database->insertSql(null, array(__DIR__ . '/Config/thelia.sql'));
+ }
}
diff --git a/local/modules/Recettes/templates/backOffice/default/recette-tab.html b/local/modules/Recettes/templates/backOffice/default/recette-tab.html
index 6e6c63fa..70017b74 100644
--- a/local/modules/Recettes/templates/backOffice/default/recette-tab.html
+++ b/local/modules/Recettes/templates/backOffice/default/recette-tab.html
@@ -1,3 +1,11 @@
+{loop type="recipe" name="recipe-loop" content_id=$content_id limit="1"}
+ {assign var="title" value=$TITLE}
+ {assign var="people" value=$PEOPLE}
+ {assign var="difficulty" value=$DIFFICULTY}
+ {assign var="preparation_time" value=$PREPARATION_TIME}
+ {assign var="cooking_time" value=$COOKING_TIME}
+{/loop}
+
{form_error form=$form field="preparation_time"}{$message}{/form_error}
@@ -71,7 +78,7 @@
-  
+  
{$label_attr.help}
{form_error form=$form field="cooking_time"}{$message}{/form_error}
@@ -83,7 +90,7 @@
{intl l=$label d='recettes'}
{if $required}*{/if}
-
+
{form_error form=$form field="steps"}{$message}{/form_error}
{/form_field}
@@ -99,7 +106,6 @@
-
diff --git a/local/modules/Recettes/templates/frontOffice/default/assets/css/Recettes.css b/local/modules/Recettes/templates/frontOffice/default/assets/css/Recettes.css
new file mode 100644
index 00000000..a4c58573
--- /dev/null
+++ b/local/modules/Recettes/templates/frontOffice/default/assets/css/Recettes.css
@@ -0,0 +1,27 @@
+article#recette {
+ width: 90% !important;
+ text-align: center;
+ display: flex;
+ flex-direction: column;
+}
+
+div.entete {
+ background-color: #95c11e;
+ color: white;
+ width: auto;
+ padding: 10px 0;
+ border-radius: 8px;
+}
+
+div.entete img {
+ width: 30px;
+ padding-right: 10px;
+}
+div.entete span {
+ margin-right: 40px;
+ padding: 10px 10px;
+ color: white;
+}
+div.entete span b {
+ color: #0e0e0e;
+}
diff --git a/local/modules/Recettes/templates/frontOffice/default/assets/img/cellular.svg b/local/modules/Recettes/templates/frontOffice/default/assets/img/cellular.svg
new file mode 100644
index 00000000..96f9cdf6
--- /dev/null
+++ b/local/modules/Recettes/templates/frontOffice/default/assets/img/cellular.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/local/modules/Recettes/templates/frontOffice/default/assets/img/thermometer.svg b/local/modules/Recettes/templates/frontOffice/default/assets/img/thermometer.svg
new file mode 100644
index 00000000..69e1dce8
--- /dev/null
+++ b/local/modules/Recettes/templates/frontOffice/default/assets/img/thermometer.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/local/modules/Recettes/templates/frontOffice/default/assets/img/timer.svg b/local/modules/Recettes/templates/frontOffice/default/assets/img/timer.svg
new file mode 100644
index 00000000..f33e288a
--- /dev/null
+++ b/local/modules/Recettes/templates/frontOffice/default/assets/img/timer.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/templates/frontOffice/custom/recette.html b/templates/frontOffice/custom/recette.html
new file mode 100644
index 00000000..0925c7c6
--- /dev/null
+++ b/templates/frontOffice/custom/recette.html
@@ -0,0 +1,59 @@
+{extends file="layout.tpl"}
+
+{block name='init'}
+ {assign var="content_id" value={content attr="id"}}
+{/block}
+
+{* Body Class *}
+{block name="body-class"}page-content{/block}
+
+{* Page Title *}
+{block name='no-return-functions' append}
+ {if {$content_id}}
+ {$page_title = $TITLE}
+ {/if}
+{/block}
+
+{* Breadcrumb *}
+{block name='no-return-functions' append}
+ {if $content_id}
+ {$breadcrumbs = []}
+ {loop type="content" name="content-breadcrumb" id=$content_id limit="1"}
+ {loop name="folder_path" type="folder-path" folder={$DEFAULT_FOLDER}}
+ {$breadcrumbs[] = ['title' => {$TITLE}, 'url'=> {$URL nofilter}]}
+ {/loop}
+ {$breadcrumbs[] = ['title' => {$TITLE}, 'url'=> {$URL nofilter}]}
+ {/loop}
+ {/if}
+{/block}
+
+{block name="main-content"}
+{if $content_id}
+
+
+
+ {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}
+
+
+ {$TITLE}
+
+
{intl l='Preparation time' d='recettes'}
{$PREPARATION_TIME}
+
{intl l='Cooking time' d='recettes'}
{$COOKING_TIME}
+
{intl l='Difficulty' d='recettes'}
{$label_difficulty}
+
+
+
+ {/loop}
+
+
+
+
+{/if}
+{/block}
+
+{block name="stylesheet"}
+{hook name="content.stylesheet"}
+{/block}