diff options
author | polo <ordipolo@gmx.fr> | 2025-04-13 13:30:31 +0200 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2025-04-13 13:30:31 +0200 |
commit | 75f2c543e7fe45c1a3dcea842650a5d13a0235f0 (patch) | |
tree | 82461287eac3ae23728a74a2b90d6f574f3ddb37 /src/view | |
parent | 27bd4f380f76d5494fd9be81d3d0edac9a0aa2cc (diff) | |
download | cms-75f2c543e7fe45c1a3dcea842650a5d13a0235f0.zip |
menu et fil d'ariane gèrent le champ reachable dans page
Diffstat (limited to 'src/view')
-rw-r--r-- | src/view/BreadcrumbBuilder.php | 17 | ||||
-rw-r--r-- | src/view/NavBuilder.php | 44 |
2 files changed, 31 insertions, 30 deletions
diff --git a/src/view/BreadcrumbBuilder.php b/src/view/BreadcrumbBuilder.php index f1fdddf..77f4c4c 100644 --- a/src/view/BreadcrumbBuilder.php +++ b/src/view/BreadcrumbBuilder.php | |||
@@ -7,10 +7,10 @@ class BreadcrumbBuilder extends AbstractBuilder | |||
7 | { | 7 | { |
8 | public function __construct(Node $node) | 8 | public function __construct(Node $node) |
9 | { | 9 | { |
10 | $this->html = $this->breadcrumbHTML(false); | 10 | $this->html = $this->breadcrumbHTML(); |
11 | } | 11 | } |
12 | 12 | ||
13 | private function breadcrumbHTML(bool $links = false): string | 13 | private function breadcrumbHTML(): string |
14 | { | 14 | { |
15 | $asset = 'assets/home.svg'; // => BDD? | 15 | $asset = 'assets/home.svg'; // => BDD? |
16 | $breadcrumb_array = Director::$page_path->getArray(); // tableau de Page | 16 | $breadcrumb_array = Director::$page_path->getArray(); // tableau de Page |
@@ -23,21 +23,16 @@ class BreadcrumbBuilder extends AbstractBuilder | |||
23 | $html .= '<nav class="breadcrumb" aria-label="Breadcrumb">' . "\n"; | 23 | $html .= '<nav class="breadcrumb" aria-label="Breadcrumb">' . "\n"; |
24 | $html .= '<a href="' . new URL . '"><img src="' . $asset . '"></a><span class="arrow"> →</span>' . "\n"; | 24 | $html .= '<a href="' . new URL . '"><img src="' . $asset . '"></a><span class="arrow"> →</span>' . "\n"; |
25 | 25 | ||
26 | // partie intermédiaire | 26 | // partie intermédiaire (pas de lien sur le dernier élément) |
27 | for($i = 0; $i < ($nb_of_entries - 1); $i++) | 27 | for($i = 0; $i < ($nb_of_entries - 1); $i++) |
28 | { | 28 | { |
29 | // liens optionnels | 29 | // liens optionnels |
30 | if($links) | 30 | if($breadcrumb_array[$i]->isReachable()) |
31 | { | 31 | { |
32 | $html .= '<a href="'; | 32 | $html .= '<a href="' . new URL(['page' => $breadcrumb_array[$i]->getPagePath()]) . '">'; |
33 | for($j = 1; $j < $i; $j++) // chemin sans la fin | ||
34 | { | ||
35 | $html .= new URL(['page' => $breadcrumb_array[$i]->getPagePath()]); | ||
36 | } | ||
37 | $html .= '">'; | ||
38 | } | 33 | } |
39 | $html .= '<span>' . $breadcrumb_array[$i]->getPageName() . '</span>'; | 34 | $html .= '<span>' . $breadcrumb_array[$i]->getPageName() . '</span>'; |
40 | if($links) | 35 | if($breadcrumb_array[$i]->isReachable()) |
41 | { | 36 | { |
42 | $html .= '</a>'; | 37 | $html .= '</a>'; |
43 | } | 38 | } |
diff --git a/src/view/NavBuilder.php b/src/view/NavBuilder.php index e7254b1..2ef6bc8 100644 --- a/src/view/NavBuilder.php +++ b/src/view/NavBuilder.php | |||
@@ -22,20 +22,12 @@ class NavBuilder extends AbstractBuilder | |||
22 | 22 | ||
23 | foreach($nav_data->getChildren() as $data) | 23 | foreach($nav_data->getChildren() as $data) |
24 | { | 24 | { |
25 | $class = ''; | 25 | $li_class = ''; |
26 | if(isset($current[$level]) && $data->getEndOfPath() === $current[$level]->getEndOfPath()){ | 26 | if(isset($current[$level]) && $data->getEndOfPath() === $current[$level]->getEndOfPath()){ |
27 | $class = ' current'; | 27 | $li_class = 'current'; |
28 | } | 28 | } |
29 | 29 | ||
30 | if(count($data->getChildren()) > 0) // titre de catégorie | 30 | if($data->isReachable()) |
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 | { | 31 | { |
40 | $target = ''; | 32 | $target = ''; |
41 | if(str_starts_with($data->getEndOfPath(), 'http')) // lien vers autre site | 33 | if(str_starts_with($data->getEndOfPath(), 'http')) // lien vers autre site |
@@ -47,14 +39,28 @@ class NavBuilder extends AbstractBuilder | |||
47 | { | 39 | { |
48 | $link = new URL(['page' => $data->getPagePath()]); // $link = objet | 40 | $link = new URL(['page' => $data->getPagePath()]); // $link = objet |
49 | } | 41 | } |
50 | /*else | 42 | $nav_html .= '<a href="' . $link . '"' . $target . '>'; |
51 | { | 43 | } |
52 | echo "else page d'accueil" . '<br>'; | 44 | else{ |
53 | $link = new URL; // page d'accueil | 45 | $nav_html .= '<a>'; |
54 | }*/ | ||
55 | |||
56 | $nav_html .= '<a href="' . $link . '"' . $target . '><li class="'. $class . '"><p>' . $data->getPageName() . '</p></li></a>' . "\n"; | ||
57 | } | 46 | } |
47 | |||
48 | if(count($data->getChildren()) > 0) // titre de catégorie | ||
49 | { | ||
50 | $li_class = $data->getParent() == null ? 'drop-down' : 'drop-right'; | ||
51 | |||
52 | $nav_html .= '<li class="'. $li_class . '"><p>' . $data->getPageName() . '</p><ul class="sub-menu">' . "\n"; | ||
53 | $level++; | ||
54 | $nav_html .= $this->navMainHTML($data, $current); | ||
55 | $level--; | ||
56 | $nav_html .= '</ul></li>' . "\n"; | ||
57 | } | ||
58 | else | ||
59 | { | ||
60 | $nav_html .= '<li class="'. $li_class . '"><p>' . $data->getPageName() . '</p></li>' . "\n"; | ||
61 | } | ||
62 | |||
63 | $nav_html .= "</a>\n"; | ||
58 | } | 64 | } |
59 | return $nav_html; | 65 | return $nav_html; |
60 | } | 66 | } |