From 1e2cee519264f9ab2660540723915aec72bc2116 Mon Sep 17 00:00:00 2001 From: polo Date: Mon, 20 Oct 2025 01:57:21 +0200 Subject: =?UTF-8?q?noeud=20"head"=20unique,=20noms=20fichiers=20CSS=20et?= =?UTF-8?q?=20JSS=20dans=20page,=20nombreux=20changements=20en=20cons?= =?UTF-8?q?=C3=A9quences?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/ArticleController.php | 4 +-- src/controller/MenuAndPathsController.php | 2 +- src/controller/PageManagementController.php | 38 ++++-------------------- src/installation.php | 46 ++++++++--------------------- src/model/entities/Node.php | 12 +++----- src/model/entities/Page.php | 41 +++++++++++++++++++++++++ src/view/HeadBuilder.php | 9 ++---- src/view/HeaderBuilder.php | 6 ---- src/view/MainBuilder.php | 2 +- src/view/NewBuilder.php | 6 ---- src/view/PostBuilder.php | 6 ---- src/view/templates/modify_block.php | 6 ++-- 12 files changed, 74 insertions(+), 104 deletions(-) (limited to 'src') diff --git a/src/controller/ArticleController.php b/src/controller/ArticleController.php index 06562e7..7061897 100644 --- a/src/controller/ArticleController.php +++ b/src/controller/ArticleController.php @@ -92,7 +92,7 @@ class ArticleController $date = new \DateTime($content['d'] . ':' . (new \DateTime)->format('s')); // l'input type="datetime-local" ne donne pas les secondes, on les ajoute: 'hh:mm' . ':ss' $article = new Article($content['i'], $date, $content['t'], $content['p']); - $article_node = new Node('new', [], count($node->getChildren()) + 1, $node, $node->getPage(), $article); + $article_node = new Node('new', count($node->getChildren()) + 1, $node, $node->getPage(), $article); } else{ // autres cas $timestamp = time(); @@ -101,7 +101,7 @@ class ArticleController $article = new Article($content, $date); // le "current" timestamp est obtenu par la BDD $placement = $json['placement'] === 'first' ? 0 : count($node->getChildren()) + 1; // - $article_node = new Node('post', [], $placement, $node, $node->getPage(), $article); + $article_node = new Node('post', $placement, $node, $node->getPage(), $article); if($json['placement'] === 'first'){ $node->addChild($article_node); diff --git a/src/controller/MenuAndPathsController.php b/src/controller/MenuAndPathsController.php index f0553ad..a32b210 100644 --- a/src/controller/MenuAndPathsController.php +++ b/src/controller/MenuAndPathsController.php @@ -22,7 +22,7 @@ class MenuAndPathsController $page = new Page( trim(htmlspecialchars($_POST["label_input"])), - $url_input, + $url_input, '', true, true, false, $previous_page->getPosition(), $parent); // peut et DOIT être null si on est au 1er niveau diff --git a/src/controller/PageManagementController.php b/src/controller/PageManagementController.php index 9dce952..c45f3f3 100644 --- a/src/controller/PageManagementController.php +++ b/src/controller/PageManagementController.php @@ -68,6 +68,8 @@ class PageManagementController true, true, false, $previous_page->getPosition(), $parent); // peut et DOIT être null si on est au 1er niveau + $page->useDefaultCSS(); + $page->useDefaultJS(); // on a donné à la nouvelle entrée la même position qu'à la précédente, // addChild l'ajoute à la fin du tableau "children" puis on trie @@ -80,24 +82,7 @@ class PageManagementController $page->setPagePath(ltrim($parent->getPagePath() . '/' . $page->getEndOfPath(), '/')); - // noeud "head" - $node = new Node('head', [], - 1, // position d'un head = 1 - null, // pas de parent - $page); - $node->useDefaultAttributes(); // fichiers CSS et JS - - $data = new NodeData([], $node); - - $bulk_data = $entityManager - ->createQuery('SELECT n FROM App\Entity\Image n WHERE n.file_name LIKE :name') - ->setParameter('name', '%favicon%') - ->getResult(); - $data->setImages(new ArrayCollection($bulk_data)); - $entityManager->persist($page); - $entityManager->persist($node); - $entityManager->persist($data); $entityManager->flush(); // page créée, direction la page en mode modification pour ajouter des blocs @@ -142,26 +127,15 @@ class PageManagementController } if($_POST["bloc_select"] === 'calendar' || $_POST["bloc_select"] === 'form'){ - $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; - } + $page->setCSS(array_merge($page->getCSS(), [$_POST["bloc_select"]])); - $bulk_data[0]->addAttribute('css_array', $_POST["bloc_select"]); if($_POST["bloc_select"] === 'form'){ - $bulk_data[0]->addAttribute('js_array', $_POST["bloc_select"]); + $page->setJS(array_merge($page->getJS(), [$_POST["bloc_select"]])); } - $entityManager->persist($bulk_data[0]); + $entityManager->persist($page); } - $block = new Node($_POST["bloc_select"], [], $position, $main, $page); + $block = new Node($_POST["bloc_select"], $position, $main, $page); $data = new NodeData(['title' => trim(htmlspecialchars($_POST["bloc_title"]))], $block); // valeurs par défaut diff --git a/src/installation.php b/src/installation.php index 7fff5f7..df0f851 100644 --- a/src/installation.php +++ b/src/installation.php @@ -100,21 +100,16 @@ function makeStartPage(EntityManager $entityManager){ /* -- table node -- */ // paramètres: name_node, article_timestamp, attributes, position, parent, page, article - $head_accueil = new Node('head', ['css_array' => ['body', 'head', 'nav', 'foot'], 'js_array' => ['main']], 1, NULL, $accueil, NULL); - $head_article = new Node('head', ['css_array' => ['body', 'head', 'nav', 'foot'], 'js_array' => ['main']], 1, NULL, $article, NULL); - $header = new Node('header', [], 2, NULL, NULL, NULL); - $nav = new Node('nav', [], 1, $header, NULL, NULL); - $main = new Node('main', [], 3, NULL, NULL, NULL); - $footer = new Node('footer', [], 4, NULL, NULL, NULL); - $breadcrumb = new Node('breadcrumb', [], 2, $header, NULL, NULL); - $head_login = new Node('head', ["stop" => true, 'css_array' => ['body'], 'js_array' => ['main']], 1, NULL, $connection, NULL); - $login = new Node('login', [], 1, $main, $connection, NULL); - $head_my_account = new Node('head', ["stop" => true, 'css_array' => ['body'], 'js_array' => ['main']], 1, NULL, $my_account, NULL); - $user_edit = new Node('user_edit', [], 1, $main, $my_account, NULL); - $head_edit_menu = new Node('head', ['css_array' => ['body', 'head', 'nav', 'menu', 'foot'], 'js_array' => ['main', 'menu']], 1, NULL, $menu_paths, NULL); - $bloc_edit_menu = new Node('menu', [], 1, $main, $menu_paths, NULL); - $head_new_page = new Node('head', ['css_array' => ['body', 'head', 'nav', 'new_page', 'foot'], 'js_array' => ['main', 'new_page']], 1, NULL, $new_page, NULL); - $bloc_new_page = new Node('new_page', [], 1, $main, $new_page, NULL); + $head = new Node('head', 1, NULL, NULL, NULL); + $header = new Node('header', 2, NULL, NULL, NULL); + $nav = new Node('nav', 1, $header, NULL, NULL); + $main = new Node('main', 3, NULL, NULL, NULL); + $footer = new Node('footer', 4, NULL, NULL, NULL); + $breadcrumb = new Node('breadcrumb', 2, $header, NULL, NULL); + $login = new Node('login', 1, $main, $connection, NULL); + $user_edit = new Node('user_edit', 1, $main, $my_account, NULL); + $bloc_edit_menu = new Node('menu', 1, $main, $menu_paths, NULL); + $bloc_new_page = new Node('new_page', 1, $main, $new_page, NULL); /* -- table asset -- */ // paramètres: file_name, file_path, file_path_mini, mime_type, alt @@ -128,12 +123,7 @@ function makeStartPage(EntityManager $entityManager){ /* -- table node_data -- */ // paramètres: data, node, images - $head_accueil_data = new NodeData([], $head_accueil, new ArrayCollection([$favicon])); - $head_login_data = new NodeData([], $head_login, new ArrayCollection([$favicon])); - $head_my_account_data = new NodeData([], $head_my_account, new ArrayCollection([$favicon])); - $head_article_data = new NodeData([], $head_article, new ArrayCollection([$favicon])); - $head_edit_menu_data = new NodeData([], $head_edit_menu, new ArrayCollection([$favicon])); - $head_new_page_data = new NodeData([], $head_new_page, new ArrayCollection([$favicon])); + $head_data = new NodeData([], $head, new ArrayCollection([$favicon])); $header_data = new NodeData(["title" => "Titre", "description" => "Sous-titre", "header_logo" => "assets/logo-nb-et-ffn.png", "header_background" => "assets/fond-piscine.jpg", "social" => ["facebook" => "https://www.facebook.com", "instagram" => "https://www.instagram.com", "linkedin" => "https://www.linkedin.com"]], $header, new ArrayCollection([$facebook, $instagram, $linkedin, $github])); @@ -149,20 +139,15 @@ function makeStartPage(EntityManager $entityManager){ $entityManager->persist($new_page); /* -- table node -- */ - $entityManager->persist($head_accueil); + $entityManager->persist($head); $entityManager->persist($header); $entityManager->persist($nav); $entityManager->persist($main); $entityManager->persist($footer); $entityManager->persist($breadcrumb); - $entityManager->persist($head_login); $entityManager->persist($login); - $entityManager->persist($head_my_account); $entityManager->persist($user_edit); - $entityManager->persist($head_article); - $entityManager->persist($head_edit_menu); $entityManager->persist($bloc_edit_menu); - $entityManager->persist($head_new_page); $entityManager->persist($bloc_new_page); /* -- table image -- */ @@ -173,14 +158,9 @@ function makeStartPage(EntityManager $entityManager){ $entityManager->persist($github); /* -- table node_data -- */ - $entityManager->persist($head_accueil_data); + $entityManager->persist($head_data); $entityManager->persist($header_data); $entityManager->persist($footer_data); - $entityManager->persist($head_login_data); - $entityManager->persist($head_my_account_data); - $entityManager->persist($head_article_data); - $entityManager->persist($head_edit_menu_data); - $entityManager->persist($head_new_page_data); $entityManager->flush(); header('Location: ' . new URL); diff --git a/src/model/entities/Node.php b/src/model/entities/Node.php index db081e4..fe3a1e5 100644 --- a/src/model/entities/Node.php +++ b/src/model/entities/Node.php @@ -22,9 +22,6 @@ class Node #[ORM\Column(type: "string", length: 255)] private string $name_node; - #[ORM\Column(type: "json", nullable: true)] // type: "json" crée un longtext avec mariadb - private ?array $attributes = null; - #[ORM\Column(type: "integer")] private int $position; @@ -52,12 +49,10 @@ class Node // attributs non destinés à doctrine private array $children = []; // tableau de Node private ?self $adopted = null; // = "new" est un enfant de "main" lorsque la page est "article" - static private array $default_attributes = ['css_array' => ['body', 'head', 'nav', 'foot'],'js_array' => ['main']]; - public function __construct(string $name = '', array $attributes = [], int $position = 0, ?self $parent = null, ?Page $page = null, ?Article $article = null) + public function __construct(string $name = '', int $position = 0, ?self $parent = null, ?Page $page = null, ?Article $article = null) { $this->name_node = $name; - $this->attributes = $attributes; $this->position = $position; $this->parent = $parent; $this->page = $page; @@ -77,7 +72,8 @@ class Node { $this->name_node = $name; }*/ - public function getAttributes(): array + + /*public function getAttributes(): array { return $this->attributes; } @@ -97,7 +93,7 @@ class Node 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/model/entities/Page.php b/src/model/entities/Page.php index 5b54ae6..3e90dbc 100644 --- a/src/model/entities/Page.php +++ b/src/model/entities/Page.php @@ -31,6 +31,23 @@ class Page #[ORM\Column(type: "text")] private string $description; + #[ORM\Column(type: "json", nullable: true)] + private ?array $css = null; + + #[ORM\Column(type: "json", nullable: true)] + private ?array $js = null; + + static private array $default_css = ['body', 'head', 'nav', 'foot']; + static private array $default_js = ['main']; + + /* remplissage + UPDATE nb_page + JOIN nb_node ON nb_node.page_id = nb_page.id_page + SET nb_page.css = JSON_EXTRACT(nb_node.attributes, '$.css_array'); + UPDATE nb_page + JOIN nb_node ON nb_node.page_id = nb_page.id_page + SET nb_page.js = JSON_EXTRACT(nb_node.attributes, '$.js_array'); */ + #[ORM\Column(type: "boolean")] private bool $reachable; @@ -103,6 +120,30 @@ class Page { $this->description = $description; } + public function getCSS(): array + { + return $this->css; + } + public function useDefaultCSS(): void + { + $this->css = self::$default_css; + } + public function setCSS(array $css): void + { + $this->css = $css; + } + public function getJS(): array + { + return $this->js; + } + public function useDefaultJS(): void + { + $this->js = self::$default_js; + } + public function setJS(array $js): void + { + $this->js = $js; + } public function isReachable(): bool { return $this->reachable; diff --git a/src/view/HeadBuilder.php b/src/view/HeadBuilder.php index 4fe86ef..b1dfacb 100644 --- a/src/view/HeadBuilder.php +++ b/src/view/HeadBuilder.php @@ -14,19 +14,16 @@ class HeadBuilder extends AbstractBuilder if(file_exists($viewFile)) { // css et js - if(!empty($node->getAttributes())) - { - extract($node->getAttributes()); - } + $page = Model::$page_path->getLast(); $css = ''; - foreach($css_array as $name) + foreach($page->getCSS() as $name) { $css .= '' . "\n"; } $js = ''; - foreach($js_array as $name) + foreach($page->getJS() as $name) { $js .= '' . "\n"; } diff --git a/src/view/HeaderBuilder.php b/src/view/HeaderBuilder.php index 1b60bc9..dc4aec4 100644 --- a/src/view/HeaderBuilder.php +++ b/src/view/HeaderBuilder.php @@ -41,12 +41,6 @@ class HeaderBuilder extends AbstractBuilder extract($node->getNodeData()->getData()); } - // attributs, aucun pour l'instant - if(!empty($node->getAttributes())) - { - extract($node->getAttributes()); - } - // réseaux sociaux + logo dans l'entête $keys = array_keys($social); $social_networks = ''; diff --git a/src/view/MainBuilder.php b/src/view/MainBuilder.php index a920eb4..332efa5 100644 --- a/src/view/MainBuilder.php +++ b/src/view/MainBuilder.php @@ -27,7 +27,7 @@ class MainBuilder extends AbstractBuilder if($node->getAdoptedChild() == null){ $date = new \DateTime; $article = new Article('', $date); - $new = new Node('new', [], 0, null, null, $article); + $new = new Node('new', 0, null, null, $article); } // modification else{ diff --git a/src/view/NewBuilder.php b/src/view/NewBuilder.php index ec48541..a31a1c4 100644 --- a/src/view/NewBuilder.php +++ b/src/view/NewBuilder.php @@ -33,12 +33,6 @@ class NewBuilder extends AbstractBuilder else{ $id = (string)$node->getId(); - // id (timestamp) - if(!empty($node->getAttributes())) - { - extract($node->getAttributes()); - } - // html, date $title = $node->getArticle()->getTitle(); $preview = $node->getArticle()->getPreview(); diff --git a/src/view/PostBuilder.php b/src/view/PostBuilder.php index 70a2d77..de7a818 100644 --- a/src/view/PostBuilder.php +++ b/src/view/PostBuilder.php @@ -13,12 +13,6 @@ class PostBuilder extends AbstractBuilder if(file_exists($viewFile)) { - // id (timestamp) - if(!empty($node->getAttributes())) - { - extract($node->getAttributes()); - } - // html $title = $node->getArticle()->getTitle(); $html = $node->getArticle()->getContent(); diff --git a/src/view/templates/modify_block.php b/src/view/templates/modify_block.php index 75cb218..6b7ceb0 100644 --- a/src/view/templates/modify_block.php +++ b/src/view/templates/modify_block.php @@ -44,9 +44,6 @@ if(Blocks::hasPresentation($child_node->getName())){ pixels -
+ \ No newline at end of file -- cgit v1.2.3