diff options
Diffstat (limited to 'src/Model/Menu.php')
| -rw-r--r-- | src/Model/Menu.php | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/Model/Menu.php b/src/Model/Menu.php new file mode 100644 index 0000000..6b08950 --- /dev/null +++ b/src/Model/Menu.php | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | <?php | ||
| 2 | // src/Model/Menu.php | ||
| 3 | |||
| 4 | declare(strict_types=1); | ||
| 5 | |||
| 6 | namespace App\Model; | ||
| 7 | |||
| 8 | use Doctrine\ORM\EntityManager; | ||
| 9 | use Doctrine\Common\Collections\ArrayCollection; | ||
| 10 | use App\Entity\Page; | ||
| 11 | |||
| 12 | class Menu extends Page | ||
| 13 | { | ||
| 14 | private array $other_pages = []; // pages n'apparaissant pas dans le menu | ||
| 15 | |||
| 16 | public function __construct(EntityManager $entityManager){ | ||
| 17 | $this->children = new ArrayCollection(); | ||
| 18 | |||
| 19 | $bulk_data = $entityManager | ||
| 20 | ->createQuery('SELECT n FROM App\Entity\Page n WHERE n.parent IS null') // :Doctrine\ORM\Query | ||
| 21 | ->getResult(); // :array de Page | ||
| 22 | |||
| 23 | foreach($bulk_data as $first_level_entries){ | ||
| 24 | // dans le menu | ||
| 25 | if($first_level_entries->isInMenu()){ | ||
| 26 | $this->addChild($first_level_entries); | ||
| 27 | } | ||
| 28 | // autres pages | ||
| 29 | else{ | ||
| 30 | // attention, seul le premier élément du chemin est pris en compte | ||
| 31 | $this->other_pages[] = $first_level_entries; | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | foreach($this->getChildren() as $page){ | ||
| 36 | $page->fillChildrenPagePath(); | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | public function getOtherPages(): array | ||
| 41 | { | ||
| 42 | return $this->other_pages; | ||
| 43 | } | ||
| 44 | } \ No newline at end of file | ||
