diff options
author | polo <ordipolo@gmx.fr> | 2025-09-26 12:04:02 +0200 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2025-09-26 12:04:02 +0200 |
commit | e93cd6c352a8e4fbb4e1174bdb15484adbe4c0f7 (patch) | |
tree | 7fd1591a25d3557f5869a688bad28db533d6b414 | |
parent | f977313ff095a10478291334109d9aae40528a34 (diff) | |
download | cms-e93cd6c352a8e4fbb4e1174bdb15484adbe4c0f7.zip |
suppression table Presentation
-rw-r--r-- | src/controller/PageManagementController.php | 13 | ||||
-rw-r--r-- | src/installation.php | 13 | ||||
-rw-r--r-- | src/model/Blocks.php | 37 | ||||
-rw-r--r-- | src/model/entities/Log.php | 7 | ||||
-rw-r--r-- | src/model/entities/NodeData.php | 13 | ||||
-rw-r--r-- | src/model/entities/Presentation.php | 47 | ||||
-rw-r--r-- | src/view/MainBuilder.php | 9 | ||||
-rw-r--r-- | src/view/NewsBlockBuilder.php | 2 | ||||
-rw-r--r-- | src/view/PostBlockBuilder.php | 2 | ||||
-rw-r--r-- | src/view/templates/modify_block.php | 6 |
10 files changed, 26 insertions, 123 deletions
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 | |||
135 | $main = $director->getNode(); | 135 | $main = $director->getNode(); |
136 | $position = count($main->getChildren()) + 1; // position dans la fraterie | 136 | $position = count($main->getChildren()) + 1; // position dans la fraterie |
137 | 137 | ||
138 | if(!in_array($_POST["bloc_select"], Blocks::getNameList(), true)) // 3è param: contrôle du type | 138 | if(!in_array($_POST["bloc_select"], array_keys(Blocks::$blocks), true)) // 3è param: contrôle du type |
139 | { | 139 | { |
140 | header("Location: " . new URL(['page' => $_GET['page'], 'error' => 'bad_bloc_type'])); | 140 | header("Location: " . new URL(['page' => $_GET['page'], 'error' => 'bad_bloc_type'])); |
141 | die; | 141 | die; |
@@ -168,13 +168,13 @@ class PageManagementController | |||
168 | 168 | ||
169 | // valeurs par défaut | 169 | // valeurs par défaut |
170 | if($_POST["bloc_select"] === 'post_block'){ | 170 | if($_POST["bloc_select"] === 'post_block'){ |
171 | $data->setPresentation(Presentation::findPresentation($entityManager, 'fullwidth')); // pas génial l'utilisation de l'index dans la table | 171 | $data->setPresentation('fullwidth'); |
172 | } | 172 | } |
173 | elseif($_POST["bloc_select"] === 'news_block'){ | 173 | elseif($_POST["bloc_select"] === 'news_block'){ |
174 | $data->setPresentation(Presentation::findPresentation($entityManager, 'grid')); | 174 | $data->setPresentation('grid'); |
175 | } | 175 | } |
176 | elseif($_POST["bloc_select"] === 'galery'){ | 176 | elseif($_POST["bloc_select"] === 'galery'){ |
177 | $data->setPresentation(Presentation::findPresentation($entityManager, 'mosaic')); // mieux que carousel pour commencer | 177 | $data->setPresentation('mosaic'); // mieux que carousel pour commencer |
178 | } | 178 | } |
179 | // else = null par défaut | 179 | // else = null par défaut |
180 | 180 | ||
@@ -274,9 +274,8 @@ class PageManagementController | |||
274 | $director = new Director($entityManager, false); | 274 | $director = new Director($entityManager, false); |
275 | $director->findNodeById($json['id']); | 275 | $director->findNodeById($json['id']); |
276 | 276 | ||
277 | $presentation = Presentation::findPresentation($entityManager, $json['presentation']); | 277 | if(in_array($json['presentation'], array_keys(Blocks::$presentations))){ |
278 | if($presentation !== null){ | 278 | $director->getNode()->getNodeData()->setPresentation($json['presentation']); |
279 | $director->getNode()->getNodeData()->setPresentation($presentation); | ||
280 | 279 | ||
281 | $entityManager->flush(); | 280 | $entityManager->flush(); |
282 | 281 | ||
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; | |||
7 | use App\Entity\Node; | 7 | use App\Entity\Node; |
8 | use App\Entity\NodeData; | 8 | use App\Entity\NodeData; |
9 | use App\Entity\Image; | 9 | use App\Entity\Image; |
10 | use App\Entity\Presentation; | ||
11 | use Doctrine\Common\Collections\ArrayCollection; | 10 | use Doctrine\Common\Collections\ArrayCollection; |
12 | use Doctrine\ORM\EntityManager; | 11 | use Doctrine\ORM\EntityManager; |
13 | 12 | ||
@@ -117,12 +116,6 @@ function makeStartPage(EntityManager $entityManager){ | |||
117 | $head_new_page = new Node('head', ['css_array' => ['body', 'head', 'nav', 'new_page', 'foot'], 'js_array' => ['main', 'new_page']], 1, NULL, $new_page, NULL); | 116 | $head_new_page = new Node('head', ['css_array' => ['body', 'head', 'nav', 'new_page', 'foot'], 'js_array' => ['main', 'new_page']], 1, NULL, $new_page, NULL); |
118 | $bloc_new_page = new Node('new_page', [], 1, $main, $new_page, NULL); | 117 | $bloc_new_page = new Node('new_page', [], 1, $main, $new_page, NULL); |
119 | 118 | ||
120 | /* -- table presentation -- */ | ||
121 | $fullwidth = new Presentation('fullwidth'); | ||
122 | $grid = new Presentation('grid'); | ||
123 | $mosaic = new Presentation('mosaic'); | ||
124 | $carousel = new Presentation('carousel'); | ||
125 | |||
126 | /* -- table image -- */ | 119 | /* -- table image -- */ |
127 | // paramètres: file_name, file_path, file_path_mini, mime_type, alt | 120 | // paramètres: file_name, file_path, file_path_mini, mime_type, alt |
128 | $favicon = new Image("favicon48x48.png", NULL, "assets/favicon48x48.png", "image/png", "favicon"); | 121 | $favicon = new Image("favicon48x48.png", NULL, "assets/favicon48x48.png", "image/png", "favicon"); |
@@ -169,12 +162,6 @@ function makeStartPage(EntityManager $entityManager){ | |||
169 | $entityManager->persist($bloc_edit_menu); | 162 | $entityManager->persist($bloc_edit_menu); |
170 | $entityManager->persist($head_new_page); | 163 | $entityManager->persist($head_new_page); |
171 | $entityManager->persist($bloc_new_page); | 164 | $entityManager->persist($bloc_new_page); |
172 | |||
173 | /* -- table presentation -- */ | ||
174 | $entityManager->persist($fullwidth); | ||
175 | $entityManager->persist($grid); | ||
176 | $entityManager->persist($mosaic); | ||
177 | $entityManager->persist($carousel); | ||
178 | 165 | ||
179 | /* -- table image -- */ | 166 | /* -- table image -- */ |
180 | $entityManager->persist($favicon); | 167 | $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 @@ | |||
1 | <?php | 1 | <?php |
2 | // src/Blocks.php | 2 | // src/model/Blocks.php |
3 | 3 | ||
4 | class Blocks{ | 4 | class Blocks{ |
5 | /*private array $types = ['blog', 'grid', 'calendar', 'galery', 'form'];*/ | 5 | static public array $blocks = ['post_block' => 'Articles libres', 'news_block' => 'Actualités', 'galery' => 'Galerie', 'calendar' => 'Calendrier', 'form' => 'Formulaire']; |
6 | static private array $types = ['post_block', 'news_block', 'galery', 'calendar', 'form']; | 6 | static public array $presentations = ['fullwidth' => 'Pleine largeur', 'grid' => 'Grille', 'mosaic' => 'Mosaïque', 'carousel' => 'Carrousel']; |
7 | |||
8 | /*private array $names = ['Blog', 'Grille', 'Calendrier', 'Galerie', 'Formulaire'];*/ | ||
9 | static private array $names = ['Articles libres', 'Actualités', 'Galerie', 'Calendrier', 'Formulaire']; | ||
10 | |||
11 | static public function getNameList(): array | ||
12 | { | ||
13 | $blocks = []; | ||
14 | foreach(self::$types as $type){ | ||
15 | $blocks[] = $type; | ||
16 | } | ||
17 | return $blocks; | ||
18 | } | ||
19 | |||
20 | static public function getTypeNamePairs(): array | ||
21 | { | ||
22 | $blocks = []; | ||
23 | for($i = 0; $i < count(self::$types); $i++){ | ||
24 | $blocks[] = ['type' => self::$types[$i], 'name' => self::$names[$i]]; | ||
25 | } | ||
26 | return $blocks; | ||
27 | } | ||
28 | |||
29 | static public function getNameFromType(string $type): string | ||
30 | { | ||
31 | for($i=0; $i < count(self::$types); $i++){ | ||
32 | if(self::$types[$i] === $type){ | ||
33 | return self::$names[$i]; | ||
34 | } | ||
35 | } | ||
36 | return 'server side error'; | ||
37 | } | ||
38 | } \ No newline at end of file | 7 | } \ 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 | |||
16 | #[ORM\Column(type: "integer")] | 16 | #[ORM\Column(type: "integer")] |
17 | private int $id_log; | 17 | private int $id_log; |
18 | 18 | ||
19 | #[ORM\Column(type: 'datetime', options: ['default' => 'CURRENT_TIMESTAMP'])] | 19 | #[ORM\Column(type: 'datetime', options: ['default' => 'CURRENT_TIMESTAMP'])] // CURRENT_TIMESTAMP "inutile", date générée par PHP |
20 | //#[ORM\Column(type: 'datetime', columnDefinition: "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")] | 20 | private \DateTime $date_time; // type datetime de doctrine <=> type \DateTime de PHP |
21 | private ?\DateTime $date_time ; // le type datetime de doctrine convertit en type \DateTime de PHP | ||
22 | 21 | ||
23 | #[ORM\Column(type: "boolean")] | 22 | #[ORM\Column(type: "boolean")] |
24 | private bool $success; | 23 | private bool $success; |
25 | 24 | ||
26 | public function __construct(bool $success){ | 25 | public function __construct(bool $success){ |
27 | $this->date_time = new \DateTime(); | 26 | $this->date_time = new \DateTime; |
28 | $this->success = $success; | 27 | $this->success = $success; |
29 | } | 28 | } |
30 | } | 29 | } |
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 | |||
27 | #[ORM\Column(type: "json")] | 27 | #[ORM\Column(type: "json")] |
28 | private array $data; | 28 | private array $data; |
29 | 29 | ||
30 | #[ORM\ManyToOne(targetEntity: Presentation::class)] | 30 | #[ORM\Column(type: "string", length: 255, nullable: true)] |
31 | #[ORM\JoinColumn(name: "presentation_id", referencedColumnName: "id_presentation", nullable: true)] | 31 | private ?string $presentation; |
32 | private ?Presentation $presentation; | ||
33 | 32 | ||
34 | #[ORM\Column(type: "integer", length: 255, nullable: true)] | 33 | #[ORM\Column(type: "integer", length: 255, nullable: true)] |
35 | private ?int $grid_cols_min_width = null; // pour le mode grille | 34 | private ?int $grid_cols_min_width = null; // pour le mode grille |
@@ -43,12 +42,12 @@ class NodeData | |||
43 | )] | 42 | )] |
44 | private Collection $images; | 43 | private Collection $images; |
45 | 44 | ||
46 | public function __construct(array $data, Node $node, Collection $images = new ArrayCollection, Presentation $presentation = null) | 45 | public function __construct(array $data, Node $node, Collection $images = new ArrayCollection, string $presentation = null) |
47 | { | 46 | { |
48 | $this->data = $data; | 47 | $this->data = $data; |
49 | $this->node = $node; | 48 | $this->node = $node; |
50 | $this->images = $images; | 49 | $this->images = $images; |
51 | if(!empty($presentation) && $presentation->getName() === 'grid'){ | 50 | if(!empty($presentation) && $presentation === 'grid'){ |
52 | $this->grid_cols_min_width = 250; | 51 | $this->grid_cols_min_width = 250; |
53 | } | 52 | } |
54 | } | 53 | } |
@@ -75,11 +74,11 @@ class NodeData | |||
75 | unset($this->data[$key]); | 74 | unset($this->data[$key]); |
76 | } | 75 | } |
77 | } | 76 | } |
78 | public function getPresentation(): ?Presentation | 77 | public function getPresentation(): ?string |
79 | { | 78 | { |
80 | return $this->presentation; | 79 | return $this->presentation; |
81 | } | 80 | } |
82 | public function setPresentation(Presentation $presentation): void | 81 | public function setPresentation(string $presentation): void |
83 | { | 82 | { |
84 | $this->presentation = $presentation; | 83 | $this->presentation = $presentation; |
85 | } | 84 | } |
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 @@ | |||
1 | <?php | ||
2 | // src/model/entities/Presentation.php | ||
3 | |||
4 | declare(strict_types=1); | ||
5 | |||
6 | namespace App\Entity; | ||
7 | |||
8 | use Doctrine\ORM\EntityManager; | ||
9 | use Doctrine\ORM\Mapping as ORM; | ||
10 | |||
11 | #[ORM\Entity] | ||
12 | #[ORM\Table(name: TABLE_PREFIX . "presentation")] | ||
13 | class Presentation | ||
14 | { | ||
15 | static public array $option_list = ['fullwidth' => 'Pleine largeur', 'grid' => 'Grille', 'mosaic' => 'Mosaïque', 'carousel' => 'Carrousel']; | ||
16 | |||
17 | #[ORM\Id] | ||
18 | #[ORM\GeneratedValue] | ||
19 | #[ORM\Column(type: "integer")] | ||
20 | private int $id_presentation; | ||
21 | |||
22 | #[ORM\Column(type: "string", length: 255)] | ||
23 | private string $name; | ||
24 | |||
25 | public function __construct(string $name) | ||
26 | { | ||
27 | $this->name = array_keys(self::$option_list)[0]; // = fullwidth, sécurité option inconnue | ||
28 | foreach(self::$option_list as $key => $value){ | ||
29 | if($name === $key){ | ||
30 | $this->name = $name; | ||
31 | } | ||
32 | } | ||
33 | } | ||
34 | |||
35 | public function getName(): string | ||
36 | { | ||
37 | return $this->name; | ||
38 | } | ||
39 | |||
40 | static public function findPresentation(EntityManager $entityManager, string $name): ?self | ||
41 | { | ||
42 | return $entityManager | ||
43 | ->createQuery('SELECT p FROM App\Entity\Presentation p WHERE p.name = :name') | ||
44 | ->setParameter('name', $name) | ||
45 | ->getOneOrNullResult(); | ||
46 | } | ||
47 | } \ 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 | |||
55 | // mode modification de page uniquement | 55 | // mode modification de page uniquement |
56 | private function viewEditBlocks($node): void | 56 | private function viewEditBlocks($node): void |
57 | { | 57 | { |
58 | $blocks = Blocks::getTypeNamePairs(); | ||
59 | |||
60 | $options = ''; | 58 | $options = ''; |
61 | for($i = 0; $i < count($blocks); $i++){ | 59 | foreach(Blocks::$blocks as $key => $value){ |
62 | $options .= '<option value= "' . $blocks[$i]['type'] . '">' . $blocks[$i]['name'] . "</option>\n"; | 60 | $options .= '<option value= "' . $key . '">' . $value . "</option>\n"; |
63 | } | 61 | } |
64 | 62 | ||
65 | //$page_id = Director::$page_path->getLast()->getId(); | ||
66 | $head_node = null; | 63 | $head_node = null; |
67 | foreach(ViewController::$root_node->getChildren() as $first_level_node){ | 64 | foreach(ViewController::$root_node->getChildren() as $first_level_node){ |
68 | if($first_level_node->getName() === 'head'){ | 65 | if($first_level_node->getName() === 'head'){ |
@@ -88,7 +85,7 @@ class MainBuilder extends AbstractBuilder | |||
88 | private function makePresentationOptions(string $presentation): string | 85 | private function makePresentationOptions(string $presentation): string |
89 | { | 86 | { |
90 | $options = ''; | 87 | $options = ''; |
91 | foreach(Presentation::$option_list as $key => $value){ | 88 | foreach(Blocks::$presentations as $key => $value){ |
92 | $options .= '<option value="' . $key . '" ' . ($presentation === $key ? 'selected' : '') . '>' . $value . '</option>'; | 89 | $options .= '<option value="' . $key . '" ' . ($presentation === $key ? 'selected' : '') . '>' . $value . '</option>'; |
93 | } | 90 | } |
94 | return $options; | 91 | 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 | |||
22 | } | 22 | } |
23 | 23 | ||
24 | // stratégie d'affichage du contenu (utilisation de méthodes ou de classe List, GridPresentation, etc) | 24 | // stratégie d'affichage du contenu (utilisation de méthodes ou de classe List, GridPresentation, etc) |
25 | $section_class = $node->getNodeData()->getPresentation()->getName(); // = list, grid , mosaic ou carousel | 25 | $section_class = $node->getNodeData()->getPresentation(); // = list, grid , mosaic ou carousel |
26 | $cols_min_width = ''; | 26 | $cols_min_width = ''; |
27 | if($section_class === 'grid'){ | 27 | if($section_class === 'grid'){ |
28 | $min_width = $node->getNodeData()->getColsMinWidth(); | 28 | $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 | |||
22 | } | 22 | } |
23 | 23 | ||
24 | // stratégie d'affichage du contenu (utilisation de méthodes ou de classe List, GridPresentation, etc) | 24 | // stratégie d'affichage du contenu (utilisation de méthodes ou de classe List, GridPresentation, etc) |
25 | $section_class = $node->getNodeData()->getPresentation()->getName(); // = list, grid , mosaic ou carousel | 25 | $section_class = $node->getNodeData()->getPresentation(); // = list, grid , mosaic ou carousel |
26 | $cols_min_width = ''; | 26 | $cols_min_width = ''; |
27 | if($section_class === 'grid'){ | 27 | if($section_class === 'grid'){ |
28 | $min_width = $node->getNodeData()->getColsMinWidth(); | 28 | $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 @@ | |||
1 | <div class="modify_one_block" id="bloc_edit_<?= $child_node->getId() ?>"> | 1 | <div class="modify_one_block" id="bloc_edit_<?= $child_node->getId() ?>"> |
2 | <div class="block_options"> | 2 | <div class="block_options"> |
3 | <label for="bloc_rename_<?= $child_node->getId() ?>">Type <b><?= Blocks::getNameFromType($child_node->getName()) ?></b> | 3 | <label for="bloc_rename_<?= $child_node->getId() ?>">Type <b><?= Blocks::$blocks[$child_node->getName()] ?></b> |
4 | </label> | 4 | </label> |
5 | <p> | 5 | <p> |
6 | <input type="text" id="bloc_rename_<?= $child_node->getId() ?>" name="bloc_rename_title" value="<?= $child_node->getNodeData()->getdata()['title'] ?>" required> | 6 | <input type="text" id="bloc_rename_<?= $child_node->getId() ?>" name="bloc_rename_title" value="<?= $child_node->getNodeData()->getdata()['title'] ?>" required> |
@@ -24,9 +24,9 @@ if($child_node->getNodeData()->getPresentation() !== null){ | |||
24 | <div class="grid_options"><p> | 24 | <div class="grid_options"><p> |
25 | <label for="presentation_select_<?= $child_node->getId() ?>">Présentation</label> | 25 | <label for="presentation_select_<?= $child_node->getId() ?>">Présentation</label> |
26 | <select id="presentation_select_<?= $child_node->getId() ?>" onchange="changePresentation(<?= $child_node->getId() ?>)"> | 26 | <select id="presentation_select_<?= $child_node->getId() ?>" onchange="changePresentation(<?= $child_node->getId() ?>)"> |
27 | <?= $this->makePresentationOptions($child_node->getNodeData()->getPresentation()->getName()) ?> | 27 | <?= $this->makePresentationOptions($child_node->getNodeData()->getPresentation()) ?> |
28 | </select> | 28 | </select> |
29 | <div id="cols_min_width_edit_<?= $child_node->getId() ?>" class="<?= ($child_node->getNodeData()->getPresentation()->getName() === 'grid' ? '' : 'hidden') ?>"> | 29 | <div id="cols_min_width_edit_<?= $child_node->getId() ?>" class="<?= ($child_node->getNodeData()->getPresentation() === 'grid' ? '' : 'hidden') ?>"> |
30 | <label for="cols_min_width_select_<?= $child_node->getId() ?>">Largeur minimum </label> | 30 | <label for="cols_min_width_select_<?= $child_node->getId() ?>">Largeur minimum </label> |
31 | <input type="number" id="cols_min_width_select_<?= $child_node->getId() ?>" onchange="changeColsMinWidth(<?= $child_node->getId() ?>)" min="150" max="400" value="<?= $child_node->getNodeData()->getColsMinWidth() ?>"> pixels | 31 | <input type="number" id="cols_min_width_select_<?= $child_node->getId() ?>" onchange="changeColsMinWidth(<?= $child_node->getId() ?>)" min="150" max="400" value="<?= $child_node->getNodeData()->getColsMinWidth() ?>"> pixels |
32 | </div> | 32 | </div> |