diff options
Diffstat (limited to 'src/controller/Director.php')
| -rw-r--r-- | src/controller/Director.php | 93 |
1 files changed, 66 insertions, 27 deletions
diff --git a/src/controller/Director.php b/src/controller/Director.php index 5ff8f47..db84661 100644 --- a/src/controller/Director.php +++ b/src/controller/Director.php | |||
| @@ -13,17 +13,29 @@ class Director | |||
| 13 | static public Menu $menu_data; // pour NavBuilder | 13 | static public Menu $menu_data; // pour NavBuilder |
| 14 | static public Path $page_path; // pour BreadcrumbBuilder | 14 | static public Path $page_path; // pour BreadcrumbBuilder |
| 15 | private Page $page; | 15 | private Page $page; |
| 16 | private Node $root_node; | 16 | private Node $node; |
| 17 | private Node $article; | ||
| 17 | 18 | ||
| 18 | public function __construct(EntityManager $entityManager) | 19 | public function __construct(EntityManager $entityManager, bool $for_display = false) |
| 19 | { | 20 | { |
| 20 | $this->entityManager = $entityManager; | 21 | $this->entityManager = $entityManager; |
| 21 | self::$menu_data = new Menu($entityManager); // Menu est un modèle mais pas une entité | 22 | if($for_display){ |
| 22 | self::$page_path = new Path(); | 23 | self::$menu_data = new Menu($entityManager); // Menu est un modèle mais pas une entité |
| 23 | $this->page = self::$page_path->getLast(); | 24 | self::$page_path = new Path(); |
| 24 | $this->root_node = new Node; // instance mère "vide" ne possédant rien d'autre que des enfants | 25 | $this->page = self::$page_path->getLast(); |
| 26 | } | ||
| 27 | $this->node = new Node; // instance mère "vide" ne possédant rien d'autre que des enfants | ||
| 25 | } | 28 | } |
| 26 | 29 | ||
| 30 | public function getNode(): Node | ||
| 31 | { | ||
| 32 | return $this->node; | ||
| 33 | } | ||
| 34 | public function getArticleNode(): Node | ||
| 35 | { | ||
| 36 | return $this->article; | ||
| 37 | } | ||
| 38 | |||
| 27 | public function makeRootNode(string $id = ''): void | 39 | public function makeRootNode(string $id = ''): void |
| 28 | { | 40 | { |
| 29 | // on récupère toutes les entrées | 41 | // on récupère toutes les entrées |
| @@ -44,25 +56,10 @@ class Director | |||
| 44 | ->setParameter('id', $id) | 56 | ->setParameter('id', $id) |
| 45 | ->getResult(); | 57 | ->getResult(); |
| 46 | } | 58 | } |
| 47 | $this->feedObjects($bulk_data); | 59 | $this->feedRootNodeObjects($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 | } | 60 | } |
| 64 | 61 | ||
| 65 | private function feedObjects(array $bulk_data): void // $bulk_data = tableau de Node | 62 | private function feedRootNodeObjects(array $bulk_data): void // $bulk_data = tableau de Node |
| 66 | { | 63 | { |
| 67 | // puis on les range | 64 | // 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) | 65 | // (attention, risque de disfonctionnement si les noeuds de 1er niveau ne sont pas récupérés en 1er dans la BDD) |
| @@ -71,7 +68,7 @@ class Director | |||
| 71 | // premier niveau | 68 | // premier niveau |
| 72 | if($node->getParent() == null) | 69 | if($node->getParent() == null) |
| 73 | { | 70 | { |
| 74 | $this->root_node->addChild($node); | 71 | $this->node->addChild($node); |
| 75 | 72 | ||
| 76 | // spécifique page article | 73 | // spécifique page article |
| 77 | if($node->getName() === 'main' && $this->page->getEndOfPath() == 'article'){ | 74 | if($node->getName() === 'main' && $this->page->getEndOfPath() == 'article'){ |
| @@ -94,8 +91,50 @@ class Director | |||
| 94 | } | 91 | } |
| 95 | } | 92 | } |
| 96 | 93 | ||
| 97 | public function getRootNode(): Node | 94 | // récupération d'un article pour modification |
| 98 | { | 95 | public function makeArticleNode(string $id = '', bool $get_section = false): bool |
| 99 | return $this->root_node; | 96 | { |
| 97 | if($get_section){ | ||
| 98 | $dql = 'SELECT n, p FROM App\Entity\Node n LEFT JOIN n.parent p WHERE n.article_timestamp = :id'; | ||
| 99 | } | ||
| 100 | else{ | ||
| 101 | $dql = 'SELECT n FROM App\Entity\Node n WHERE n.article_timestamp = :id'; | ||
| 102 | } | ||
| 103 | // n est l'article et p son $parent | ||
| 104 | $bulk_data = $this->entityManager | ||
| 105 | ->createQuery($dql) | ||
| 106 | ->setParameter('id', $id) | ||
| 107 | ->getResult(); | ||
| 108 | |||
| 109 | if(count($bulk_data) === 0){ | ||
| 110 | return false; | ||
| 111 | } | ||
| 112 | |||
| 113 | if($get_section){ | ||
| 114 | $this->article = $bulk_data[0]; | ||
| 115 | $this->makeSectionNode($bulk_data[0]->getParent()->getId()); | ||
| 116 | } | ||
| 117 | else{ | ||
| 118 | $this->article = $bulk_data[0]; | ||
| 119 | } | ||
| 120 | |||
| 121 | return true; | ||
| 122 | } | ||
| 123 | |||
| 124 | // récupération des articles d'un bloc <section> à la création d'un article | ||
| 125 | public function makeSectionNode(int $section_id): bool | ||
| 126 | { | ||
| 127 | $section = $this->entityManager->find('App\Entity\Node', (string)$section_id); | ||
| 128 | |||
| 129 | $bulk_data = $this->entityManager | ||
| 130 | ->createQuery('SELECT n FROM App\Entity\Node n WHERE n.parent = :parent') | ||
| 131 | ->setParameter('parent', $section) | ||
| 132 | ->getResult(); | ||
| 133 | |||
| 134 | foreach($bulk_data as $article){ | ||
| 135 | $section->addChild($article); // pas de flush, on ne va pas écrire dans la BDD à chaque nouvelle page | ||
| 136 | } | ||
| 137 | $this->node = $section; | ||
| 138 | return true; | ||
| 100 | } | 139 | } |
| 101 | } | 140 | } |
