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/controller/Director.php | |
download | cms-df3612ed7e6691530503f79483d2fdbc032d01b8.zip |
mise en ligne github
Diffstat (limited to 'src/controller/Director.php')
-rw-r--r-- | src/controller/Director.php | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/src/controller/Director.php b/src/controller/Director.php new file mode 100644 index 0000000..896cde1 --- /dev/null +++ b/src/controller/Director.php | |||
@@ -0,0 +1,101 @@ | |||
1 | <?php | ||
2 | // src/controller/Director.php | ||
3 | |||
4 | declare(strict_types=1); | ||
5 | |||
6 | use Doctrine\ORM\EntityManager; | ||
7 | use App\Entity\Page; | ||
8 | use App\Entity\Node; | ||
9 | |||
10 | class Director | ||
11 | { | ||
12 | private EntityManager $entityManager; | ||
13 | static public Menu $menu_data; // pour NavBuilder | ||
14 | static public Path $page_path; // pour BreadcrumbBuilder | ||
15 | private Page $page; | ||
16 | private Node $root_node; | ||
17 | |||
18 | public function __construct(EntityManager $entityManager) | ||
19 | { | ||
20 | $this->entityManager = $entityManager; | ||
21 | self::$menu_data = new Menu($entityManager); // Menu est un modèle mais pas une entité | ||
22 | self::$page_path = new Path(); | ||
23 | $this->page = self::$page_path->getLast(); | ||
24 | $this->root_node = new Node; // instance mère "vide" ne possédant rien d'autre que des enfants | ||
25 | } | ||
26 | |||
27 | public function makeRootNode(string $id = ''): void | ||
28 | { | ||
29 | // on récupère toutes les entrées | ||
30 | $dql = 'SELECT n FROM App\Entity\Node n WHERE n.page = :page OR n.page IS null'; | ||
31 | if($id == '') | ||
32 | { | ||
33 | $bulk_data = $this->entityManager | ||
34 | ->createQuery($dql) | ||
35 | ->setParameter('page', $this->page) | ||
36 | ->getResult(); | ||
37 | } | ||
38 | else // avec $_GET['id'] dans l'URL | ||
39 | { | ||
40 | $dql .= ' OR n.article_timestamp = :id'; | ||
41 | $bulk_data = $this->entityManager | ||
42 | ->createQuery($dql) | ||
43 | ->setParameter('page', $this->page) | ||
44 | ->setParameter('id', $id) | ||
45 | ->getResult(); | ||
46 | } | ||
47 | $this->feedObjects($bulk_data); | ||
48 | } | ||
49 | |||
50 | public function makeArticleNode(string $id = ''): bool | ||
51 | { | ||
52 | $bulk_data = $this->entityManager | ||
53 | ->createQuery('SELECT n FROM App\Entity\Node n WHERE n.article_timestamp = :id') | ||
54 | ->setParameter('id', $id) | ||
55 | ->getResult(); | ||
56 | |||
57 | if(count($bulk_data) === 0){ | ||
58 | return false; | ||
59 | } | ||
60 | |||
61 | $this->root_node = $bulk_data[0]; | ||
62 | return true; | ||
63 | } | ||
64 | |||
65 | public function feedObjects(array $bulk_data): void // $bulk_data = tableau de Node | ||
66 | { | ||
67 | // puis on les range | ||
68 | // (attention, risque de disfonctionnement si les noeuds de 1er niveau ne sont pas récupérés en 1er dans la BDD) | ||
69 | foreach($bulk_data as $node) | ||
70 | { | ||
71 | // premier niveau | ||
72 | if($node->getParent() == null) | ||
73 | { | ||
74 | $this->root_node->addChild($node); | ||
75 | |||
76 | // spécifique page article | ||
77 | if($node->getName() === 'main' && $this->page->getEndOfPath() == 'article'){ | ||
78 | $main = $node; | ||
79 | } | ||
80 | } | ||
81 | // autres niveaux | ||
82 | else | ||
83 | { | ||
84 | $node->getParent()->addChild($node); | ||
85 | |||
86 | // spécifique page article | ||
87 | if($node->getName() === 'new' && $this->page->getEndOfPath() == 'article'){ | ||
88 | $new = $node; | ||
89 | } | ||
90 | } | ||
91 | } | ||
92 | if(isset($new)){ | ||
93 | $main->setTempChild($new); | ||
94 | } | ||
95 | } | ||
96 | |||
97 | public function getRootNode(): Node | ||
98 | { | ||
99 | return $this->root_node; | ||
100 | } | ||
101 | } | ||