diff options
| author | polo <ordipolo@gmx.fr> | 2026-10-23 00:47:32 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2026-10-23 00:47:32 +0200 |
| commit | f27cca08ff786ceff1870147f6d6bad14d71117f (patch) | |
| tree | d36597a72025313d6faf4ed228755fa267ebe2f6 /src/model/entities/Page.php | |
| parent | c7309f900ef05bd5cb313110ec159b761af394ec (diff) | |
| download | cms-f27cca08ff786ceff1870147f6d6bad14d71117f.tar.gz cms-f27cca08ff786ceff1870147f6d6bad14d71117f.tar.bz2 cms-f27cca08ff786ceff1870147f6d6bad14d71117f.zip | |
dossiers avec majuscule, namespace pour toutes les classes, autoload psr-4, UserDataService::createZip déplacé dans Backup
Diffstat (limited to 'src/model/entities/Page.php')
| -rw-r--r-- | src/model/entities/Page.php | 221 |
1 files changed, 0 insertions, 221 deletions
diff --git a/src/model/entities/Page.php b/src/model/entities/Page.php deleted file mode 100644 index 8d3dd40..0000000 --- a/src/model/entities/Page.php +++ /dev/null | |||
| @@ -1,221 +0,0 @@ | |||
| 1 | <?php | ||
| 2 | // src/model/entities/Page.php | ||
| 3 | |||
| 4 | declare(strict_types=1); | ||
| 5 | |||
| 6 | namespace App\Entity; | ||
| 7 | |||
| 8 | use Doctrine\ORM\Mapping as ORM; | ||
| 9 | use Doctrine\Common\Collections\Collection; | ||
| 10 | use Doctrine\Common\Collections\ArrayCollection; | ||
| 11 | |||
| 12 | #[ORM\Entity] | ||
| 13 | #[ORM\Table(name: TABLE_PREFIX . "page")] | ||
| 14 | class Page | ||
| 15 | { | ||
| 16 | use \Position; | ||
| 17 | |||
| 18 | #[ORM\Id] | ||
| 19 | #[ORM\GeneratedValue] | ||
| 20 | #[ORM\Column(type: "integer")] | ||
| 21 | private int $id_page; | ||
| 22 | |||
| 23 | #[ORM\Column(type: "string", length: 255)] | ||
| 24 | private string $name_page; | ||
| 25 | |||
| 26 | #[ORM\Column(type: "string", length: 255)] | ||
| 27 | private string $end_of_path; // morceau d'URL plus exactement | ||
| 28 | |||
| 29 | private string $page_path = ''; | ||
| 30 | |||
| 31 | #[ORM\Column(type: "text")] | ||
| 32 | private string $description; | ||
| 33 | |||
| 34 | #[ORM\Column(type: "json", nullable: true)] | ||
| 35 | private ?array $css = null; | ||
| 36 | |||
| 37 | #[ORM\Column(type: "json", nullable: true)] | ||
| 38 | private ?array $js = null; | ||
| 39 | |||
| 40 | static private array $default_css = ['body', 'head', 'nav', 'foot']; | ||
| 41 | static private array $default_js = ['main']; | ||
| 42 | |||
| 43 | #[ORM\Column(type: "boolean")] | ||
| 44 | private bool $reachable; | ||
| 45 | |||
| 46 | #[ORM\Column(type: "boolean")] | ||
| 47 | private bool $in_menu; | ||
| 48 | |||
| 49 | #[ORM\Column(type: "boolean")] | ||
| 50 | private bool $hidden; | ||
| 51 | |||
| 52 | #[ORM\Column(type: "integer", nullable: true)] // null si hors menu | ||
| 53 | private ?int $position; | ||
| 54 | |||
| 55 | #[ORM\ManyToOne(targetEntity: self::class, inversedBy: "children")] | ||
| 56 | #[ORM\JoinColumn(name: "parent_id", referencedColumnName: "id_page", onDelete: "SET NULL", nullable: true)] | ||
| 57 | private ?self $parent = null; | ||
| 58 | |||
| 59 | #[ORM\OneToMany(targetEntity: self::class, mappedBy: 'parent')] | ||
| 60 | protected Collection $children; | ||
| 61 | |||
| 62 | /*#[ORM\Column(type: "json", nullable: true)] | ||
| 63 | private ?array $metadata = null;*/ | ||
| 64 | |||
| 65 | public function __construct(string $name, string $eop, string $description, bool $reachable, bool $in_menu, bool $hidden, ?int $position, ?Page $parent) | ||
| 66 | { | ||
| 67 | $this->name_page = $name; | ||
| 68 | $this->end_of_path = $eop; | ||
| 69 | $this->description = $description; | ||
| 70 | $this->reachable = $reachable; | ||
| 71 | $this->in_menu = $in_menu; | ||
| 72 | $this->hidden = $hidden; | ||
| 73 | $this->position = $position; | ||
| 74 | $this->parent = $parent; | ||
| 75 | $this->children = new ArrayCollection(); | ||
| 76 | } | ||
| 77 | |||
| 78 | // getters/setters | ||
| 79 | public function getId(): int | ||
| 80 | { | ||
| 81 | return $this->id_page; | ||
| 82 | } | ||
| 83 | public function getPageName(): string | ||
| 84 | { | ||
| 85 | return $this->name_page; | ||
| 86 | } | ||
| 87 | public function setPageName(string $name): void | ||
| 88 | { | ||
| 89 | $this->name_page = $name; | ||
| 90 | } | ||
| 91 | public function getPagePath(): string | ||
| 92 | { | ||
| 93 | return $this->page_path; | ||
| 94 | } | ||
| 95 | public function setPagePath(string $path):void | ||
| 96 | { | ||
| 97 | $this->page_path = $path; | ||
| 98 | } | ||
| 99 | public function getEndOfPath(): string | ||
| 100 | { | ||
| 101 | return $this->end_of_path; | ||
| 102 | } | ||
| 103 | public function setEndOfPath(string $end_of_path):void | ||
| 104 | { | ||
| 105 | $this->end_of_path = $end_of_path; | ||
| 106 | } | ||
| 107 | public function getDescription(): string | ||
| 108 | { | ||
| 109 | return $this->description; | ||
| 110 | } | ||
| 111 | public function setDescription(string $description): void | ||
| 112 | { | ||
| 113 | $this->description = $description; | ||
| 114 | } | ||
| 115 | |||
| 116 | public function getCSS(): array | ||
| 117 | { | ||
| 118 | return array_merge(self::$default_css, $this->css ?? []); | ||
| 119 | } | ||
| 120 | public function addCSS(string $css): void | ||
| 121 | { | ||
| 122 | if(!in_array($css, $this->css ?? [])){ | ||
| 123 | $this->css[] = $css; | ||
| 124 | } | ||
| 125 | } | ||
| 126 | public function removeCSS(string $css): void | ||
| 127 | { | ||
| 128 | // array_diff renvoie une copie du 1er tableau alégée des élements existants aussi dans le 2è, array_values réindexe | ||
| 129 | $this->css = array_values(array_diff($this->css, [$css])); | ||
| 130 | } | ||
| 131 | public function getJS(): array | ||
| 132 | { | ||
| 133 | return array_merge(self::$default_js, $this->js ?? []); | ||
| 134 | //UPDATE `nb_page` SET `js` = NULL WHERE JSON_EQUALS(`js`, '["main"]'); | ||
| 135 | } | ||
| 136 | public function addJS(string $js): void | ||
| 137 | { | ||
| 138 | if(!in_array($js, $this->js ?? [])){ | ||
| 139 | $this->js[] = $js; | ||
| 140 | } | ||
| 141 | } | ||
| 142 | public function removeJS(string $js): void | ||
| 143 | { | ||
| 144 | $this->js = array_values(array_diff($this->js, [$js])); | ||
| 145 | } | ||
| 146 | |||
| 147 | public function isReachable(): bool | ||
| 148 | { | ||
| 149 | return $this->reachable; | ||
| 150 | } | ||
| 151 | public function isInMenu(): bool | ||
| 152 | { | ||
| 153 | return $this->in_menu; | ||
| 154 | } | ||
| 155 | public function isHidden(): bool | ||
| 156 | { | ||
| 157 | return $this->hidden; | ||
| 158 | } | ||
| 159 | public function setHidden(bool $hidden): void | ||
| 160 | { | ||
| 161 | $this->hidden = $hidden; | ||
| 162 | } | ||
| 163 | public function getPosition(): ?int | ||
| 164 | { | ||
| 165 | return $this->position; | ||
| 166 | } | ||
| 167 | public function setPosition(int $position): void | ||
| 168 | { | ||
| 169 | $this->position = $position; | ||
| 170 | } | ||
| 171 | public function getParent(): ?Page | ||
| 172 | { | ||
| 173 | return $this->parent; | ||
| 174 | } | ||
| 175 | public function setParent(?Page $parent): void | ||
| 176 | { | ||
| 177 | $this->parent = $parent; | ||
| 178 | } | ||
| 179 | public function getChildren(): Collection | ||
| 180 | { | ||
| 181 | return $this->children; | ||
| 182 | } | ||
| 183 | |||
| 184 | // utilisée par $menu_path | ||
| 185 | public function fillChildrenPagePath(string $parent_path = ''): void | ||
| 186 | { | ||
| 187 | $this->page_path = $parent_path != '' ? $parent_path . '/' . $this->end_of_path : $this->end_of_path; | ||
| 188 | foreach($this->getChildren() as $page){ | ||
| 189 | $page->fillChildrenPagePath($this->page_path); | ||
| 190 | } | ||
| 191 | } | ||
| 192 | |||
| 193 | public function addChild(self $child): void | ||
| 194 | { | ||
| 195 | $this->children[] = $child; | ||
| 196 | $this->sortChildren(false); | ||
| 197 | } | ||
| 198 | public function removeChild(self $child): void | ||
| 199 | { | ||
| 200 | $this->children->removeElement($child); | ||
| 201 | $this->children = new ArrayCollection(array_values($this->children->toArray())); // réindexer en passant par un tableau | ||
| 202 | $this->sortChildren(false); | ||
| 203 | } | ||
| 204 | |||
| 205 | public function findPageById(int $id): ?Page | ||
| 206 | { | ||
| 207 | $target = null; | ||
| 208 | foreach($this->children as $page){ | ||
| 209 | if($page->getId() === $id){ | ||
| 210 | return $page; | ||
| 211 | } | ||
| 212 | if(count($page->getChildren()) > 0){ | ||
| 213 | $target = $page->findPageById($id); | ||
| 214 | if($target !== null){ | ||
| 215 | return $target; | ||
| 216 | } | ||
| 217 | } | ||
| 218 | } | ||
| 219 | return $target; | ||
| 220 | } | ||
| 221 | } | ||
