diff options
author | polo-pc-greta <ordipolo@gmx.fr> | 2025-03-27 10:13:03 +0100 |
---|---|---|
committer | polo-pc-greta <ordipolo@gmx.fr> | 2025-03-27 10:13:03 +0100 |
commit | df3612ed7e6691530503f79483d2fdbc032d01b8 (patch) | |
tree | 56d1c68fdc8625f5dad1937a654299d45142c79a /src/model/Menu.php | |
download | cms-df3612ed7e6691530503f79483d2fdbc032d01b8.zip |
mise en ligne github
Diffstat (limited to 'src/model/Menu.php')
-rw-r--r-- | src/model/Menu.php | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/model/Menu.php b/src/model/Menu.php new file mode 100644 index 0000000..624a0fc --- /dev/null +++ b/src/model/Menu.php | |||
@@ -0,0 +1,53 @@ | |||
1 | <?php | ||
2 | // src/controller/Menu.php | ||
3 | |||
4 | declare(strict_types=1); | ||
5 | |||
6 | use Doctrine\ORM\EntityManager; | ||
7 | use App\Entity\Page; | ||
8 | use Doctrine\Common\Collections\ArrayCollection; | ||
9 | |||
10 | class Menu extends Page | ||
11 | { | ||
12 | private EntityManager $entityManager; | ||
13 | private array $other_pages = []; // pages n'apparaissant pas dans le menu | ||
14 | |||
15 | public function __construct(EntityManager $entityManager){ | ||
16 | $this->children = new ArrayCollection(); | ||
17 | |||
18 | $bulk_data = $entityManager | ||
19 | ->createQuery('SELECT n FROM App\Entity\Page n WHERE n.parent IS null') // :Doctrine\ORM\Query | ||
20 | ->getResult(); // :array de Page | ||
21 | |||
22 | if(count($bulk_data) === 0){ | ||
23 | makeStartPage($entityManager); | ||
24 | } | ||
25 | |||
26 | foreach($bulk_data as $first_level_entries){ | ||
27 | // génération du menu | ||
28 | if($first_level_entries->getInMenu()){ | ||
29 | $this->addChild($first_level_entries); | ||
30 | } | ||
31 | // autres pages | ||
32 | else{ | ||
33 | // attention, seul le premier élément du chemin est pris en compte | ||
34 | $this->other_pages[] = $first_level_entries; | ||
35 | } | ||
36 | } | ||
37 | |||
38 | foreach($this->getChildren() as $page){ | ||
39 | $page->fillChildrenPagePath(); | ||
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 | } | ||
48 | |||
49 | public function getOtherPages(): array | ||
50 | { | ||
51 | return $this->other_pages; | ||
52 | } | ||
53 | } \ No newline at end of file | ||