summaryrefslogtreecommitdiff
path: root/src/view/NavBuilder.php
diff options
context:
space:
mode:
authorpolo-pc-greta <ordipolo@gmx.fr>2025-03-27 10:13:03 +0100
committerpolo-pc-greta <ordipolo@gmx.fr>2025-03-27 10:13:03 +0100
commitdf3612ed7e6691530503f79483d2fdbc032d01b8 (patch)
tree56d1c68fdc8625f5dad1937a654299d45142c79a /src/view/NavBuilder.php
downloadcms-df3612ed7e6691530503f79483d2fdbc032d01b8.zip
mise en ligne github
Diffstat (limited to 'src/view/NavBuilder.php')
-rw-r--r--src/view/NavBuilder.php61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/view/NavBuilder.php b/src/view/NavBuilder.php
new file mode 100644
index 0000000..e7254b1
--- /dev/null
+++ b/src/view/NavBuilder.php
@@ -0,0 +1,61 @@
1<?php
2// src/view/NavBuilder.php
3
4declare(strict_types=1);
5
6use App\Entity\Node;
7use App\Entity\Page;
8
9class NavBuilder extends AbstractBuilder
10{
11 public function __construct(Node $node)
12 {
13 $this->html .= '<nav class="nav_main"><ul>';
14 $this->html .= $this->navMainHTML(Director::$menu_data, Director::$page_path->getArray());
15 $this->html .= '</ul></nav>';
16 }
17
18 private function navMainHTML(Page $nav_data, array $current): string
19 {
20 $nav_html = '';
21 static $level = 0;
22
23 foreach($nav_data->getChildren() as $data)
24 {
25 $class = '';
26 if(isset($current[$level]) && $data->getEndOfPath() === $current[$level]->getEndOfPath()){
27 $class = ' current';
28 }
29
30 if(count($data->getChildren()) > 0) // titre de catégorie
31 {
32 $nav_html .= '<li class="drop-down'. $class . '"><p>' . $data->getPageName() . '</p><ul class="sub-menu">' . "\n";
33 $level++;
34 $nav_html .= $this->navMainHTML($data, $current);
35 $level--;
36 $nav_html .= '</ul></li>' . "\n";
37 }
38 else
39 {
40 $target = '';
41 if(str_starts_with($data->getEndOfPath(), 'http')) // lien vers autre site
42 {
43 $link = $data->getEndOfPath(); // $link = chaine
44 $target = ' target="_blank"';
45 }
46 elseif($data->getEndOfPath() != '') // lien relatif
47 {
48 $link = new URL(['page' => $data->getPagePath()]); // $link = objet
49 }
50 /*else
51 {
52 echo "else page d'accueil" . '<br>';
53 $link = new URL; // page d'accueil
54 }*/
55
56 $nav_html .= '<a href="' . $link . '"' . $target . '><li class="'. $class . '"><p>' . $data->getPageName() . '</p></li></a>' . "\n";
57 }
58 }
59 return $nav_html;
60 }
61} \ No newline at end of file