From f27cca08ff786ceff1870147f6d6bad14d71117f Mon Sep 17 00:00:00 2001 From: polo Date: Fri, 23 Oct 2026 00:47:32 +0200 Subject: =?UTF-8?q?dossiers=20avec=20majuscule,=20namespace=20pour=20toute?= =?UTF-8?q?s=20les=20classes,=20autoload=20psr-4,=20UserDataService::creat?= =?UTF-8?q?eZip=20d=C3=A9plac=C3=A9=20dans=20Backup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Model/Entity/Page.php | 222 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 222 insertions(+) create mode 100644 src/Model/Entity/Page.php (limited to 'src/Model/Entity/Page.php') diff --git a/src/Model/Entity/Page.php b/src/Model/Entity/Page.php new file mode 100644 index 0000000..7cca3dc --- /dev/null +++ b/src/Model/Entity/Page.php @@ -0,0 +1,222 @@ +name_page = $name; + $this->end_of_path = $eop; + $this->description = $description; + $this->reachable = $reachable; + $this->in_menu = $in_menu; + $this->hidden = $hidden; + $this->position = $position; + $this->parent = $parent; + $this->children = new ArrayCollection(); + } + + // getters/setters + public function getId(): int + { + return $this->id_page; + } + public function getPageName(): string + { + return $this->name_page; + } + public function setPageName(string $name): void + { + $this->name_page = $name; + } + public function getPagePath(): string + { + return $this->page_path; + } + public function setPagePath(string $path):void + { + $this->page_path = $path; + } + public function getEndOfPath(): string + { + return $this->end_of_path; + } + public function setEndOfPath(string $end_of_path):void + { + $this->end_of_path = $end_of_path; + } + public function getDescription(): string + { + return $this->description; + } + public function setDescription(string $description): void + { + $this->description = $description; + } + + public function getCSS(): array + { + return array_merge(self::$default_css, $this->css ?? []); + } + public function addCSS(string $css): void + { + if(!in_array($css, $this->css ?? [])){ + $this->css[] = $css; + } + } + public function removeCSS(string $css): void + { + // array_diff renvoie une copie du 1er tableau alégée des élements existants aussi dans le 2è, array_values réindexe + $this->css = array_values(array_diff($this->css, [$css])); + } + public function getJS(): array + { + return array_merge(self::$default_js, $this->js ?? []); + //UPDATE `nb_page` SET `js` = NULL WHERE JSON_EQUALS(`js`, '["main"]'); + } + public function addJS(string $js): void + { + if(!in_array($js, $this->js ?? [])){ + $this->js[] = $js; + } + } + public function removeJS(string $js): void + { + $this->js = array_values(array_diff($this->js, [$js])); + } + + public function isReachable(): bool + { + return $this->reachable; + } + public function isInMenu(): bool + { + return $this->in_menu; + } + public function isHidden(): bool + { + return $this->hidden; + } + public function setHidden(bool $hidden): void + { + $this->hidden = $hidden; + } + public function getPosition(): ?int + { + return $this->position; + } + public function setPosition(int $position): void + { + $this->position = $position; + } + public function getParent(): ?Page + { + return $this->parent; + } + public function setParent(?Page $parent): void + { + $this->parent = $parent; + } + public function getChildren(): Collection + { + return $this->children; + } + + // utilisée par $menu_path + public function fillChildrenPagePath(string $parent_path = ''): void + { + $this->page_path = $parent_path != '' ? $parent_path . '/' . $this->end_of_path : $this->end_of_path; + foreach($this->getChildren() as $page){ + $page->fillChildrenPagePath($this->page_path); + } + } + + public function addChild(self $child): void + { + $this->children[] = $child; + $this->sortChildren(false); + } + public function removeChild(self $child): void + { + $this->children->removeElement($child); + $this->children = new ArrayCollection(array_values($this->children->toArray())); // réindexer en passant par un tableau + $this->sortChildren(false); + } + + public function findPageById(int $id): ?Page + { + $target = null; + foreach($this->children as $page){ + if($page->getId() === $id){ + return $page; + } + if(count($page->getChildren()) > 0){ + $target = $page->findPageById($id); + if($target !== null){ + return $target; + } + } + } + return $target; + } +} -- cgit v1.2.3