From e93cd6c352a8e4fbb4e1174bdb15484adbe4c0f7 Mon Sep 17 00:00:00 2001 From: polo Date: Fri, 26 Sep 2025 12:04:02 +0200 Subject: suppression table Presentation --- src/controller/PageManagementController.php | 13 ++++---- src/installation.php | 13 -------- src/model/Blocks.php | 37 ++--------------------- src/model/entities/Log.php | 7 ++--- src/model/entities/NodeData.php | 13 ++++---- src/model/entities/Presentation.php | 47 ----------------------------- src/view/MainBuilder.php | 9 ++---- src/view/NewsBlockBuilder.php | 2 +- src/view/PostBlockBuilder.php | 2 +- src/view/templates/modify_block.php | 6 ++-- 10 files changed, 26 insertions(+), 123 deletions(-) delete mode 100644 src/model/entities/Presentation.php diff --git a/src/controller/PageManagementController.php b/src/controller/PageManagementController.php index 3d7edde..e811a6a 100644 --- a/src/controller/PageManagementController.php +++ b/src/controller/PageManagementController.php @@ -135,7 +135,7 @@ class PageManagementController $main = $director->getNode(); $position = count($main->getChildren()) + 1; // position dans la fraterie - if(!in_array($_POST["bloc_select"], Blocks::getNameList(), true)) // 3è param: contrôle du type + if(!in_array($_POST["bloc_select"], array_keys(Blocks::$blocks), true)) // 3è param: contrôle du type { header("Location: " . new URL(['page' => $_GET['page'], 'error' => 'bad_bloc_type'])); die; @@ -168,13 +168,13 @@ class PageManagementController // valeurs par défaut if($_POST["bloc_select"] === 'post_block'){ - $data->setPresentation(Presentation::findPresentation($entityManager, 'fullwidth')); // pas génial l'utilisation de l'index dans la table + $data->setPresentation('fullwidth'); } elseif($_POST["bloc_select"] === 'news_block'){ - $data->setPresentation(Presentation::findPresentation($entityManager, 'grid')); + $data->setPresentation('grid'); } elseif($_POST["bloc_select"] === 'galery'){ - $data->setPresentation(Presentation::findPresentation($entityManager, 'mosaic')); // mieux que carousel pour commencer + $data->setPresentation('mosaic'); // mieux que carousel pour commencer } // else = null par défaut @@ -274,9 +274,8 @@ class PageManagementController $director = new Director($entityManager, false); $director->findNodeById($json['id']); - $presentation = Presentation::findPresentation($entityManager, $json['presentation']); - if($presentation !== null){ - $director->getNode()->getNodeData()->setPresentation($presentation); + if(in_array($json['presentation'], array_keys(Blocks::$presentations))){ + $director->getNode()->getNodeData()->setPresentation($json['presentation']); $entityManager->flush(); diff --git a/src/installation.php b/src/installation.php index 0d68e7b..452df60 100644 --- a/src/installation.php +++ b/src/installation.php @@ -7,7 +7,6 @@ use App\Entity\Page; use App\Entity\Node; use App\Entity\NodeData; use App\Entity\Image; -use App\Entity\Presentation; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\EntityManager; @@ -117,12 +116,6 @@ function makeStartPage(EntityManager $entityManager){ $head_new_page = new Node('head', ['css_array' => ['body', 'head', 'nav', 'new_page', 'foot'], 'js_array' => ['main', 'new_page']], 1, NULL, $new_page, NULL); $bloc_new_page = new Node('new_page', [], 1, $main, $new_page, NULL); - /* -- table presentation -- */ - $fullwidth = new Presentation('fullwidth'); - $grid = new Presentation('grid'); - $mosaic = new Presentation('mosaic'); - $carousel = new Presentation('carousel'); - /* -- table image -- */ // paramètres: file_name, file_path, file_path_mini, mime_type, alt $favicon = new Image("favicon48x48.png", NULL, "assets/favicon48x48.png", "image/png", "favicon"); @@ -169,12 +162,6 @@ function makeStartPage(EntityManager $entityManager){ $entityManager->persist($bloc_edit_menu); $entityManager->persist($head_new_page); $entityManager->persist($bloc_new_page); - - /* -- table presentation -- */ - $entityManager->persist($fullwidth); - $entityManager->persist($grid); - $entityManager->persist($mosaic); - $entityManager->persist($carousel); /* -- table image -- */ $entityManager->persist($favicon); diff --git a/src/model/Blocks.php b/src/model/Blocks.php index a6fab45..53268db 100644 --- a/src/model/Blocks.php +++ b/src/model/Blocks.php @@ -1,38 +1,7 @@ self::$types[$i], 'name' => self::$names[$i]]; - } - return $blocks; - } - - static public function getNameFromType(string $type): string - { - for($i=0; $i < count(self::$types); $i++){ - if(self::$types[$i] === $type){ - return self::$names[$i]; - } - } - return 'server side error'; - } + static public array $blocks = ['post_block' => 'Articles libres', 'news_block' => 'Actualités', 'galery' => 'Galerie', 'calendar' => 'Calendrier', 'form' => 'Formulaire']; + static public array $presentations = ['fullwidth' => 'Pleine largeur', 'grid' => 'Grille', 'mosaic' => 'Mosaïque', 'carousel' => 'Carrousel']; } \ No newline at end of file diff --git a/src/model/entities/Log.php b/src/model/entities/Log.php index 39b4307..eeb76e4 100644 --- a/src/model/entities/Log.php +++ b/src/model/entities/Log.php @@ -16,15 +16,14 @@ class Log #[ORM\Column(type: "integer")] private int $id_log; - #[ORM\Column(type: 'datetime', options: ['default' => 'CURRENT_TIMESTAMP'])] - //#[ORM\Column(type: 'datetime', columnDefinition: "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")] - private ?\DateTime $date_time ; // le type datetime de doctrine convertit en type \DateTime de PHP + #[ORM\Column(type: 'datetime', options: ['default' => 'CURRENT_TIMESTAMP'])] // CURRENT_TIMESTAMP "inutile", date générée par PHP + private \DateTime $date_time; // type datetime de doctrine <=> type \DateTime de PHP #[ORM\Column(type: "boolean")] private bool $success; public function __construct(bool $success){ - $this->date_time = new \DateTime(); + $this->date_time = new \DateTime; $this->success = $success; } } diff --git a/src/model/entities/NodeData.php b/src/model/entities/NodeData.php index 3688e4a..99dda83 100644 --- a/src/model/entities/NodeData.php +++ b/src/model/entities/NodeData.php @@ -27,9 +27,8 @@ class NodeData #[ORM\Column(type: "json")] private array $data; - #[ORM\ManyToOne(targetEntity: Presentation::class)] - #[ORM\JoinColumn(name: "presentation_id", referencedColumnName: "id_presentation", nullable: true)] - private ?Presentation $presentation; + #[ORM\Column(type: "string", length: 255, nullable: true)] + private ?string $presentation; #[ORM\Column(type: "integer", length: 255, nullable: true)] private ?int $grid_cols_min_width = null; // pour le mode grille @@ -43,12 +42,12 @@ class NodeData )] private Collection $images; - public function __construct(array $data, Node $node, Collection $images = new ArrayCollection, Presentation $presentation = null) + public function __construct(array $data, Node $node, Collection $images = new ArrayCollection, string $presentation = null) { $this->data = $data; $this->node = $node; $this->images = $images; - if(!empty($presentation) && $presentation->getName() === 'grid'){ + if(!empty($presentation) && $presentation === 'grid'){ $this->grid_cols_min_width = 250; } } @@ -75,11 +74,11 @@ class NodeData unset($this->data[$key]); } } - public function getPresentation(): ?Presentation + public function getPresentation(): ?string { return $this->presentation; } - public function setPresentation(Presentation $presentation): void + public function setPresentation(string $presentation): void { $this->presentation = $presentation; } diff --git a/src/model/entities/Presentation.php b/src/model/entities/Presentation.php deleted file mode 100644 index 6ada565..0000000 --- a/src/model/entities/Presentation.php +++ /dev/null @@ -1,47 +0,0 @@ - 'Pleine largeur', 'grid' => 'Grille', 'mosaic' => 'Mosaïque', 'carousel' => 'Carrousel']; - - #[ORM\Id] - #[ORM\GeneratedValue] - #[ORM\Column(type: "integer")] - private int $id_presentation; - - #[ORM\Column(type: "string", length: 255)] - private string $name; - - public function __construct(string $name) - { - $this->name = array_keys(self::$option_list)[0]; // = fullwidth, sécurité option inconnue - foreach(self::$option_list as $key => $value){ - if($name === $key){ - $this->name = $name; - } - } - } - - public function getName(): string - { - return $this->name; - } - - static public function findPresentation(EntityManager $entityManager, string $name): ?self - { - return $entityManager - ->createQuery('SELECT p FROM App\Entity\Presentation p WHERE p.name = :name') - ->setParameter('name', $name) - ->getOneOrNullResult(); - } -} \ No newline at end of file diff --git a/src/view/MainBuilder.php b/src/view/MainBuilder.php index 8a40d82..2510b08 100644 --- a/src/view/MainBuilder.php +++ b/src/view/MainBuilder.php @@ -55,14 +55,11 @@ class MainBuilder extends AbstractBuilder // mode modification de page uniquement private function viewEditBlocks($node): void { - $blocks = Blocks::getTypeNamePairs(); - $options = ''; - for($i = 0; $i < count($blocks); $i++){ - $options .= '\n"; + foreach(Blocks::$blocks as $key => $value){ + $options .= '\n"; } - //$page_id = Director::$page_path->getLast()->getId(); $head_node = null; foreach(ViewController::$root_node->getChildren() as $first_level_node){ if($first_level_node->getName() === 'head'){ @@ -88,7 +85,7 @@ class MainBuilder extends AbstractBuilder private function makePresentationOptions(string $presentation): string { $options = ''; - foreach(Presentation::$option_list as $key => $value){ + foreach(Blocks::$presentations as $key => $value){ $options .= ''; } return $options; diff --git a/src/view/NewsBlockBuilder.php b/src/view/NewsBlockBuilder.php index e7bbec9..963afe6 100644 --- a/src/view/NewsBlockBuilder.php +++ b/src/view/NewsBlockBuilder.php @@ -22,7 +22,7 @@ class NewsBlockBuilder extends AbstractBuilder } // stratégie d'affichage du contenu (utilisation de méthodes ou de classe List, GridPresentation, etc) - $section_class = $node->getNodeData()->getPresentation()->getName(); // = list, grid , mosaic ou carousel + $section_class = $node->getNodeData()->getPresentation(); // = list, grid , mosaic ou carousel $cols_min_width = ''; if($section_class === 'grid'){ $min_width = $node->getNodeData()->getColsMinWidth(); diff --git a/src/view/PostBlockBuilder.php b/src/view/PostBlockBuilder.php index dca4fbd..ba54901 100644 --- a/src/view/PostBlockBuilder.php +++ b/src/view/PostBlockBuilder.php @@ -22,7 +22,7 @@ class PostBlockBuilder extends AbstractBuilder } // stratégie d'affichage du contenu (utilisation de méthodes ou de classe List, GridPresentation, etc) - $section_class = $node->getNodeData()->getPresentation()->getName(); // = list, grid , mosaic ou carousel + $section_class = $node->getNodeData()->getPresentation(); // = list, grid , mosaic ou carousel $cols_min_width = ''; if($section_class === 'grid'){ $min_width = $node->getNodeData()->getColsMinWidth(); diff --git a/src/view/templates/modify_block.php b/src/view/templates/modify_block.php index 2514085..22a2932 100644 --- a/src/view/templates/modify_block.php +++ b/src/view/templates/modify_block.php @@ -1,6 +1,6 @@
-