diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/controller/ajax.php | 34 | ||||
| -rw-r--r-- | src/model/Menu.php | 6 | ||||
| -rw-r--r-- | src/model/entities/Page.php | 14 | ||||
| -rw-r--r-- | src/view/MenuBuilder.php | 9 | ||||
| -rw-r--r-- | src/view/NavBuilder.php | 59 |
5 files changed, 70 insertions, 52 deletions
diff --git a/src/controller/ajax.php b/src/controller/ajax.php index c774bf3..9d1cc42 100644 --- a/src/controller/ajax.php +++ b/src/controller/ajax.php | |||
| @@ -209,12 +209,10 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['menu_edit'])) | |||
| 209 | // récupération des données | 209 | // récupération des données |
| 210 | $data = file_get_contents('php://input'); | 210 | $data = file_get_contents('php://input'); |
| 211 | $json = json_decode($data, true); | 211 | $json = json_decode($data, true); |
| 212 | Director::$menu_data = new Menu($entityManager); | ||
| 212 | 213 | ||
| 213 | if($_GET['menu_edit'] === 'switch_positions' && isset($json['id1']) && isset($json['id2'])) | 214 | if($_GET['menu_edit'] === 'switch_positions' && isset($json['id1']) && isset($json['id2'])) |
| 214 | { | 215 | { |
| 215 | //$menu = new Menu($entityManager); | ||
| 216 | Director::$menu_data = new Menu($entityManager); | ||
| 217 | |||
| 218 | $id1 = $json['id1']; | 216 | $id1 = $json['id1']; |
| 219 | $id2 = $json['id2']; | 217 | $id2 = $json['id2']; |
| 220 | 218 | ||
| @@ -232,11 +230,9 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['menu_edit'])) | |||
| 232 | Director::$menu_data->sortChildren(true); // modifie tableau children | 230 | Director::$menu_data->sortChildren(true); // modifie tableau children |
| 233 | $entityManager->flush(); | 231 | $entityManager->flush(); |
| 234 | 232 | ||
| 235 | // menu utilisant les nouvelles données | 233 | // nouveau menu |
| 236 | //Director::$page_path = new Path(); | 234 | $nav_builder = new NavBuilder(); |
| 237 | $nav_builder = new NavBuilder(); // builder appelé sans envoi du noeud correspondant | 235 | echo json_encode(['success' => true, 'nav' => $nav_builder->render()]); |
| 238 | |||
| 239 | echo json_encode(['success' => true, 'path1' => '', 'path2' => '', 'nav' => $nav_builder->render()]); | ||
| 240 | } | 236 | } |
| 241 | else{ | 237 | else{ |
| 242 | echo json_encode(['success' => false]); | 238 | echo json_encode(['success' => false]); |
| @@ -244,9 +240,29 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['menu_edit'])) | |||
| 244 | 240 | ||
| 245 | die; | 241 | die; |
| 246 | } | 242 | } |
| 243 | |||
| 244 | if($_GET['menu_edit'] === 'displayInMenu' && isset($json['id']) && isset($json['checked'])) | ||
| 245 | { | ||
| 246 | $id = $json['id']; | ||
| 247 | $checked = $json['checked']; | ||
| 248 | |||
| 249 | $page = Director::$menu_data->findPageById((int)$id); | ||
| 250 | if($page->isHidden() === $checked){ | ||
| 251 | $page->setHidden(!$checked); | ||
| 252 | $entityManager->flush(); | ||
| 253 | |||
| 254 | // nouveau menu | ||
| 255 | $nav_builder = new NavBuilder(); | ||
| 256 | echo json_encode(['success' => true, 'nav' => $nav_builder->render()]); | ||
| 257 | } | ||
| 258 | else{ | ||
| 259 | echo json_encode(['success' => false]); | ||
| 260 | } | ||
| 261 | die; | ||
| 262 | } | ||
| 247 | } | 263 | } |
| 248 | 264 | ||
| 249 | // détection des requêtes de type XHR, pas d'utilité pour l'instant | 265 | // détection des requêtes de type XHR?, pas d'utilité pour l'instant |
| 250 | /*elseif(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'){ | 266 | /*elseif(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'){ |
| 251 | echo "requête XHR reçue par le serveur"; | 267 | echo "requête XHR reçue par le serveur"; |
| 252 | die; | 268 | die; |
diff --git a/src/model/Menu.php b/src/model/Menu.php index 403accf..10cf3d5 100644 --- a/src/model/Menu.php +++ b/src/model/Menu.php | |||
| @@ -38,12 +38,6 @@ class Menu extends Page | |||
| 38 | foreach($this->getChildren() as $page){ | 38 | foreach($this->getChildren() as $page){ |
| 39 | $page->fillChildrenPagePath(); | 39 | $page->fillChildrenPagePath(); |
| 40 | } | 40 | } |
| 41 | |||
| 42 | /*for($i = 0; $i < count($this->getChildren()[1]->getChildren()); $i++){ | ||
| 43 | echo $this->getChildren()[1]->getChildren()[$i]->getEndOfPath() . ' - '; | ||
| 44 | echo $this->getChildren()[1]->getChildren()[$i]->getPageName() . '<br>'; | ||
| 45 | }*/ | ||
| 46 | //die; | ||
| 47 | } | 41 | } |
| 48 | 42 | ||
| 49 | public function getOtherPages(): array | 43 | public function getOtherPages(): array |
diff --git a/src/model/entities/Page.php b/src/model/entities/Page.php index c30305c..e3e60ca 100644 --- a/src/model/entities/Page.php +++ b/src/model/entities/Page.php | |||
| @@ -34,6 +34,9 @@ class Page | |||
| 34 | #[ORM\Column(type: "boolean")] | 34 | #[ORM\Column(type: "boolean")] |
| 35 | private bool $in_menu; | 35 | private bool $in_menu; |
| 36 | 36 | ||
| 37 | #[ORM\Column(type: "boolean")] | ||
| 38 | private bool $hidden; | ||
| 39 | |||
| 37 | #[ORM\Column(type: "integer", nullable: true)] // null si hors menu | 40 | #[ORM\Column(type: "integer", nullable: true)] // null si hors menu |
| 38 | private ?int $position; | 41 | private ?int $position; |
| 39 | 42 | ||
| @@ -47,12 +50,13 @@ class Page | |||
| 47 | /*#[ORM\Column(type: "json", nullable: true)] | 50 | /*#[ORM\Column(type: "json", nullable: true)] |
| 48 | private ?array $metadata = null;*/ | 51 | private ?array $metadata = null;*/ |
| 49 | 52 | ||
| 50 | public function __construct(string $name, string $eop, bool $reachable, bool $in_menu, ?int $position, ?Page $parent) | 53 | public function __construct(string $name, string $eop, bool $reachable, bool $in_menu, bool $hidden, ?int $position, ?Page $parent) |
| 51 | { | 54 | { |
| 52 | $this->name_page = $name; | 55 | $this->name_page = $name; |
| 53 | $this->end_of_path = $eop; | 56 | $this->end_of_path = $eop; |
| 54 | $this->reachable = $reachable; | 57 | $this->reachable = $reachable; |
| 55 | $this->in_menu = $in_menu; | 58 | $this->in_menu = $in_menu; |
| 59 | $this->hidden = $hidden; | ||
| 56 | $this->position = $position; | 60 | $this->position = $position; |
| 57 | $this->parent = $parent; | 61 | $this->parent = $parent; |
| 58 | $this->children = new ArrayCollection(); | 62 | $this->children = new ArrayCollection(); |
| @@ -83,6 +87,14 @@ class Page | |||
| 83 | { | 87 | { |
| 84 | return $this->in_menu; | 88 | return $this->in_menu; |
| 85 | } | 89 | } |
| 90 | public function isHidden(): bool | ||
| 91 | { | ||
| 92 | return $this->hidden; | ||
| 93 | } | ||
| 94 | public function setHidden(bool $hidden): void | ||
| 95 | { | ||
| 96 | $this->hidden = $hidden; | ||
| 97 | } | ||
| 86 | public function getPosition(): ?int | 98 | public function getPosition(): ?int |
| 87 | { | 99 | { |
| 88 | return $this->position; | 100 | return $this->position; |
diff --git a/src/view/MenuBuilder.php b/src/view/MenuBuilder.php index 0fcfbe5..5a010d5 100644 --- a/src/view/MenuBuilder.php +++ b/src/view/MenuBuilder.php | |||
| @@ -22,8 +22,6 @@ class MenuBuilder extends AbstractBuilder | |||
| 22 | extract($node->getNodeData()->getData()); | 22 | extract($node->getNodeData()->getData()); |
| 23 | }*/ | 23 | }*/ |
| 24 | 24 | ||
| 25 | // ajouter un article | ||
| 26 | $new_article = ''; | ||
| 27 | if($_SESSION['admin']) | 25 | if($_SESSION['admin']) |
| 28 | { | 26 | { |
| 29 | $this->unfoldMenu(Director::$menu_data, 0 - $this->margin_left_multiplier); | 27 | $this->unfoldMenu(Director::$menu_data, 0 - $this->margin_left_multiplier); |
| @@ -47,7 +45,7 @@ class MenuBuilder extends AbstractBuilder | |||
| 47 | foreach($menu->getChildren() as $entry) | 45 | foreach($menu->getChildren() as $entry) |
| 48 | { | 46 | { |
| 49 | $div_style = 'margin-left: ' . $margin_left . 'px;'; | 47 | $div_style = 'margin-left: ' . $margin_left . 'px;'; |
| 50 | $checked = $entry->IsInMenu() ? 'checked' : ''; | 48 | $checked = $entry->isHidden() ? '' : 'checked'; |
| 51 | $this->html .= '<div id="' . $entry->getId() . '" style="' . $div_style . '"> | 49 | $this->html .= '<div id="' . $entry->getId() . '" style="' . $div_style . '"> |
| 52 | <img class="move_entry_icon" onclick="" src="assets/arrow-left.svg"> | 50 | <img class="move_entry_icon" onclick="" src="assets/arrow-left.svg"> |
| 53 | <img class="move_entry_icon" onclick="" src="assets/arrow-right.svg"> | 51 | <img class="move_entry_icon" onclick="" src="assets/arrow-right.svg"> |
| @@ -67,14 +65,9 @@ class MenuBuilder extends AbstractBuilder | |||
| 67 | $this->html .= '<i>' . $entry->getPagePath() . '</i>'; | 65 | $this->html .= '<i>' . $entry->getPagePath() . '</i>'; |
| 68 | } | 66 | } |
| 69 | 67 | ||
| 70 | |||
| 71 | // supprimer me label "visible" et griser le texte et bouton en JS à la place | ||
| 72 | |||
| 73 | /* | 68 | /* |
| 74 | => flèche gauche: position = position du parent + 1, parent = grand-parent, recalculer les positions | 69 | => flèche gauche: position = position du parent + 1, parent = grand-parent, recalculer les positions |
| 75 | => flèche droite: position = nombre d'éléments de la fraterie + 1, l'élément précédent devient le parent | 70 | => flèche droite: position = nombre d'éléments de la fraterie + 1, l'élément précédent devient le parent |
| 76 | => flèches haut et bas: inversement de position, comme pour les noeuds, mais dans la table page | ||
| 77 | => checkbox: in_menu ^= 1 | ||
| 78 | */ | 71 | */ |
| 79 | 72 | ||
| 80 | if(count($entry->getChildren()) > 0){ | 73 | if(count($entry->getChildren()) > 0){ |
diff --git a/src/view/NavBuilder.php b/src/view/NavBuilder.php index 2718569..f4fb651 100644 --- a/src/view/NavBuilder.php +++ b/src/view/NavBuilder.php | |||
| @@ -27,41 +27,44 @@ class NavBuilder extends AbstractBuilder | |||
| 27 | 27 | ||
| 28 | foreach($nav_data->getChildren() as $data) | 28 | foreach($nav_data->getChildren() as $data) |
| 29 | { | 29 | { |
| 30 | $li_class = ''; | 30 | if(!$data->isHidden()){ |
| 31 | if(isset($current[$level]) && $data->getEndOfPath() === $current[$level]->getEndOfPath()){ | 31 | $li_class = ''; |
| 32 | $li_class = 'current '; | 32 | if(isset($current[$level]) && $data->getEndOfPath() === $current[$level]->getEndOfPath()){ |
| 33 | } | 33 | $li_class = 'current '; |
| 34 | } | ||
| 34 | 35 | ||
| 35 | $link = ''; | 36 | $link = ''; |
| 36 | if($data->isReachable()) | 37 | if($data->isReachable()) // titre de catégorie du menu non clicable |
| 37 | { | ||
| 38 | if(str_starts_with($data->getEndOfPath(), 'http')) // lien vers autre site | ||
| 39 | { | 38 | { |
| 40 | $link .= '<a href="' . $data->getEndOfPath() . '" target="_blank">'; | 39 | if(str_starts_with($data->getEndOfPath(), 'http')) // lien vers autre site |
| 40 | { | ||
| 41 | $link .= '<a href="' . $data->getEndOfPath() . '" target="_blank">'; | ||
| 42 | } | ||
| 43 | elseif($data->getEndOfPath() != '') // lien relatif | ||
| 44 | { | ||
| 45 | $link .= '<a href="' . new URL(['page' => $data->getPagePath()]) . '">'; | ||
| 46 | } | ||
| 47 | } | ||
| 48 | else{ | ||
| 49 | $link .= '<a>'; | ||
| 41 | } | 50 | } |
| 42 | elseif($data->getEndOfPath() != '') // lien relatif | 51 | |
| 52 | if(count($data->getChildren()) > 0) // titre de catégorie | ||
| 43 | { | 53 | { |
| 44 | $link .= '<a href="' . new URL(['page' => $data->getPagePath()]) . '">'; | 54 | $li_class .= $data->getParent() == null ? 'drop-down' : 'drop-right'; |
| 55 | |||
| 56 | $nav_html .= '<li class="'. $li_class . '">' . $link . '<p>' . $data->getPageName() . '</p></a><ul class="sub-menu">' . "\n"; | ||
| 57 | $level++; | ||
| 58 | $nav_html .= $this->navMainHTML($data, $current); | ||
| 59 | $level--; | ||
| 60 | $nav_html .= '</ul></li>' . "\n"; | ||
| 61 | } | ||
| 62 | else | ||
| 63 | { | ||
| 64 | $nav_html .= '<li class="'. $li_class . '">' . $link . '<p>' . $data->getPageName() . '</p></a></li>' . "\n"; | ||
| 45 | } | 65 | } |
| 46 | } | ||
| 47 | else{ | ||
| 48 | $link .= '<a>'; | ||
| 49 | } | 66 | } |
| 50 | 67 | ||
| 51 | if(count($data->getChildren()) > 0) // titre de catégorie | ||
| 52 | { | ||
| 53 | $li_class .= $data->getParent() == null ? 'drop-down' : 'drop-right'; | ||
| 54 | |||
| 55 | $nav_html .= '<li class="'. $li_class . '">' . $link . '<p>' . $data->getPageName() . '</p></a><ul class="sub-menu">' . "\n"; | ||
| 56 | $level++; | ||
| 57 | $nav_html .= $this->navMainHTML($data, $current); | ||
| 58 | $level--; | ||
| 59 | $nav_html .= '</ul></li>' . "\n"; | ||
| 60 | } | ||
| 61 | else | ||
| 62 | { | ||
| 63 | $nav_html .= '<li class="'. $li_class . '">' . $link . '<p>' . $data->getPageName() . '</p></a></li>' . "\n"; | ||
| 64 | } | ||
| 65 | } | 68 | } |
| 66 | return $nav_html; | 69 | return $nav_html; |
| 67 | } | 70 | } |
