From f60a9d046088b3bad3e97ff568fc83fecc67ccde Mon Sep 17 00:00:00 2001 From: polo Date: Thu, 26 Jun 2025 11:11:24 +0200 Subject: =?UTF-8?q?ajout=20dans=20css=5Farray=20=C3=A0=20la=20cr=C3=A9atio?= =?UTF-8?q?n=20d'un=20bloc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/index.php | 2 +- src/controller/post.php | 26 +++++++++++++++++++++++++- src/model/entities/Node.php | 8 +++++--- src/view/MainBuilder.php | 9 +++++---- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/public/index.php b/public/index.php index 8d3148c..bd3eec7 100644 --- a/public/index.php +++ b/public/index.php @@ -53,7 +53,7 @@ require '../src/controller/post.php'; $id = ''; if(!empty($_GET['id'])) { - $id = htmlspecialchars($_GET['id']); + $id = htmlspecialchars($_GET['id']); // nettoyage qui n'abime pas les id du genre "n16" } if(isset($_GET['action']) && $_GET['action'] === 'deconnexion') diff --git a/src/controller/post.php b/src/controller/post.php index 3ba0656..7e6ed53 100644 --- a/src/controller/post.php +++ b/src/controller/post.php @@ -132,8 +132,32 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) $main = $director->getNode(); $position = count($main->getChildren()) + 1; // position dans la fraterie + $blocs_true_names = ['blog', 'grid', 'calendar', 'galery', 'form']; // même liste dans FormBuilder.php + if(!in_array($_POST["bloc_select"], $blocs_true_names, true)) // 3è param: contrôle du type + { + header("Location: " . new URL(['page' => $_GET['page'], 'error' => 'bad_bloc_type'])); + die; + } + + if($_POST["bloc_select"] === 'calendar'){ + $dql = 'SELECT n FROM App\Entity\Node n WHERE n.page = :page AND n.name_node = :name'; // noeud 'head' de la page + $bulk_data = $entityManager + ->createQuery($dql) + ->setParameter('page', $page) + ->setParameter('name', 'head') + ->getResult(); + + if(count($bulk_data) != 1){ // 1 head par page + header("Location: " . new URL(['page' => $_GET['page'], 'error' => 'head_node_not_found'])); + die; + } + + $bulk_data[0]->addAttribute('css_array', 'calendar'); + $entityManager->persist($bulk_data[0]); + } + $bloc = new Node( - trim(htmlspecialchars($_POST["bloc_select"])), + $_POST["bloc_select"], null, [], $position, $main, diff --git a/src/model/entities/Node.php b/src/model/entities/Node.php index 711eb3e..c4d0830 100644 --- a/src/model/entities/Node.php +++ b/src/model/entities/Node.php @@ -98,13 +98,15 @@ class Node { $this->attributes = self::$default_attributes; } - /*public function addAttribute(string $key, string $value): void + public function addAttribute(string $key, string $value): void { if(!isset($this->attributes[$key])) { // sécurité $key inexistante $this->attributes[$key] = []; } - $this->attributes[$key][] = $value; - }*/ + if(!in_array($value, $this->attributes[$key])){ + $this->attributes[$key][] = $value; + } + } /*public function removeAttribute(string $key, string $value): void { if(isset($this->attributes[$key])) // sécurité $key inexistante diff --git a/src/view/MainBuilder.php b/src/view/MainBuilder.php index 11f5c4b..a478412 100644 --- a/src/view/MainBuilder.php +++ b/src/view/MainBuilder.php @@ -55,8 +55,8 @@ class MainBuilder extends AbstractBuilder $viewFile = self::VIEWS_PATH . $node->getName() . '.php'; // mode modification uniquement // blocs disponibles - $blocs = ['Blog', 'Grille', 'Calendrier', 'Galerie']; // générer ça dynamiquement! - $blocs_true_names = ['blog', 'grid', 'calendar', 'galery']; + $blocs = ['Blog', 'Grille', 'Calendrier', 'Galerie', 'Formulaire']; // générer ça dynamiquement! + $blocs_true_names = ['blog', 'grid', 'calendar', 'galery', 'form']; // même liste dans post.php $options = ''; for($i = 0; $i < count($blocs); $i++){ @@ -85,7 +85,8 @@ class MainBuilder extends AbstractBuilder foreach($node->getChildren() as $child_node){ // renommage d'un bloc $bloc_edit .= '
-

+

+ '. "\n"; // déplacement d'un bloc @@ -95,7 +96,7 @@ class MainBuilder extends AbstractBuilder $bloc_edit .= '

-

+

'. "\n"; } -- cgit v1.2.3