summaryrefslogtreecommitdiff
path: root/src/model/Menu.php
blob: 624a0fc4acedc4f4782e7810803043112b3e4f5c (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
48
49
50
51
52
53
<?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);
        }

        foreach($bulk_data as $first_level_entries){
            // génération du menu
            if($first_level_entries->getInMenu()){
                $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();
        }
        
        /*for($i = 0; $i < count($this->getChildren()[1]->getChildren()); $i++){
        	echo $this->getChildren()[1]->getChildren()[$i]->getEndOfPath() . ' - ';
        	echo $this->getChildren()[1]->getChildren()[$i]->getPageName() . '<br>';
        }*/
        //die;
	}

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