From a3ba7dde60dc1c94b7170ec28266a966e5004d33 Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 22 Apr 2025 00:39:54 +0200 Subject: page menu et chemin, partie 2 --- src/controller/ajax.php | 34 +++++++++++++++++++------- src/model/Menu.php | 6 ----- src/model/entities/Page.php | 14 ++++++++++- src/view/MenuBuilder.php | 9 +------ src/view/NavBuilder.php | 59 ++++++++++++++++++++++++--------------------- 5 files changed, 70 insertions(+), 52 deletions(-) (limited to 'src') diff --git a/src/controller/ajax.php b/src/controller/ajax.php index c774bf3..9d1cc42 100644 --- a/src/controller/ajax.php +++ b/src/controller/ajax.php @@ -209,12 +209,10 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['menu_edit'])) // récupération des données $data = file_get_contents('php://input'); $json = json_decode($data, true); + Director::$menu_data = new Menu($entityManager); if($_GET['menu_edit'] === 'switch_positions' && isset($json['id1']) && isset($json['id2'])) { - //$menu = new Menu($entityManager); - Director::$menu_data = new Menu($entityManager); - $id1 = $json['id1']; $id2 = $json['id2']; @@ -232,11 +230,9 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['menu_edit'])) Director::$menu_data->sortChildren(true); // modifie tableau children $entityManager->flush(); - // menu utilisant les nouvelles données - //Director::$page_path = new Path(); - $nav_builder = new NavBuilder(); // builder appelé sans envoi du noeud correspondant - - echo json_encode(['success' => true, 'path1' => '', 'path2' => '', 'nav' => $nav_builder->render()]); + // nouveau menu + $nav_builder = new NavBuilder(); + echo json_encode(['success' => true, 'nav' => $nav_builder->render()]); } else{ echo json_encode(['success' => false]); @@ -244,9 +240,29 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['menu_edit'])) die; } + + if($_GET['menu_edit'] === 'displayInMenu' && isset($json['id']) && isset($json['checked'])) + { + $id = $json['id']; + $checked = $json['checked']; + + $page = Director::$menu_data->findPageById((int)$id); + if($page->isHidden() === $checked){ + $page->setHidden(!$checked); + $entityManager->flush(); + + // nouveau menu + $nav_builder = new NavBuilder(); + echo json_encode(['success' => true, 'nav' => $nav_builder->render()]); + } + else{ + echo json_encode(['success' => false]); + } + die; + } } -// détection des requêtes de type XHR, pas d'utilité pour l'instant +// détection des requêtes de type XHR?, pas d'utilité pour l'instant /*elseif(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'){ echo "requête XHR reçue par le serveur"; die; diff --git a/src/model/Menu.php b/src/model/Menu.php index 403accf..10cf3d5 100644 --- a/src/model/Menu.php +++ b/src/model/Menu.php @@ -38,12 +38,6 @@ class Menu extends Page foreach($this->getChildren() as $page){ $page->fillChildrenPagePath(); } - - /*for($i = 0; $i < count($this->getChildren()[1]->getChildren()); $i++){ - echo $this->getChildren()[1]->getChildren()[$i]->getEndOfPath() . ' - '; - echo $this->getChildren()[1]->getChildren()[$i]->getPageName() . '
'; - }*/ - //die; } public function getOtherPages(): array diff --git a/src/model/entities/Page.php b/src/model/entities/Page.php index c30305c..e3e60ca 100644 --- a/src/model/entities/Page.php +++ b/src/model/entities/Page.php @@ -34,6 +34,9 @@ class Page #[ORM\Column(type: "boolean")] private bool $in_menu; + #[ORM\Column(type: "boolean")] + private bool $hidden; + #[ORM\Column(type: "integer", nullable: true)] // null si hors menu private ?int $position; @@ -47,12 +50,13 @@ class Page /*#[ORM\Column(type: "json", nullable: true)] private ?array $metadata = null;*/ - public function __construct(string $name, string $eop, bool $reachable, bool $in_menu, ?int $position, ?Page $parent) + public function __construct(string $name, string $eop, bool $reachable, bool $in_menu, bool $hidden, ?int $position, ?Page $parent) { $this->name_page = $name; $this->end_of_path = $eop; $this->reachable = $reachable; $this->in_menu = $in_menu; + $this->hidden = $hidden; $this->position = $position; $this->parent = $parent; $this->children = new ArrayCollection(); @@ -83,6 +87,14 @@ class Page { return $this->in_menu; } + public function isHidden(): bool + { + return $this->hidden; + } + public function setHidden(bool $hidden): void + { + $this->hidden = $hidden; + } public function getPosition(): ?int { return $this->position; diff --git a/src/view/MenuBuilder.php b/src/view/MenuBuilder.php index 0fcfbe5..5a010d5 100644 --- a/src/view/MenuBuilder.php +++ b/src/view/MenuBuilder.php @@ -22,8 +22,6 @@ class MenuBuilder extends AbstractBuilder extract($node->getNodeData()->getData()); }*/ - // ajouter un article - $new_article = ''; if($_SESSION['admin']) { $this->unfoldMenu(Director::$menu_data, 0 - $this->margin_left_multiplier); @@ -47,7 +45,7 @@ class MenuBuilder extends AbstractBuilder foreach($menu->getChildren() as $entry) { $div_style = 'margin-left: ' . $margin_left . 'px;'; - $checked = $entry->IsInMenu() ? 'checked' : ''; + $checked = $entry->isHidden() ? '' : 'checked'; $this->html .= '
@@ -67,14 +65,9 @@ class MenuBuilder extends AbstractBuilder $this->html .= '' . $entry->getPagePath() . ''; } - - // supprimer me label "visible" et griser le texte et bouton en JS à la place - /* => flèche gauche: position = position du parent + 1, parent = grand-parent, recalculer les positions => flèche droite: position = nombre d'éléments de la fraterie + 1, l'élément précédent devient le parent - => flèches haut et bas: inversement de position, comme pour les noeuds, mais dans la table page - => checkbox: in_menu ^= 1 */ if(count($entry->getChildren()) > 0){ diff --git a/src/view/NavBuilder.php b/src/view/NavBuilder.php index 2718569..f4fb651 100644 --- a/src/view/NavBuilder.php +++ b/src/view/NavBuilder.php @@ -27,41 +27,44 @@ class NavBuilder extends AbstractBuilder foreach($nav_data->getChildren() as $data) { - $li_class = ''; - if(isset($current[$level]) && $data->getEndOfPath() === $current[$level]->getEndOfPath()){ - $li_class = 'current '; - } + if(!$data->isHidden()){ + $li_class = ''; + if(isset($current[$level]) && $data->getEndOfPath() === $current[$level]->getEndOfPath()){ + $li_class = 'current '; + } - $link = ''; - if($data->isReachable()) - { - if(str_starts_with($data->getEndOfPath(), 'http')) // lien vers autre site + $link = ''; + if($data->isReachable()) // titre de catégorie du menu non clicable { - $link .= ''; + if(str_starts_with($data->getEndOfPath(), 'http')) // lien vers autre site + { + $link .= ''; + } + elseif($data->getEndOfPath() != '') // lien relatif + { + $link .= ''; + } + } + else{ + $link .= ''; } - elseif($data->getEndOfPath() != '') // lien relatif + + if(count($data->getChildren()) > 0) // titre de catégorie { - $link .= ''; + $li_class .= $data->getParent() == null ? 'drop-down' : 'drop-right'; + + $nav_html .= '
  • ' . $link . '

    ' . $data->getPageName() . '

  • ' . "\n"; + } + else + { + $nav_html .= '
  • ' . $link . '

    ' . $data->getPageName() . '

  • ' . "\n"; } - } - else{ - $link .= ''; } - if(count($data->getChildren()) > 0) // titre de catégorie - { - $li_class .= $data->getParent() == null ? 'drop-down' : 'drop-right'; - - $nav_html .= '
  • ' . $link . '

    ' . $data->getPageName() . '

  • ' . "\n"; - } - else - { - $nav_html .= '
  • ' . $link . '

    ' . $data->getPageName() . '

  • ' . "\n"; - } } return $nav_html; } -- cgit v1.2.3