blob: e7254b1248aefd0f707ff8d7e25f027ba546fccc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
<?php
// src/view/NavBuilder.php
declare(strict_types=1);
use App\Entity\Node;
use App\Entity\Page;
class NavBuilder extends AbstractBuilder
{
public function __construct(Node $node)
{
$this->html .= '<nav class="nav_main"><ul>';
$this->html .= $this->navMainHTML(Director::$menu_data, Director::$page_path->getArray());
$this->html .= '</ul></nav>';
}
private function navMainHTML(Page $nav_data, array $current): string
{
$nav_html = '';
static $level = 0;
foreach($nav_data->getChildren() as $data)
{
$class = '';
if(isset($current[$level]) && $data->getEndOfPath() === $current[$level]->getEndOfPath()){
$class = ' current';
}
if(count($data->getChildren()) > 0) // titre de catégorie
{
$nav_html .= '<li class="drop-down'. $class . '"><p>' . $data->getPageName() . '</p><ul class="sub-menu">' . "\n";
$level++;
$nav_html .= $this->navMainHTML($data, $current);
$level--;
$nav_html .= '</ul></li>' . "\n";
}
else
{
$target = '';
if(str_starts_with($data->getEndOfPath(), 'http')) // lien vers autre site
{
$link = $data->getEndOfPath(); // $link = chaine
$target = ' target="_blank"';
}
elseif($data->getEndOfPath() != '') // lien relatif
{
$link = new URL(['page' => $data->getPagePath()]); // $link = objet
}
/*else
{
echo "else page d'accueil" . '<br>';
$link = new URL; // page d'accueil
}*/
$nav_html .= '<a href="' . $link . '"' . $target . '><li class="'. $class . '"><p>' . $data->getPageName() . '</p></li></a>' . "\n";
}
}
return $nav_html;
}
}
|