diff options
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 | ||
