aboutsummaryrefslogtreecommitdiff
path: root/src/View/HeaderBuilder.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/View/HeaderBuilder.php')
-rw-r--r--src/View/HeaderBuilder.php131
1 files changed, 131 insertions, 0 deletions
diff --git a/src/View/HeaderBuilder.php b/src/View/HeaderBuilder.php
new file mode 100644
index 0000000..14f5ffa
--- /dev/null
+++ b/src/View/HeaderBuilder.php
@@ -0,0 +1,131 @@
1<?php
2// src/View/HeaderBuilder.php
3
4declare(strict_types=1);
5
6namespace App\View;
7
8use App\Entity\Node;
9use App\Entity\NodeData;
10use App\Entity\Asset;
11
12class HeaderBuilder extends AbstractBuilder
13{
14 //private ?Node $nav = null;
15 //private ?Node $breadcrumb = null;
16 const ICON_PATH = 'icons/';
17
18 public function __construct(Node $node)
19 {
20 // pas de useChildrenBuilder, il faudrait peut-être
21 $children = $node->getChildren();
22 foreach($children as $child)
23 {
24 if($child->getName() === 'nav'){
25 //$this->nav = $child;
26 // actuellement le noeud nav ne contient aucune info utile et l'envoyer à NavBuilder est inutile
27 $nav_builder = new NavBuilder(/*$this->nav*/);
28
29 $nav = $nav_builder->render();
30 }
31 elseif($child->getName() === 'breadcrumb'){
32 //$this->breadcrumb = $child;
33 $breadcrumb_builder = new BreadcrumbBuilder(/*$this->breadcrumb*/);
34 $breadcrumb = $breadcrumb_builder->render();
35 }
36 }
37
38 $viewFile = self::VIEWS_PATH . $node->getName() . '.php';
39
40 if(file_exists($viewFile))
41 {
42 $node_data = $node->getNodeData();
43 // titre et description
44 if(!empty($node_data->getData()))
45 {
46 extract($node_data->getData());
47 }
48
49 // réseaux sociaux + logo dans l'entête
50 // ?-> est l'opérateur de chainage optionnel
51 $header_logo = Asset::USER_PATH . $node_data->getAssetByRole('header_logo')?->getFileName() ?? '';
52 $header_background_name = $node_data->getAssetByRole('header_background')?->getFileName();
53 $header_background = $header_background_name ? Asset::USER_PATH . $header_background_name : '';
54 $social_networks = '';
55
56 // boutons mode admin
57 if(IS_ADMIN){
58 // assets dans classe header_additional_inputs
59 $admin_head_favicon = '<input type="file" id="head_favicon_input" class="hidden" accept="image/png, image/jpeg, image/gif, image/webp, image/tiff, image/x-icon, image/bmp">
60 <button id="head_favicon_open" onclick="head_favicon.open()"><img id="head_favicon_content" class="action_icon"> Favicon</button>
61 <img id="head_favicon_submit" class="action_icon hidden" src="assets/save.svg" onclick="head_favicon.submit()">
62 <img id="head_favicon_cancel" class="action_icon hidden" src="assets/close.svg" onclick="head_favicon.cancel()">';
63 $admin_header_background = '<input type="file" id="header_background_input" class="hidden" accept="image/png, image/jpeg, image/gif, image/webp, image/tiff">
64 <button id="header_background_open" onclick="header_background.open()"><img id="header_background_content" class="background_button" src="' . $header_background . '"> Image de fond</button>
65 <img id="header_background_submit" class="action_icon hidden" src="assets/save.svg" onclick="header_background.submit()">
66 <img id="header_background_cancel" class="action_icon hidden" src="assets/close.svg" onclick="header_background.cancel()">';
67
68 // asset dans classe header_content
69 $admin_header_logo = '<input type="file" id="header_logo_input" class="hidden" accept="image/png, image/jpeg, image/gif, image/webp, image/tiff">
70 <img id="header_logo_open" class="action_icon" src="assets/edit.svg" onclick="header_logo.open()">
71 <img id="header_logo_submit" class="action_icon hidden" src="assets/save.svg" onclick="header_logo.submit()">
72 <img id="header_logo_cancel" class="action_icon hidden" src="assets/close.svg" onclick="header_logo.cancel()">';
73
74 // texte dans classe header_content
75 $admin_header_title = '<input type="text" id="header_title_input" class="hidden" value="' . htmlspecialchars($title ?? '') . '" placeholder="nom du site web" size="30">
76 <img id="header_title_open" class="action_icon" src="assets/edit.svg" onclick="header_title.open()">
77 <img id="header_title_submit" class="action_icon hidden" src="assets/save.svg" onclick="header_title.submit()">
78 <img id="header_title_cancel" class="action_icon hidden" src="assets/close.svg" onclick="header_title.cancel()">';
79 $admin_header_description = '<input type="text" id="header_description_input" class="hidden" value="' . htmlspecialchars($description ?? '') . '" placeholder="sous-titre ou description" size="30">
80 <img id="header_description_open" class="action_icon" src="assets/edit.svg" onclick="header_description.open()">
81 <img id="header_description_submit" class="action_icon hidden" src="assets/save.svg" onclick="header_description.submit()">
82 <img id="header_description_cancel" class="action_icon hidden" src="assets/close.svg" onclick="header_description.cancel()">';
83
84 // icônes réseaux sociaux
85 // boucle sur la liste complète de réseaux sociaux
86 foreach(NodeData::$social_networks as $network){
87 $checked = (isset($social_show[$network]) && $social_show[$network]) ? 'checked' : '';
88 $href = (isset($social[$network]) && $social[$network] !== '') ? 'href="' . $social[$network] . '"' : '';
89
90 $social_networks .= '<div id="header_' . $network . '">
91 <input type="checkbox" onclick="checkSocialNetwork(\'header_' . $network . '\')" ' . $checked . '>
92 <a ' . $href . ' target="_blank" rel="noopener noreferrer">'
93 . $this->insertSVG(self::ICON_PATH . $network . '.svg', ['id' => 'header_' . $network . '_content', 'class' => ($checked ? 'svg_fill_red' : '')])
94 . '</a>
95 <input type="url" id="header_' . $network . '_input" class="hidden" value="' . ($social[$network] ?? "") . '" placeholder="https://..." size="30" onchange="controlURL(this)">
96 <img id="header_' . $network . '_open" class="action_icon" src="assets/edit.svg" onclick="header_' . $network . '.open()">
97 <img id="header_' . $network . '_submit" class="action_icon hidden" src="assets/save.svg" onclick="header_' . $network . '.submit()">
98 <img id="header_' . $network . '_cancel" class="action_icon hidden" src="assets/close.svg" onclick="header_' . $network . '.cancel()">
99 <script>let header_' . $network . ' = new InputTextSocialNetwork(\'header_' . $network . '\', {\'has_content\': false});</script>
100 </div>';
101 // {'has_content': false} => InputToggle ne gèrera pas cette balise
102 }
103 }
104 else{
105 $admin_head_favicon = '';
106 $admin_header_background = '';
107 $admin_header_logo = '';
108 $admin_header_title = '';
109 $admin_header_description = '';
110
111 if(isset($social_show)){
112 // boucle sur les réseaux sociaux "activés"
113 foreach(array_keys($social_show) as $network){
114 if($social_show[$network]){
115 $href = (isset($social[$network]) && $social[$network] !== '') ? 'href="' . $social[$network] . '"' : '';
116 $social_networks .= '<div id="header_' . $network . '">
117 <a ' . $href . ' target="_blank" rel="noopener noreferrer">'
118 . $this->insertSVG(self::ICON_PATH . $network . '.svg', ['id' => 'header_' . $network . '_content','class' => 'svg_fill_red'])
119 . '</a>
120 </div>';
121 }
122 }
123 }
124 }
125
126 ob_start();
127 require $viewFile;
128 $this->html .= ob_get_clean();
129 }
130 }
131} \ No newline at end of file