summaryrefslogtreecommitdiff
path: root/src/model/Menu.php
blob: 10cf3d5b524a2ea68135715754cb588c12c4ced7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
// src/controller/Menu.php

declare(strict_types=1);

use Doctrine\ORM\EntityManager;
use App\Entity\Page;
use Doctrine\Common\Collections\ArrayCollection;

class Menu extends Page
{
	private EntityManager $entityManager;
    private array $other_pages = []; // pages n'apparaissant pas dans le menu

	public function __construct(EntityManager $entityManager){
		$this->children = new ArrayCollection();

		$bulk_data = $entityManager
            ->createQuery('SELECT n FROM App\Entity\Page n WHERE n.parent IS null') // :Doctrine\ORM\Query
            ->getResult(); // :array de Page

        if(count($bulk_data) === 0){
            makeStartPage($entityManager); // => installation.php
        }

        foreach($bulk_data as $first_level_entries){
            // dans le menu
            if($first_level_entries->isInMenu()){
                $this->addChild($first_level_entries);
            }
            // autres pages
            else{
                // attention, seul le premier élément du chemin est pris en compte
                $this->other_pages[] = $first_level_entries;
            }
        }

        foreach($this->getChildren() as $page){
        	$page->fillChildrenPagePath();
        }
	}

    public function getOtherPages(): array
    {
        return $this->other_pages;
    }
}