From 43c962f442165327d73756c62501ff823d43f9f3 Mon Sep 17 00:00:00 2001 From: polo Date: Mon, 31 Mar 2025 18:43:53 +0200 Subject: positions dans table page, fil d'ariane en haut, logo dans footer --- src/model/entities/Page.php | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src/model/entities/Page.php') diff --git a/src/model/entities/Page.php b/src/model/entities/Page.php index d7d8098..fbf0f27 100644 --- a/src/model/entities/Page.php +++ b/src/model/entities/Page.php @@ -32,6 +32,9 @@ class Page #[ORM\Column(type: "boolean")] private bool $in_menu; + #[ORM\Column(type: "integer", nullable: true)] // null si hors menu + private ?int $position; + #[ORM\ManyToOne(targetEntity: self::class)] #[ORM\JoinColumn(name: "parent_id", referencedColumnName: "id_page", onDelete: "SET NULL", nullable: true)] private ?self $parent = null; @@ -42,12 +45,13 @@ class Page /*#[ORM\Column(type: "json", nullable: true)] private ?array $metadata = null;*/ - public function __construct(string $name, string $eop, bool $reachable, bool $in_menu, ?Page $parent) + public function __construct(string $name, string $eop, bool $reachable, bool $in_menu, ?int $position, ?Page $parent) { $this->name_page = $name; $this->end_of_path = $eop; $this->reachable = $reachable; $this->in_menu = $in_menu; + $this->position = $position; $this->parent = $parent; $this->children = new ArrayCollection(); } @@ -73,6 +77,10 @@ class Page { return $this->in_menu; } + public function getPosition(): ?int + { + return $this->position; + } public function getParent(): ?Page { return $this->parent; @@ -93,5 +101,26 @@ class Page public function addChild(self $child): void { $this->children[] = $child; + $this->sortChildren(); + } + + // utiliser $position pour afficher les éléments dans l'ordre + private function sortChildren(): void + { + $iteration = count($this->children); + while($iteration > 1) + { + for($i = 0; $i < $iteration - 1; $i++) + { + //echo '
' . $this->children[$i]->getPosition() . ' - ' . $this->children[$i + 1]->getPosition(); + if($this->children[$i]->getPosition() > $this->children[$i + 1]->getPosition()) + { + $tmp = $this->children[$i]; + $this->children[$i] = $this->children[$i + 1]; + $this->children[$i + 1] = $tmp; + } + } + $iteration--; + } } } -- cgit v1.2.3