Creation recette editeur

Created by: PetitGens

Merge request reports

Loading
+36 −0
Changes for src/controllers/creationRecetteUtilisateur.php: 36 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

include_once 'src/model/recetteManager.php';
include_once 'src/model/recette.php';
include_once 'src/controllers/connexion.php';

class CreationRecetteUtilisateurControleur{

    public function executer() {
        require_once 'templates/creationRecetteUtilisateur.php';
    }

    public function insererRecette($titre, $categorie, $resume, $recette, $image, $ingredients, $tags) {

        $recetteManager = new recetteManager();
        $connexionManager = new ConnexionController();
        
        $listeingredients = explode(',', $ingredients);
        $listetags = explode(',', $tags);

        $recette = new Recette($titre, $recette, $resume, $image, 'A',$connexionManager->estConnecte()->getId() , $categorie);

        $recetteManager->creerRecette($recette);

        $recette = $recetteManager->getDerniereRecetteCree((new ConnexionController)->estConnecte());

        foreach($listeingredients as $ingredient){
            (new IngredientManager)->ajouterIngredientARecette(new Ingredient($ingredient), $recette->getId());
        }
        foreach($listetags as $tag){
            (new TagManager)->ajouterTagARecette(new Tag($tag), $recette->getId());
        }

    }

}
 No newline at end of file
+20 −0
Changes for src/model/recetteManager.php: 20 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -81,6 +81,26 @@ class RecetteManager extends Manager {
        return self::recetteFromLigne($ligne);
    }

    public function getDerniereRecetteCree(Utilisateur $utilisateur): ?Recette{
        $idUtilisateur = $utilisateur->getId(); 
        $requete = 
        "SELECT * FROM CUI_RECETTE 
        JOIN CUI_CATEGORIE USING (CAT_CODE)
        JOIN CUI_UTILISATEUR USING (UTIL_ID)
        WHERE UTIL_ID = '$idUtilisateur'
        ORDER BY REC_DATE_CREATION DESC LIMIT 1";

        $resultat = self::projectionBdd($requete);
                
        if(! isset($resultat[0])) {
            return null;
        }

        $ligne = $resultat[0];

        return self::recetteFromLigne($ligne);
    }

    /**
     * Renvoie la version modifiée d'une recette si elle existe
     * @param string $id l'id de la recette
+92 −0
Changes for templates/creationRecetteUtilisateur.php: 92 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php


$titre = 'nouvelle recette';

// ob_start crée un buffer qui va récupérer tout ce qui est censé être affiché (echo + HTML) 
ob_start();

    ?>

<div class="container py-4 py-xl-5">
            <div class="row mb-5">
                <div class="col-md-8 col-xl-6 text-center mx-auto">
                    <h2>Création de recette</h2>
                    <p class="w-lg-50">À votre tour! insérez votre recette ici.</p>
                </div>
            </div>

            <form method="post">

                <div>
                    <label for="titre">Titre :</label>
                    <input type="text" id="titre" name="titre">
                </div>

                <label for="categorie">Categorie :</label> 
                    <select name="categorie" id="categorie"> 
                        <?php
                        foreach((new CategorieManager)->getCategories() as $categorie){
                            ?>
                            <option value="<?=$categorie?>"><?=$categorie?></option>
                            <?php
                        }
                        ?>
                    </select>
                    
                <br>
                <div>
                    <label for="resume">Résumé :</label>
                    <textarea id="resume" name="resume" style="width:100%; height:100px"></textarea>
                </div>
                <div>
                    <label for="recette">Recette :</label>
                    <textarea id="recette" name="recette" style="width:100%; height:400px"></textarea>
                </div>
                <div>
                    <label for="image">Lien vers l'image :</label>
                    <input type="text" id="image" name="image">
                </div>
                
                <div>
                    <label for="tags">tags (séparez les par des virgules) :</label>
                    <input type="text" id="tags" name="tags">
                </div>

                <div>
                    <label for="ingredients">ingredients (séparez les par des virgules) :</label>
                    <input type="text" id="ingredients" name="ingredients">
                </div>

                <button type="submit" id="boutonvalider">Enregistrer</button>

            </form>

        </div>

<?php




if(isset($_POST['titre']) and isset($_POST['categorie']) and isset($_POST['resume']) and isset($_POST['recette']) and isset($_POST['image']) and  isset($_POST['ingredients']) and isset($_POST['tags'])){
    
    $controleurcreationrecette = new CreationRecetteUtilisateurControleur();

    $titre = $_POST['titre'];
    $categorie = $_POST['categorie'];
    $resume = $_POST['resume'];
    $recette = $_POST['recette'];
    $image = $_POST['image'];
    $ingredients = $_POST['ingredients'];
    $tags = $_POST['tags'];

    $controleurcreationrecette->insererRecette($titre, $categorie, $resume, $recette, $image, $ingredients, $tags);

}


// On peut récupérer le contenu du buffer comme ça :
$contenu = ob_get_clean();

require 'templates/layout.php';
 No newline at end of file
+1 −2
Changes for templates/layout.php: 1 added line, 2 removed lines.
Original line number Diff line number Diff line
@@ -52,7 +52,6 @@ $utilisateur = ConnexionController::estConnecte();
                            ?>
                        </div>
                    </li>

                    <?php
                    if($utilisateur){
                        ?>
@@ -62,7 +61,7 @@ $utilisateur = ConnexionController::estConnecte();
                            </a>
                            <div id="sousMenuCompte" class="dropdown-menu" data-bs-popper="none" style="--bs-body-bg: var(--bs-primary);background: var(--bs-secondary);">
                                <a class="dropdown-item" href=".?action=mesRecettes">Mes recettes</a>
                                <a class="dropdown-item" href="#">Nouvelle Recette</a>
                                <a class="dropdown-item" href=".?action=creation">Nouvelle Recette</a>
                                <?php if ($utilisateur->estAdministrateur()){
                                    ?>
                                    <a class="dropdown-item" href="?action=recettesAdmin">Recettes a valider</a>
+2 −1
Changes for templates/pageRecette.php: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -27,10 +27,10 @@ function afficherPageRecette(Recette $recette, bool $admin){

    ob_start();
    ?>

    <div data-bss-bg="true" style="text-align:center;height: 500px;padding-top: 30px;padding-right: 10px;padding-left: 10px;background-image: url(<?=$recette->getImage()?>);background-repeat: no-repeat;background-size: contain;background-position: center">
        <h1 style="margin:auto;margin-top: 20px;margin-bottom: 10%;padding: 10px;width: fit-content;text-align: center;background:rgba(192,192,192,0.75);border-radius: 5px;"><?=$recette->getTitre() ?></h1>
    </div>
    <p style="margin:auto;margin-top: 10px;margin-bottom: 10px;padding: 10px;width: fit-content;text-align: center;background:rgba(192,192,192,0.75);border-radius: 5px;"><?=$recette->getResume() ?></p>
    <div class="row" style="width: inherit;padding-right: 4%;padding-left: 4%;">
        <div class="col" style="overflow: auto">
            <div class="d-flex flex-row flex-nowrap" style="overflow: auto">
@@ -79,3 +79,4 @@ function afficherPageRecette(Recette $recette, bool $admin){

    require 'templates/layout.php';
}
?>
 No newline at end of file
Loading
Loading