1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
<?php
$recetteTable = App::getInstance()->getTable('Recette');
if (!empty($_POST)) {
$result = $recetteTable->create([
'categories_id' => $_POST['categories_id'],
'recettes' => $_POST['recettes'],
'nbpersonnes' => $_POST['nbpersonnes'],
'marge' => $_POST['marge'],
'observations' => $_POST['observations']
]);
$recette_id = App::getInstance()->getDb()->lastInsertId();
$compositionTable = App::getInstance()->getTable('CompositionRecette');
$id_composition = [];
foreach ($_POST['ingredients_id'] as $key => $ingredient_id) {
$quantite = $_POST['quantite'][$key];
$compositionTable->create([
'recettes_id' => $recette_id,
'ingredients_id' => $ingredient_id,
'quantites' => $quantite
]);
$id_composition[] = App::getInstance()->getDb()->lastInsertId();
}
if ($recette_id && count($id_composition)) {
//redirection
}
}
$categories = App::getInstance()->getTable('Categorie')->extract('id', 'categories');
$ingredients = App::getInstance()->getTable('Ingredient')->extract('id', 'ingredients');
$form = new \Core\HTML\BootstrapForm($_POST);
?>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
Recettes
<small>Control Panel</small>
</h1>
<ol class="breadcrumb">
<li><a href="index.php?p=home"><i class="fa fa-dashboard"></i> Home</a></li>
<li class="active"><a href="index.php?p=ingredients">Recettes</a></li>
<li class="active">Ajouter</li>
</ol>
</section>
<!-- Main content -->
<section class="content">
<div class="row">
<form method="POST">
<div class="col-md-6">
<div class="box box-danger">
<div class="box-header">
<h3 class="box-title">Création de la recette</h3>
</div>
<div class="box-body">
<!-- Catégories -->
<?= $form->select('categories_id', 'Catégorie', $categories); ?>
<!-- /.form group -->
<!-- Nom de la recette -->
<?= $form->input('recettes', 'Choisir le nom de la recette'); ?>
<!-- /.form group -->
<!-- Nombre de personnes -->
<?= $form->input('nbpersonnes', 'Nombre de personnes'); ?>
<!-- /.form group -->
<!-- Marge -->
<?= $form->input('marge', 'Marge'); ?>
<!-- /.form group -->
<!-- Observation -->
<?= $form->input('observations', 'Observations', ['type'=>'textarea']); ?>
<!-- /.form group -->
<button id="add" class="btn btn-block submit">Valider</button>
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
</div>
<div class="col-md-6">
<div class="box box-danger">
<div class="box-header">
<h3 class="box-title">Sélectionner les ingrédients</h3>
</div>
<div class="box-body">
<div data-role="dynamic-fields">
<div class="inline">
<div class=" col-md-7">
<!-- Ingrédient -->
<?= $form->select('ingredients_id[]', 'Ingrédient', $ingredients); ?>
<!-- /.form group -->
</div>
<div class="col-md-3">
<!-- Quantités -->
<?= $form->input('quantite[]', 'Quantité'); ?>
<!-- /.form group -->
</div>
<div class="col-md-2">
<label>Action</label>
<button class="btn btn-default remove" data-role="remove"> <span class="glyphicon glyphicon-remove"></span></button>
<button class="btn btn-default" data-role="add"> <span class="glyphicon glyphicon-plus"></span></button>
</div>
</div>
</div>
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
</div>
</form>
<!-- /.form -->
</div>
<!-- /.row -->
</section>
<!-- /.content -->
</div>
<!-- /.content-wrapper --> |