diff options
Diffstat (limited to 'src/View/MainBuilder.php')
| -rw-r--r-- | src/View/MainBuilder.php | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/View/MainBuilder.php b/src/View/MainBuilder.php new file mode 100644 index 0000000..b5b9b00 --- /dev/null +++ b/src/View/MainBuilder.php | |||
| @@ -0,0 +1,99 @@ | |||
| 1 | <?php | ||
| 2 | // src/View/MainBuilder.php | ||
| 3 | |||
| 4 | declare(strict_types=1); | ||
| 5 | |||
| 6 | namespace App\View; | ||
| 7 | |||
| 8 | use App\Entity\Article; | ||
| 9 | use App\Entity\Node; | ||
| 10 | use App\Entity\Presentation; | ||
| 11 | use App\Model\Model; | ||
| 12 | use App\Service\URL; | ||
| 13 | |||
| 14 | class MainBuilder extends AbstractBuilder | ||
| 15 | { | ||
| 16 | static public bool $modif_mode = false; | ||
| 17 | |||
| 18 | public function __construct(Node $node) | ||
| 19 | { | ||
| 20 | $this->html .= "<main>\n"; | ||
| 21 | |||
| 22 | // page article: cas particulier où l'article est greffé sur main | ||
| 23 | if(Model::$page_path->getLast()->getEndOfPath() === 'article'){ | ||
| 24 | // pas censé arriver | ||
| 25 | if(!isset($_GET['id'])){ | ||
| 26 | header('Location: ' . new URL); | ||
| 27 | die; | ||
| 28 | } | ||
| 29 | |||
| 30 | // nouvel article | ||
| 31 | if($node->getAdoptedChild() == null){ | ||
| 32 | $date = new \DateTime; | ||
| 33 | $article = new Article('', $date); | ||
| 34 | $new = new Node('new', 0, null, null, $article); | ||
| 35 | } | ||
| 36 | // modification | ||
| 37 | else{ | ||
| 38 | $new = $node->getAdoptedChild(); | ||
| 39 | } | ||
| 40 | //$builder_name = 'App\View\\' . $this->snakeToPascalCase($new->getName()) . 'Builder'; | ||
| 41 | $builder_name = 'App\View\NewBuilder'; | ||
| 42 | $builder = new $builder_name($new); | ||
| 43 | $this->html .= $builder->render(); | ||
| 44 | } | ||
| 45 | else{ | ||
| 46 | // si action = "modif_page", affiche des commandes supplémentaires | ||
| 47 | if(IS_ADMIN && self::$modif_mode){ | ||
| 48 | // ajouter un contrôle du champ in_menu | ||
| 49 | $this->viewEditBlocks($node); | ||
| 50 | } | ||
| 51 | |||
| 52 | // dans tous les cas | ||
| 53 | $this->useChildrenBuilder($node); | ||
| 54 | } | ||
| 55 | |||
| 56 | $this->html .= "</main>\n"; | ||
| 57 | } | ||
| 58 | |||
| 59 | // mode modification de page uniquement | ||
| 60 | private function viewEditBlocks(Node $node): void | ||
| 61 | { | ||
| 62 | $options = ''; | ||
| 63 | foreach(Presentation::BLOCKS as $key => $value){ | ||
| 64 | $options .= '<option value= "' . $key . '">' . $value . "</option>\n"; | ||
| 65 | } | ||
| 66 | |||
| 67 | // ceci pourrait être déplacé au début des blocs | ||
| 68 | $bloc_edit = ''; | ||
| 69 | foreach($node->getChildren() as $child_node){ | ||
| 70 | // ordre des articles 'news' | ||
| 71 | if($child_node->getName() === 'news_block'){ | ||
| 72 | $order = $child_node->getNodeData()->getChronoOrder() ? 'chrono' : 'antichrono'; | ||
| 73 | } | ||
| 74 | |||
| 75 | // présentation par défaut | ||
| 76 | if(Presentation::hasPresentation($child_node->getName()) && $child_node->getNodeData()->getPresentation() === null){ | ||
| 77 | $child_node->getNodeData()->setPresentation('full_width'); // pas de persistence ici | ||
| 78 | } | ||
| 79 | |||
| 80 | ob_start(); | ||
| 81 | require self::VIEWS_PATH . 'modify_block.php'; | ||
| 82 | $bloc_edit .= ob_get_clean(); | ||
| 83 | } | ||
| 84 | |||
| 85 | ob_start(); | ||
| 86 | require self::VIEWS_PATH . 'modify_page.php'; | ||
| 87 | $this->html .= ob_get_clean(); | ||
| 88 | } | ||
| 89 | |||
| 90 | // utilisée dans modify_block.php | ||
| 91 | private function makePresentationOptions(string $presentation): string | ||
| 92 | { | ||
| 93 | $options = ''; | ||
| 94 | foreach(Presentation::PRESENTATIONS as $key => $value){ | ||
| 95 | $options .= '<option value="' . $key . '" ' . ($presentation === $key ? 'selected' : '') . '>' . $value . '</option>'; | ||
| 96 | } | ||
| 97 | return $options; | ||
| 98 | } | ||
| 99 | } \ No newline at end of file | ||
