aboutsummaryrefslogtreecommitdiff
path: root/src/model/entities/Presentation.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/model/entities/Presentation.php')
-rw-r--r--src/model/entities/Presentation.php133
1 files changed, 133 insertions, 0 deletions
diff --git a/src/model/entities/Presentation.php b/src/model/entities/Presentation.php
new file mode 100644
index 0000000..912c19e
--- /dev/null
+++ b/src/model/entities/Presentation.php
@@ -0,0 +1,133 @@
1<?php
2// src/model/entities/Presentation.php
3
4declare(strict_types=1);
5
6namespace App\Entity;
7
8use Doctrine\ORM\Mapping as ORM;
9
10#[ORM\Entity]
11#[ORM\Table(name: TABLE_PREFIX . "presentation")]
12class Presentation{
13 #[ORM\Id]
14 #[ORM\GeneratedValue]
15 #[ORM\Column(type: "integer")]
16 private int $id_presentation;
17
18 // inverseBy fait le lien avec $presentation dans Node (qui a "mappedBy")
19 #[ORM\OneToOne(targetEntity: Node::class, inversedBy: "presentation")]
20 #[ORM\JoinColumn(name: "node_id", referencedColumnName: "id_node")]
21 private ?Node $node;
22
23 #[ORM\Column(type: "json")]
24 private array $data;
25
26 #[ORM\Column(type: "string", length: 255, nullable: true)]
27 private ?string $presentation;
28
29 #[ORM\Column(type: "boolean", length: 255, nullable: true)]
30 private ?bool $chrono_order = null;
31
32 #[ORM\Column(type: "integer", nullable: true)]
33 private ?int $grid_cols_min_width = null; // pour le mode grille
34
35 #[ORM\Column(type: "integer", nullable: true)]
36 private ?int $pagination_limit = null; // pour les post_block et news_block
37
38 private int $nb_pages = 1;
39
40 public function __construct(array $data, Node $node
41 //, ?string $presentation = null, ?bool $chrono_order = null
42 ){
43 $this->data = $data;
44 $this->node = $node;
45 /*if(!empty($presentation) && $presentation === 'grid'){
46 $this->grid_cols_min_width = 250;
47 }
48 $this->chrono_order = $chrono_order ?? null;*/
49 }
50
51 /*public function getId(): int
52 {
53 return $this->id_presentation;
54 }*/
55
56 public function setNode(?Node $node): void
57 {
58 $this->node = $node;
59 }
60
61 // un trait pour ça
62 public function getData(): array
63 {
64 return $this->data;
65 }
66 public function updateData(string $key, string|int|bool|array $value = ''): void
67 {
68 if($value !== ''){
69 $this->data[$key] = $value;
70 }
71 // si $value est vide, supprime la clé
72 elseif(isset($this->data[$key])){
73 unset($this->data[$key]);
74 }
75 }
76
77 // spécifique aux blocs contenant des articles
78 public function getPresentation(): ?string
79 {
80 return $this->presentation;
81 }
82 public function setPresentation(string $presentation): void
83 {
84 $this->presentation = $presentation;
85 }
86 public function getColsMinWidth(): int
87 {
88 $default = 320; // pixels
89 return $this->grid_cols_min_width === null ? $default : $this->grid_cols_min_width;
90 }
91 public function setColsMinWidth(int $columns): void
92 {
93 $this->grid_cols_min_width = $columns;
94 }
95 public function getChronoOrder(): bool
96 {
97 return $this->chrono_order ?? false;
98 }
99 public function setChronoOrder(bool $reverse_order): void
100 {
101 $this->chrono_order = $reverse_order;
102 }
103
104 public function getPaginationLimit(): ?int
105 {
106 $default = 12; // si 0 pas de pagination, 12 rend bien avec des grilles de 2, 3 ou 4 colonnes
107 return $this->pagination_limit === null ? $default : $this->pagination_limit;
108 }
109 public function setPaginationLimit(int $pagination_limit): void
110 {
111 $this->pagination_limit = $pagination_limit;
112 }
113 public function getNumberOfPages(): int
114 {
115 return $this->nb_pages;
116 }
117 public function setNumberOfPages(int $nb_pages): void
118 {
119 $this->nb_pages = $nb_pages;
120 }
121
122 static public array $blocks = ['post_block' => 'Articles libres', 'news_block' => 'Actualités',
123 //'galery' => 'Galerie',
124 'calendar' => 'Calendrier', 'form' => 'Formulaire'
125 ];
126 static public array $presentations = ['fullwidth' => 'Pleine largeur', 'grid' => 'Grille', 'mosaic' => 'Mosaïque'
127 //, 'carousel' => 'Carrousel'
128 ];
129 static public function hasPresentation(string $block): bool
130 {
131 return in_array($block, ['post_block', 'news_block']) ? true : false;
132 }
133} \ No newline at end of file