aboutsummaryrefslogtreecommitdiff
path: root/src/View/NavBuilder.php
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2026-10-23 00:47:32 +0200
committerpolo <ordipolo@gmx.fr>2026-10-23 00:47:32 +0200
commitf27cca08ff786ceff1870147f6d6bad14d71117f (patch)
treed36597a72025313d6faf4ed228755fa267ebe2f6 /src/View/NavBuilder.php
parentc7309f900ef05bd5cb313110ec159b761af394ec (diff)
downloadcms-f27cca08ff786ceff1870147f6d6bad14d71117f.tar.gz
cms-f27cca08ff786ceff1870147f6d6bad14d71117f.tar.bz2
cms-f27cca08ff786ceff1870147f6d6bad14d71117f.zip
dossiers avec majuscule, namespace pour toutes les classes, autoload psr-4, UserDataService::createZip déplacé dans Backup
Diffstat (limited to 'src/View/NavBuilder.php')
-rw-r--r--src/View/NavBuilder.php77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/View/NavBuilder.php b/src/View/NavBuilder.php
new file mode 100644
index 0000000..2e3cdbd
--- /dev/null
+++ b/src/View/NavBuilder.php
@@ -0,0 +1,77 @@
1<?php
2// src/View/NavBuilder.php
3//
4// menu principal
5
6declare(strict_types=1);
7
8namespace App\View;
9
10//use App\Entity\Node;
11use App\Entity\Page;
12use App\Model\Model;
13use App\Service\URL;
14
15class NavBuilder extends AbstractBuilder
16{
17 public function __construct(/*?Node $node = null*/)
18 {
19 $this->html .= '<nav class="nav_main"><ul>';
20 if(count(Model::$menu->getChildren()) > 1 || !Model::$menu->getChildren()[0]->getChildren()->isEmpty()){
21 $this->html .= $this->navMainHTML(
22 Model::$menu, // Menu étend Page
23 Model::$page_path != null ? Model::$page_path->getArray() : []); // param nullable, ça retire une dépendance stricte entre NavBuilder et Model
24 }
25 $this->html .= '</ul></nav>';
26 }
27
28 private function navMainHTML(Page $nav_data, array $current): string
29 {
30 $nav_html = '';
31 static $level = 0;
32
33 foreach($nav_data->getChildren() as $data)
34 {
35 if(!$data->isHidden()){
36 $li_class = '';
37 if(isset($current[$level]) && $data->getEndOfPath() === $current[$level]->getEndOfPath()){
38 $li_class = 'current ';
39 }
40
41 $link = '';
42 if($data->isReachable()) // titre de catégorie du menu non clicable
43 {
44 if(str_starts_with($data->getEndOfPath(), 'http')) // lien vers autre site
45 {
46 $link .= '<a href="' . htmlspecialchars($data->getEndOfPath()) . '" target="_blank">';
47 }
48 elseif($data->getEndOfPath() != '') // lien relatif
49 {
50 $link .= '<a href="' . new URL(['page' => $data->getPagePath()]) . '">';
51 }
52 }
53 else{
54 $link .= '<a>';
55 }
56
57 if(count($data->getChildren()) > 0) // titre de catégorie
58 {
59 $li_class .= $data->getParent() == null ? 'drop-down' : 'drop-right';
60
61 $nav_html .= '<li class="'. $li_class . '">' . $link . '<p id="m_' . $data->getId() . '">' . $data->getPageName() . '</p></a>
62 <button class="sub-menu-toggle" aria-label="Ouvrir le sous-menu">▼</button>
63 <ul class="sub-menu">' . "\n";
64 $level++;
65 $nav_html .= $this->navMainHTML($data, $current);
66 $level--;
67 $nav_html .= '</ul></li>' . "\n";
68 }
69 else
70 {
71 $nav_html .= '<li class="'. $li_class . '">' . $link . '<p id="m_' . $data->getId() . '">' . $data->getPageName() . '</p></a></li>' . "\n";
72 }
73 }
74 }
75 return $nav_html;
76 }
77} \ No newline at end of file