aboutsummaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
Diffstat (limited to 'src/model')
-rw-r--r--src/model/Blocks.php17
-rw-r--r--src/model/Model.php3
-rw-r--r--src/model/entities/EmailForm.php1
-rw-r--r--src/model/entities/Node.php20
-rw-r--r--src/model/entities/NodeData.php20
-rw-r--r--src/model/entities/Presentation.php133
6 files changed, 155 insertions, 39 deletions
diff --git a/src/model/Blocks.php b/src/model/Blocks.php
deleted file mode 100644
index 786ec74..0000000
--- a/src/model/Blocks.php
+++ /dev/null
@@ -1,17 +0,0 @@
1<?php
2// src/model/Blocks.php
3
4class Blocks{
5 static public array $blocks = ['post_block' => 'Articles libres', 'news_block' => 'Actualités',
6 //'galery' => 'Galerie',
7 'calendar' => 'Calendrier', 'form' => 'Formulaire'];
8
9 static public array $presentations = ['fullwidth' => 'Pleine largeur', 'grid' => 'Grille', 'mosaic' => 'Mosaïque'
10 //, 'carousel' => 'Carrousel'
11 ];
12
13 static public function hasPresentation(string $block): bool
14 {
15 return in_array($block, ['post_block', 'news_block']) ? true : false;
16 }
17} \ No newline at end of file
diff --git a/src/model/Model.php b/src/model/Model.php
index 1054d57..15ff12a 100644
--- a/src/model/Model.php
+++ b/src/model/Model.php
@@ -9,6 +9,7 @@ declare(strict_types=1);
9use Doctrine\ORM\EntityManager; 9use Doctrine\ORM\EntityManager;
10use App\Entity\Page; 10use App\Entity\Page;
11use App\Entity\Node; 11use App\Entity\Node;
12use App\Entity\Presentation;
12use Doctrine\ORM\QueryBuilder; 13use Doctrine\ORM\QueryBuilder;
13use Symfony\Component\HttpFoundation\Request; 14use Symfony\Component\HttpFoundation\Request;
14 15
@@ -60,7 +61,7 @@ class Model
60 61
61 foreach($bulk_data as $parent_block){ 62 foreach($bulk_data as $parent_block){
62 // groupes d'articles triés par bloc, permet de paginer par bloc 63 // groupes d'articles triés par bloc, permet de paginer par bloc
63 if(Blocks::hasPresentation($parent_block->getName())){ // = post_block ou news_block 64 if(Presentation::hasPresentation($parent_block->getName())){ // = post_block ou news_block
64 $bulk_data = array_merge($bulk_data, $this->getNextArticles($parent_block, $request)[0]); 65 $bulk_data = array_merge($bulk_data, $this->getNextArticles($parent_block, $request)[0]);
65 } 66 }
66 67
diff --git a/src/model/entities/EmailForm.php b/src/model/entities/EmailForm.php
index 466a389..0dcdeec 100644
--- a/src/model/entities/EmailForm.php
+++ b/src/model/entities/EmailForm.php
@@ -6,7 +6,6 @@ declare(strict_types=1);
6namespace App\Entity; 6namespace App\Entity;
7 7
8use Doctrine\ORM\Mapping as ORM; 8use Doctrine\ORM\Mapping as ORM;
9//use Doctrine\Common\Collections\ArrayCollection;
10 9
11#[ORM\Entity] 10#[ORM\Entity]
12#[ORM\Table(name: TABLE_PREFIX . "email_form")] 11#[ORM\Table(name: TABLE_PREFIX . "email_form")]
diff --git a/src/model/entities/Node.php b/src/model/entities/Node.php
index fb2d867..7932efc 100644
--- a/src/model/entities/Node.php
+++ b/src/model/entities/Node.php
@@ -5,7 +5,6 @@ declare(strict_types=1);
5 5
6namespace App\Entity; 6namespace App\Entity;
7 7
8use Config;
9use Doctrine\ORM\Mapping as ORM; 8use Doctrine\ORM\Mapping as ORM;
10 9
11#[ORM\Entity] 10#[ORM\Entity]
@@ -48,6 +47,9 @@ class Node
48 #[ORM\OneToOne(targetEntity: EmailForm::class, mappedBy: "node", cascade: ['persist'])] // pas de remove, les e-mails sont associés au EmailForm 47 #[ORM\OneToOne(targetEntity: EmailForm::class, mappedBy: "node", cascade: ['persist'])] // pas de remove, les e-mails sont associés au EmailForm
49 private ?EmailForm $email_form = null; 48 private ?EmailForm $email_form = null;
50 49
50 #[ORM\OneToOne(targetEntity: Presentation::class, mappedBy: "node", cascade: ['persist', 'remove'])]
51 private ?Presentation $presentation = null;
52
51 // attributs non destinés à doctrine 53 // attributs non destinés à doctrine
52 private array $children = []; // tableau de Node 54 private array $children = []; // tableau de Node
53 private ?self $adopted = null; // = "new" est un enfant de "main" lorsque la page est "article" 55 private ?self $adopted = null; // = "new" est un enfant de "main" lorsque la page est "article"
@@ -111,11 +113,15 @@ class Node
111 113
112 // une interface serait cool! 114 // une interface serait cool!
113 // OU possible un "héritage doctrine", faire en sorte que Node soit la mère de NodeData, EmailForm, Article... 115 // OU possible un "héritage doctrine", faire en sorte que Node soit la mère de NodeData, EmailForm, Article...
114 // une seulle instance est matérialisée par plusieurs tables en même temps 116 // une seule instance est matérialisée par plusieurs tables en même temps
115 public function getNodeData(): NodeData|EmailForm|null 117 public function getNodeData(): NodeData|EmailForm|Presentation|null
116 { 118 {
117 // limite du polymorphisme avec doctrine => impossible d'avoir une unique variable $node_data 119 // pour du polymorphisme (une unique variable $node_data): opter pour l'héritage
118 return $this->name_node === 'form' ? $this->email_form : $this->node_data; 120 return match($this->name_node){
121 'form' => $this->email_form,
122 'post_block', 'news_block' => $this->presentation,
123 default => $this->node_data, // inclut 'calendar'
124 };
119 } 125 }
120 public function getChildren(): array 126 public function getChildren(): array
121 { 127 {
@@ -134,7 +140,7 @@ class Node
134 { 140 {
135 $this->children[] = $child; 141 $this->children[] = $child;
136 142
137 if(!\Blocks::hasPresentation($this->getName())){ // post_block et news_block ont leurs enfants ordonnés avec ORDER BY 143 if(!Presentation::hasPresentation($this->getName())){ // post_block et news_block ont leurs enfants ordonnés avec ORDER BY
138 $this->sortChildren(false); 144 $this->sortChildren(false);
139 } 145 }
140 } 146 }
diff --git a/src/model/entities/NodeData.php b/src/model/entities/NodeData.php
index c55f6a1..f6d6b01 100644
--- a/src/model/entities/NodeData.php
+++ b/src/model/entities/NodeData.php
@@ -24,7 +24,7 @@ class NodeData
24 // inverseBy fait le lien avec $node_data dans Node (qui a "mappedBy") 24 // inverseBy fait le lien avec $node_data dans Node (qui a "mappedBy")
25 #[ORM\OneToOne(targetEntity: Node::class, inversedBy: "node_data")] 25 #[ORM\OneToOne(targetEntity: Node::class, inversedBy: "node_data")]
26 #[ORM\JoinColumn(name: "node_id", referencedColumnName: "id_node", onDelete: "CASCADE")] 26 #[ORM\JoinColumn(name: "node_id", referencedColumnName: "id_node", onDelete: "CASCADE")]
27 private Node $node; 27 private ?Node $node;
28 28
29 #[ORM\Column(type: "json")] 29 #[ORM\Column(type: "json")]
30 private array $data; 30 private array $data;
@@ -44,18 +44,12 @@ class NodeData
44 #[ORM\OneToMany(mappedBy: 'node_data', targetEntity: AssetEmployment::class, cascade: ['persist', 'remove'])] 44 #[ORM\OneToMany(mappedBy: 'node_data', targetEntity: AssetEmployment::class, cascade: ['persist', 'remove'])]
45 private Collection $asset_employment; 45 private Collection $asset_employment;
46 46
47 private int $nb_pages = 1;
48 private array $emails = []; // => noeud "show_emails" 47 private array $emails = []; // => noeud "show_emails"
49 48
50 public function __construct(array $data, Node $node, Collection $asset_employment = new ArrayCollection, ?string $presentation = null, ?bool $chrono_order = null) 49 public function __construct(array $data, Node $node, Collection $asset_employment = new ArrayCollection){
51 {
52 $this->data = $data; 50 $this->data = $data;
53 $this->node = $node; 51 $this->node = $node;
54 $this->asset_employment = $asset_employment; 52 $this->asset_employment = $asset_employment;
55 if(!empty($presentation) && $presentation === 'grid'){
56 $this->grid_cols_min_width = 250;
57 }
58 $this->chrono_order = $chrono_order ?? null;
59 } 53 }
60 54
61 public function getId(): int 55 public function getId(): int
@@ -82,7 +76,7 @@ class NodeData
82 } 76 }
83 77
84 // spécifique aux blocs contenant des articles 78 // spécifique aux blocs contenant des articles
85 public function getPresentation(): ?string 79 /*public function getPresentation(): ?string
86 { 80 {
87 return $this->presentation; 81 return $this->presentation;
88 } 82 }
@@ -117,6 +111,7 @@ class NodeData
117 { 111 {
118 $this->pagination_limit = $pagination_limit; 112 $this->pagination_limit = $pagination_limit;
119 } 113 }
114 private int $nb_pages = 1;
120 public function getNumberOfPages(): int 115 public function getNumberOfPages(): int
121 { 116 {
122 return $this->nb_pages; 117 return $this->nb_pages;
@@ -124,13 +119,12 @@ class NodeData
124 public function setNumberOfPages(int $nb_pages): void 119 public function setNumberOfPages(int $nb_pages): void
125 { 120 {
126 $this->nb_pages = $nb_pages; 121 $this->nb_pages = $nb_pages;
127 } 122 }*/
128 123
129 /*public function setNode(Node $node): void 124 public function setNode(?Node $node): void
130 { 125 {
131 $this->node = $node; 126 $this->node = $node;
132 }*/ 127 }
133
134 128
135 public function getNodeDataAssets(): Collection 129 public function getNodeDataAssets(): Collection
136 { 130 {
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