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