Merge pull request 'BenBack' (#7) from BenBack into master
Reviewed-on: #7
This commit is contained in:
@@ -432,31 +432,88 @@ ul {
|
||||
}
|
||||
|
||||
.recette-form {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
height: 80%;
|
||||
width: 80%;
|
||||
margin: 10px;
|
||||
padding: 10px;
|
||||
border: 1px solid black;
|
||||
background: white;
|
||||
border-radius: 20px;
|
||||
}
|
||||
|
||||
.recette-form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
#recette-form-div-desc {
|
||||
height: 400px;
|
||||
height: 300px;
|
||||
}
|
||||
|
||||
#recette-form-description {
|
||||
height: 95%;
|
||||
}
|
||||
|
||||
.recette-add-form-all {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.recette-form-add {
|
||||
flex: 3;
|
||||
}
|
||||
|
||||
.recette-form-add-ingr {
|
||||
height: 30%;
|
||||
}
|
||||
|
||||
.recette-form-add-tag {
|
||||
height: 30%;
|
||||
}
|
||||
|
||||
.recette-form-add-additional{
|
||||
flex: 1;
|
||||
padding-right: 10px;
|
||||
}
|
||||
|
||||
.err {
|
||||
color: red;
|
||||
display: none;
|
||||
text-align: center;
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
.liste-ingr-elem {
|
||||
display: flex;
|
||||
height: 100px;
|
||||
padding:5px;
|
||||
background-color: #c6fdefe0;
|
||||
color: #000000;
|
||||
border: 1px solid black;
|
||||
border-radius: 10px;
|
||||
box-shadow: 1px 1px 1px black;
|
||||
}
|
||||
|
||||
.liste-ingr-elem-text {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
flex:12;
|
||||
padding-left: 20px;
|
||||
line-height: 100px;
|
||||
}
|
||||
|
||||
.ingr-image {
|
||||
flex: 1;
|
||||
border: 1px solid black;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
/*Footer et son contenue*/
|
||||
footer{
|
||||
padding: 25px;
|
||||
background: rgb(11, 189, 144);
|
||||
color: white;
|
||||
border-top: 1px solid black;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
169
public/assets/js/form.js
Normal file
169
public/assets/js/form.js
Normal file
@@ -0,0 +1,169 @@
|
||||
document.addEventListener("DOMContentLoaded", function(){
|
||||
|
||||
|
||||
let compl_form = document.getElementById("recette-form-complete");
|
||||
console.log(compl_form);
|
||||
|
||||
function formulaire_ingredient_update(event) {
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
console.log(event);
|
||||
|
||||
let form = document.getElementById("recette-form-ingr-add");
|
||||
|
||||
let cible = document.getElementById("recette-form-ingr");
|
||||
let nomIngredient = document.getElementById("recette-form-ingr-nom");
|
||||
let image = document.getElementById("recette-form-ingr-photo");
|
||||
if( nomIngredient.value === "" || image.value === "" ){
|
||||
alert( "Un champ requis est manquant." );
|
||||
return;
|
||||
}
|
||||
|
||||
let ingr = form.nom;
|
||||
|
||||
let form_data = new FormData(form);
|
||||
|
||||
fetch("/api/ingredients/create", {
|
||||
method : "POST",
|
||||
body: form_data
|
||||
}).then( reponse => {
|
||||
if (!reponse.ok) {
|
||||
let div_err = document.getElementById("recette-form-div-err-ingr");
|
||||
|
||||
div_err.style.display = "inherit";
|
||||
div_err.innerText = "Erreur de connection au serveur";
|
||||
|
||||
}
|
||||
else {
|
||||
reponse.json().then( data => {
|
||||
if (data.success) {
|
||||
let new_elem = document.createElement("option");
|
||||
|
||||
new_elem.setAttribute("value",document.getElementById('recette-form-ingr-nom').value);
|
||||
new_elem.innerText = document.getElementById('recette-form-ingr-nom').value;
|
||||
|
||||
cible.appendChild(new_elem);
|
||||
|
||||
document.getElementById('recette-form-ingr-nom').value = "";
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
function formulaire_tag_update(event){
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
let form = document.getElementById("recette-form-tag-add");
|
||||
|
||||
let cible = document.getElementById("recette-form-tag");
|
||||
let nomTag = document.getElementById("recette-form-tag-nom");
|
||||
if( nomTag.value === "" ){
|
||||
alert( "Un champ requis est manquant." );
|
||||
return;
|
||||
}
|
||||
|
||||
let tag = form.tag;
|
||||
|
||||
let form_data = new FormData(form);
|
||||
|
||||
fetch("/api/tags/create", {
|
||||
method : "POST",
|
||||
body: form_data
|
||||
}).then( reponse => {
|
||||
if (!reponse.ok) {
|
||||
let div_err = document.getElementById("recette-form-div-err-tag");
|
||||
|
||||
div_err.style.display = "inherit";
|
||||
div_err.innerText = "Erreur de connection au serveur";
|
||||
|
||||
}
|
||||
else {
|
||||
reponse.json().then( data => {
|
||||
if (data.success) {
|
||||
let new_elem = document.createElement("option");
|
||||
|
||||
new_elem.setAttribute("value",nomTag.value);
|
||||
new_elem.innerText = nomTag.value;
|
||||
|
||||
cible.appendChild(new_elem);
|
||||
|
||||
nomTag.value = "";
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
function formulaire_traitement(event){
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
console.log( event );
|
||||
|
||||
let nom = document.getElementById('recette-form-nom');
|
||||
let temps = document.getElementsByName('recette-form-nom');
|
||||
let photo = document.getElementById('recette-form-photo');
|
||||
let ingredients = document.getElementById('recette-form-ingr');
|
||||
let tags = document.getElementById('recette-form-tag');
|
||||
let description = document.getElementById('recette-form-description');
|
||||
|
||||
if( nom.value === "" || temps.value == "" || ingredients.value === "" || tags.value === ""){
|
||||
console.log( "Another field" );
|
||||
alert( "Un champ requis est manquant." );
|
||||
return;
|
||||
}
|
||||
if( !IS_EDIT && photo.value === ""){
|
||||
console.log( "Photo field" );
|
||||
alert( "Un champ requis est manquant." );
|
||||
return;
|
||||
}
|
||||
|
||||
if( temps <= 0 ){
|
||||
alert( "Le temps doit être positif ou supérieur à 0." );
|
||||
return;
|
||||
}
|
||||
|
||||
let form_data = new FormData(compl_form);
|
||||
form_data.append( "ingredients", form_data.getAll("ingr").join(",") );
|
||||
form_data.append( "tags", form_data.getAll( "tag").join(",") );
|
||||
if( RECETTE_ID !== 0 )
|
||||
form_data.append( 'id', RECETTE_ID );
|
||||
|
||||
let endpoint = IS_EDIT ? "/api/recettes/edit" : "/api/recettes/create";
|
||||
|
||||
fetch( endpoint, {
|
||||
method : "POST",
|
||||
body: form_data
|
||||
}).then( reponse => {
|
||||
if (!reponse.ok) {
|
||||
alert( "Erreur survenie" );
|
||||
}
|
||||
else {
|
||||
reponse.json().then( data => {
|
||||
if (data.success) {
|
||||
alert( "Envoyé" );
|
||||
} else {
|
||||
alert( data.error || "" );
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
let ingr_form = document.getElementById("recette-form-ingr-add");
|
||||
|
||||
ingr_form.addEventListener('submit', formulaire_ingredient_update);
|
||||
|
||||
let tag_form = document.getElementById("recette-form-tag-add");
|
||||
|
||||
tag_form.addEventListener('submit', formulaire_tag_update);
|
||||
compl_form.addEventListener('submit', formulaire_traitement);
|
||||
|
||||
|
||||
})
|
||||
@@ -41,13 +41,17 @@ class RecettesAPIController extends Controller {
|
||||
$recetteRepo = new RecetteRepository();
|
||||
$resp = $recetteRepo->advancedRecetteSearch( $title, $tagsId, $ingredientsId );
|
||||
|
||||
$resp = array_map( function($recette) use ($recetteRepo){
|
||||
$r = $recetteRepo->getByID( $recette['num_recette'] );
|
||||
$objResp = [];
|
||||
foreach( $resp as $r ){
|
||||
$r = $recetteRepo->getByID( $r['num_recette'] );
|
||||
$r->url = Router::getRouteURL( 'recettes->show', $r->slug );
|
||||
$r->nb_ingredients = $r->getNumberOfIngredients();
|
||||
return $r;
|
||||
}, $resp ?? [] );
|
||||
JSONResponse::sendSuccess( [ 'data' => $resp ] );
|
||||
if( !in_array( $r, $objResp ) ){
|
||||
$objResp[] = $r;
|
||||
}
|
||||
}
|
||||
|
||||
JSONResponse::sendSuccess( [ 'data' => $objResp ] );
|
||||
|
||||
}
|
||||
|
||||
@@ -58,8 +62,8 @@ class RecettesAPIController extends Controller {
|
||||
$temps = Request::post( 'temps' ) ?? "";
|
||||
$fileField = "image";
|
||||
|
||||
$tagsId = explode( ",", Request::post( 'tag' ) ) ?? [];
|
||||
$ingredientsId = explode( ",", Request::post( 'ingr' ) ) ?? [];
|
||||
$tagsId = explode( ",", Request::post( 'tags' ) ) ?? [];
|
||||
$ingredientsId = explode( ",", Request::post( 'ingredients' ) ) ?? [];
|
||||
|
||||
if( $tagsId == [ "" ] )
|
||||
$tagsId = [];
|
||||
@@ -83,13 +87,16 @@ class RecettesAPIController extends Controller {
|
||||
|
||||
// Vérification d'une entrée qui existerait déjà.
|
||||
$slug = strtolower( $name );
|
||||
$slug = str_replace( ' ', '-', $slug );
|
||||
$slug = str_replace( ' ', '', $slug );
|
||||
|
||||
$recetteRepo = new RecetteRepository();
|
||||
|
||||
if( $recetteRepo->getBySlug( $slug ) ){
|
||||
JSONResponse::sendError( [ 'error' => "Recette already exists" ] );
|
||||
}
|
||||
if( in_array( $slug, [ 'create', 'edit', 'delete' ] ) ){
|
||||
JSONResponse::sendError( [ 'error' => "Recette already exists" ] );
|
||||
}
|
||||
|
||||
// Création de la recette.
|
||||
$recette = new Recette();
|
||||
@@ -98,7 +105,7 @@ class RecettesAPIController extends Controller {
|
||||
$recette->titre_recette = $name;
|
||||
$recette->slug = $slug;
|
||||
|
||||
$recette->temps_de_preparation = intval( $temps );
|
||||
$recette->temps_de_preparation = intval( $temps <= 0 ? 1 : $temps );
|
||||
$recette->photo = $urlOrError;
|
||||
$recette->description_recette = $description;
|
||||
$recette->publication_date = date("Y-m-d");
|
||||
@@ -140,8 +147,8 @@ class RecettesAPIController extends Controller {
|
||||
$temps = Request::post( 'temps' ) ?? "";
|
||||
$fileField = "image";
|
||||
|
||||
$tagsId = explode( ",", Request::post( 'tag' ) ) ?? [];
|
||||
$ingredientsId = explode( ",", Request::post( 'ingr' ) ) ?? [];
|
||||
$tagsId = explode( ",", Request::post( 'tags' ) ) ?? [];
|
||||
$ingredientsId = explode( ",", Request::post( 'ingredients' ) ) ?? [];
|
||||
|
||||
if( $tagsId == [ "" ] )
|
||||
$tagsId = [];
|
||||
@@ -173,12 +180,12 @@ class RecettesAPIController extends Controller {
|
||||
|
||||
// Vérification d'une entrée qui existerait déjà.
|
||||
$slug = strtolower( $name );
|
||||
$slug = str_replace( ' ', '-', $slug );
|
||||
$slug = str_replace( ' ', '', $slug );
|
||||
|
||||
$recette->titre_recette = $name;
|
||||
$recette->slug = $slug;
|
||||
|
||||
$recette->temps_de_preparation = intval( $temps );
|
||||
$recette->temps_de_preparation = intval( $temps <= 0 ? 1 : $temps );
|
||||
$recette->description_recette = $description;
|
||||
|
||||
// Importation de la recette.
|
||||
|
||||
@@ -33,4 +33,15 @@ class RecettesController extends Controller {
|
||||
] );
|
||||
}
|
||||
|
||||
public function show( string $slug ): View {
|
||||
|
||||
$recette = new RecetteRepository()->getBySlug( $slug );
|
||||
if( !$recette )
|
||||
die( "Recette not found" );
|
||||
|
||||
return new View( 'recettes/show', [
|
||||
'recette' => $recette,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,12 @@
|
||||
namespace App\Domain\Recettes;
|
||||
|
||||
use App\Domain\Controller;
|
||||
use App\Domain\Ingredients\IngredientRepository;
|
||||
use App\Domain\Tags\TagRepository;
|
||||
use App\Helpers\Authentification;
|
||||
use App\Http\JSONResponse;
|
||||
use App\Http\Request;
|
||||
use App\Infrastructure\View;
|
||||
|
||||
class RecettesManagementController extends Controller {
|
||||
|
||||
@@ -11,7 +17,69 @@ class RecettesManagementController extends Controller {
|
||||
return [
|
||||
self::Route( routeUrl: '/recettes/create', routeName: 'recettes->create', routeAction: 'create' ),
|
||||
self::Route( routeUrl: '/recettes/edit/{int}', routeName: 'recettes->edit', routeAction: 'edit' ),
|
||||
self::Route( routeUrl: '/recettes/delete/{int}', routeName: 'recettes->delete', routeAction: 'delete' ),
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
public function create(): View {
|
||||
if( !Authentification::isLoggedIn() )
|
||||
die( "Not logged in" );
|
||||
|
||||
return new View( 'recettes/create', [
|
||||
'tags' => new TagRepository()->getAll(),
|
||||
'ingredients' => new IngredientRepository()->getAll(),
|
||||
] );
|
||||
}
|
||||
|
||||
public function edit( int $idRecette ): View {
|
||||
if( !Authentification::isLoggedIn() )
|
||||
die( "Not logged in" );
|
||||
|
||||
$recette = new RecetteRepository()->getByID( $idRecette );
|
||||
if( !$recette )
|
||||
die( "Recette not found" );
|
||||
|
||||
$tagsID = array_map( function($tag) {
|
||||
return $tag->getId();
|
||||
}
|
||||
, $recette->getAllLinkedTags() ?? [] );
|
||||
|
||||
$ingredientsID = array_map( function($tag) {
|
||||
return $tag->getId();
|
||||
}
|
||||
, $recette->getAllLinkedIngredients() ?? [] );
|
||||
|
||||
return new View( 'recettes/edit', [
|
||||
'recette' => $recette,
|
||||
'recetteTags' => $tagsID,
|
||||
'recetteIngr' => $ingredientsID,
|
||||
'tags' => new TagRepository()->getAll(),
|
||||
'ingredients' => new IngredientRepository()->getAll(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete( int $idRecette ): never {
|
||||
if( !Authentification::isLoggedIn() )
|
||||
die( "Not logged in" );
|
||||
|
||||
$recette = new RecetteRepository()->getByID( $idRecette );
|
||||
if( !$recette )
|
||||
die( "Recette not found" );
|
||||
|
||||
$recetteRepo = new RecetteRepository();
|
||||
|
||||
// Retirer tous les liens Ingrédients/Tags.
|
||||
foreach( ( $recette->getAllLinkedIngredients() ?? [] ) as $ingr ){
|
||||
$recetteRepo->removeAnIngredient( $ingr, $recette );
|
||||
}
|
||||
foreach( ( $recette->getAllLinkedTags() ?? [] ) as $tag ){
|
||||
$recetteRepo->removeATag( $tag, $recette );
|
||||
}
|
||||
|
||||
if( !$recetteRepo->delete( $recette ) )
|
||||
JSONResponse::sendError( [ 'error' => 'An error occured while deleting recette' ] );
|
||||
|
||||
Request::redirectTo( 'recettes->index' );
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,2 @@
|
||||
<h1>Coucou</h1>
|
||||
<?php $str = "Markdown **text**\n# SOLONG\n*text*."; $md = \App\Helpers\Markdown::convertToHTML( $str ); echo "<p>$md</p>"; ?>
|
||||
|
||||
<?php
|
||||
/*
|
||||
$ing = new \App\Domain\Ingredients\Ingredient();
|
||||
$ing->num_ingredient = 0;
|
||||
$ing->nom_ingredient = "coucou";
|
||||
new \App\Domain\Ingredients\IngredientRepository()->add($ing);
|
||||
*/
|
||||
|
||||
var_dump( new \App\Domain\Recettes\RecetteRepository()->advancedRecetteSearch( "", [ 4 ], [] ) );
|
||||
?>
|
||||
|
||||
77
views/recettes/create.php
Normal file
77
views/recettes/create.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php use App\Domain\Recettes\Recette;
|
||||
use App\Infrastructure\View as V; ?>
|
||||
|
||||
<div class="main-body">
|
||||
<div class="content">
|
||||
<div class="recette-add-form-all">
|
||||
<form id="recette-form-complete" class="recette-form recette-form-add" action="/api/recettes/create" method="POST">
|
||||
<div class="recette-form-group form-group">
|
||||
<label for="nom">Titre : </label>
|
||||
<input type="text" class="form-control" id="recette-form-nom" name="nom" placeholder="Titre de votre recette">
|
||||
</div>
|
||||
<div class="recette-form-group form-group">
|
||||
<label for="temps">Temps (en min) : </label>
|
||||
<input type="number" class="form-control" id="recette-form-temps" name="temps" placeholder="Temps de préparation">
|
||||
</div>
|
||||
<div class="recette-form-group form-group">
|
||||
<label for="image">Photo du plat : </label>
|
||||
<input type="file" class="form-control" id="recette-form-photo" name="image" placeholder="ajouter votre image">
|
||||
</div>
|
||||
<div class="recette-form-group form-group" id="recette-form-div-ingr">
|
||||
<label for="ingr">Ingredients</label>
|
||||
<select multiple class="form-control" id="recette-form-ingr" name="ingr" placeholder="Ingredients">
|
||||
<?php foreach( V::arg( 'ingredients') as $ingr ): ?>
|
||||
<option value="<?php echo $ingr->getID(); ?>"><?php echo $ingr->nom_ingredient; ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="recette-form-group form-group" id="recette-form-div-tag">
|
||||
<label for="tag">Tag</label>
|
||||
<select multiple class="form-control" id="recette-form-tag" name="tag" placeholder="Tag">
|
||||
<?php foreach( V::arg( 'tags') as $tag ): ?>
|
||||
<option value="<?php echo $tag->getID(); ?>"><?php echo $tag->nom_tag; ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="recette-form-group form-group" id="recette-form-div-desc">
|
||||
<label for="description">Description</label>
|
||||
<textarea type="texte" class="form-control" id="recette-form-description" name="description" placeholder="Description..."></textarea>
|
||||
</div>
|
||||
|
||||
<button type='submit' class='btn btn-primary'>Confirmer</button>
|
||||
</form>
|
||||
<div class="recette-form-add-additional">
|
||||
<form id="recette-form-ingr-add" class="recette-form recette-form-add-ingr" action="" method="POST">
|
||||
<div class="recette-form-group form-group">
|
||||
<label for="name">Nom de l'Ingrédient</label>
|
||||
<input type="texte" class="form-control" id="recette-form-ingr-nom" name="name" placeholder="Nom de l'ingrédient" value="">
|
||||
</div>
|
||||
<div class="recette-form-group form-group">
|
||||
<label for="image">Photo de l'Ingrédient</label>
|
||||
<input type="file" class="form-control" id="recette-form-ingr-photo" name="image">
|
||||
</div>
|
||||
|
||||
<button id="submit-ingr" type='submit' class='btn btn-primary'>Confirmer</button>
|
||||
<div id="recette-form-div-err-ingr" class="err">
|
||||
Erreur
|
||||
</div>
|
||||
</form>
|
||||
<form id="recette-form-tag-add" class="recette-form recette-form-add-tag" action="" method="POST">
|
||||
<div class="recette-form-group form-group">
|
||||
<label for="tag">Tags</label>
|
||||
<input type="text" class="form-control" id="recette-form-tag-nom" name="name" placeholder="Nom de l'ingrédient">
|
||||
</div>
|
||||
|
||||
<button type='submit' class='btn btn-primary'>Confirmer</button>
|
||||
<div id="recette-form-div-err-tag" class="err">
|
||||
Erreur
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
const IS_EDIT = false; const RECETTE_ID = 0;
|
||||
</script>
|
||||
<script src="<?php V::assetUrl( 'js/form.js' ); ?>" defer></script>
|
||||
77
views/recettes/edit.php
Normal file
77
views/recettes/edit.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php use App\Domain\Recettes\Recette;
|
||||
use App\Infrastructure\View as V; ?>
|
||||
<?php /** @var Recette $R */$R = V::arg( 'recette'); ?>
|
||||
<div class="main-body">
|
||||
<div class="content">
|
||||
<div class="recette-add-form-all">
|
||||
<form id="recette-form-complete" class="recette-form recette-form-add" action="/api/recettes/edit" method="POST">
|
||||
<div class="recette-form-group form-group">
|
||||
<label for="nom">Titre : </label>
|
||||
<input type="text" class="form-control" id="recette-form-nom" name="nom" placeholder="Titre de votre recette" value="<?php echo $R->titre_recette; ?>">
|
||||
</div>
|
||||
<div class="recette-form-group form-group">
|
||||
<label for="temps">Temps (en min) : </label>
|
||||
<input type="number" class="form-control" id="recette-form-temps" name="temps" placeholder="Temps de préparation" value="<?php echo $R->temps_de_preparation; ?>">
|
||||
</div>
|
||||
<div class="recette-form-group form-group">
|
||||
<label for="image">Photo du plat : </label>
|
||||
<input type="file" class="form-control" id="recette-form-photo" name="image" placeholder="ajouter votre image">
|
||||
</div>
|
||||
<div class="recette-form-group form-group" id="recette-form-div-ingr">
|
||||
<label for="ingr">Ingredients</label>
|
||||
<select multiple class="form-control" id="recette-form-ingr" name="ingr" placeholder="Ingredients">
|
||||
<?php foreach( V::arg( 'ingredients') as $ingr ): ?>
|
||||
<option value="<?php echo $ingr->getID(); ?>" <?php echo in_array( $ingr->getId(), V::arg( 'recetteIngr') ) ? "selected" : ""; ?> ><?php echo $ingr->nom_ingredient; ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="recette-form-group form-group" id="recette-form-div-tag">
|
||||
<label for="tag">Tag</label>
|
||||
<select multiple class="form-control" id="recette-form-tag" name="tag" placeholder="Tag">
|
||||
<?php foreach( V::arg( 'tags') as $tag ): ?>
|
||||
<option value="<?php echo $tag->getID(); ?>" <?php echo in_array( $tag->getId(), V::arg( 'recetteTags' ) ) ? "selected" : ""; ?> ><?php echo $tag->nom_tag; ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="recette-form-group form-group" id="recette-form-div-desc">
|
||||
<label for="description">Description</label>
|
||||
<textarea type="texte" class="form-control" id="recette-form-description" name="description" placeholder="Description..."><?php echo $R->description_recette; ?></textarea>
|
||||
</div>
|
||||
|
||||
<button type='submit' class='btn btn-primary'>Confirmer</button>
|
||||
</form>
|
||||
<div class="recette-form-add-additional">
|
||||
<form id="recette-form-ingr-add" class="recette-form recette-form-add-ingr" action="" method="POST">
|
||||
<div class="recette-form-group form-group">
|
||||
<label for="name">Nom de l'Ingrédient</label>
|
||||
<input type="texte" class="form-control" id="recette-form-ingr-nom" name="name" placeholder="Nom de l'ingrédient" value="">
|
||||
</div>
|
||||
<div class="recette-form-group form-group">
|
||||
<label for="image">Photo de l'Ingrédient</label>
|
||||
<input type="file" class="form-control" id="recette-form-ingr-photo" name="image">
|
||||
</div>
|
||||
|
||||
<button id="submit-ingr" type='submit' class='btn btn-primary'>Confirmer</button>
|
||||
<div id="recette-form-div-err-ingr" class="err">
|
||||
Erreur
|
||||
</div>
|
||||
</form>
|
||||
<form id="recette-form-tag-add" class="recette-form recette-form-add-tag" action="" method="POST">
|
||||
<div class="recette-form-group form-group">
|
||||
<label for="tag">Tags</label>
|
||||
<input type="text" class="form-control" id="recette-form-tag-nom" name="name" placeholder="Nom de l'ingrédient">
|
||||
</div>
|
||||
|
||||
<button type='submit' class='btn btn-primary'>Confirmer</button>
|
||||
<div id="recette-form-div-err-tag" class="err">
|
||||
Erreur
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
const IS_EDIT = true; const RECETTE_ID = <?php echo $R->getId(); ?>;
|
||||
</script>
|
||||
<script src="<?php V::assetUrl( 'js/form.js' ); ?>" defer></script>
|
||||
@@ -5,7 +5,7 @@
|
||||
<div id="recetteList" class="recettes">
|
||||
<?php if( V::arg( 'recettesList' ) != null ) foreach( V::arg( 'recettesList' ) as $recette ): ?>
|
||||
<a class="recette-icone" href="<?php V::routeUrl( 'recettes->show', $recette->slug ); ?>">
|
||||
<img class="recette-preview-image" src="random-recette.jpg">
|
||||
<img class="recette-preview-image" src="<?php echo $recette->photo; ?>">
|
||||
<div class="recette-icone-content">
|
||||
<h3><?php echo $recette->titre_recette; ?></h3>
|
||||
<ul>
|
||||
|
||||
53
views/recettes/show.php
Normal file
53
views/recettes/show.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php use App\Domain\Recettes\Recette;
|
||||
use App\Infrastructure\View as V; ?>
|
||||
<?php /** @var Recette $R */ $R = V::arg( 'recette' ); ?>
|
||||
|
||||
<div class="content">
|
||||
<div class="recette-title">
|
||||
<h1><?php echo $R->titre_recette; ?></h1>
|
||||
</div>
|
||||
<div class="recette-content">
|
||||
<div class="recette-div-info">
|
||||
<div class="recette-div-image">
|
||||
<img class="recette-image" src="<?php echo $R->photo; ?>">
|
||||
</div>
|
||||
<div class="recette-div-liste-info">
|
||||
<?php if( \App\Helpers\Authentification::isLoggedIn() ): ?>
|
||||
<ul class="recette-list-buttons">
|
||||
<li><a class="recette-button" href="#" id="delete" data-id="<?php echo $R->num_recette; ?>">Supprimer</a></li>
|
||||
<li><a class="recette-button" href="<?php V::routeUrl( 'recettes->edit', $R->getID() ); ?>">Modifier</a></li>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
<ul class="recette-liste-info">
|
||||
<li class="recette-liste-info-elem"><?php echo $R->publication_date; ?></li>
|
||||
<li class="recette-liste-info-elem"><?php echo $R->temps_de_preparation; ?> minutes</li>
|
||||
<li class="recette-liste-info-elem"><?php echo $R->getNumberOfIngredients(); ?> ingrédients</li>
|
||||
</ul>
|
||||
<ul class="recette-liste-tag">
|
||||
<?php foreach( $R->getAllLinkedTags() as $tag ): ?>
|
||||
<li class="tag tag-unselected"><?php echo $tag->nom_tag; ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class = "recette-desc">
|
||||
<h3>Ingrédients :</h3>
|
||||
<ul>
|
||||
<?php foreach( $R->getAllLinkedIngredients() as $ingr ): ?>
|
||||
<li><?php echo $ingr->nom_ingredient; ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<div id="description">
|
||||
<?php echo $R->getHTMLDescription(); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
document.getElementById( 'delete' ).addEventListener( 'click', e => {
|
||||
if( window.confirm( "Êtes-vous sur de vouloir supprimer cette recette ? ") ){
|
||||
let id = document.getElementById( 'delete' ).getAttribute( 'data-id' );
|
||||
window.location.href = "/recettes/delete/" + id;
|
||||
}
|
||||
})
|
||||
</script>
|
||||
Reference in New Issue
Block a user