From 0fa852ee4e9c3060ba7fc0daf4b08a44ea151f7f Mon Sep 17 00:00:00 2001 From: polo Date: Thu, 2 Jul 2026 00:01:31 +0200 Subject: =?UTF-8?q?entit=C3=A9=20Presentation,=20MAJ=20filtre=20ViewContro?= =?UTF-8?q?ller::SPECIAL=5FPAGES,=20table=20node=5Fdata=20non=20all=C3=A9g?= =?UTF-8?q?=C3=A9e=20pour=20l'instant?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/entities/EmailForm.php | 1 - src/model/entities/Node.php | 20 ++++-- src/model/entities/NodeData.php | 20 ++---- src/model/entities/Presentation.php | 133 ++++++++++++++++++++++++++++++++++++ 4 files changed, 153 insertions(+), 21 deletions(-) create mode 100644 src/model/entities/Presentation.php (limited to 'src/model/entities') 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); namespace App\Entity; use Doctrine\ORM\Mapping as ORM; -//use Doctrine\Common\Collections\ArrayCollection; #[ORM\Entity] #[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); namespace App\Entity; -use Config; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity] @@ -48,6 +47,9 @@ class Node #[ORM\OneToOne(targetEntity: EmailForm::class, mappedBy: "node", cascade: ['persist'])] // pas de remove, les e-mails sont associés au EmailForm private ?EmailForm $email_form = null; + #[ORM\OneToOne(targetEntity: Presentation::class, mappedBy: "node", cascade: ['persist', 'remove'])] + private ?Presentation $presentation = null; + // attributs non destinés à doctrine private array $children = []; // tableau de Node private ?self $adopted = null; // = "new" est un enfant de "main" lorsque la page est "article" @@ -111,11 +113,15 @@ class Node // une interface serait cool! // OU possible un "héritage doctrine", faire en sorte que Node soit la mère de NodeData, EmailForm, Article... - // une seulle instance est matérialisée par plusieurs tables en même temps - public function getNodeData(): NodeData|EmailForm|null - { - // limite du polymorphisme avec doctrine => impossible d'avoir une unique variable $node_data - return $this->name_node === 'form' ? $this->email_form : $this->node_data; + // une seule instance est matérialisée par plusieurs tables en même temps + public function getNodeData(): NodeData|EmailForm|Presentation|null + { + // pour du polymorphisme (une unique variable $node_data): opter pour l'héritage + return match($this->name_node){ + 'form' => $this->email_form, + 'post_block', 'news_block' => $this->presentation, + default => $this->node_data, // inclut 'calendar' + }; } public function getChildren(): array { @@ -134,7 +140,7 @@ class Node { $this->children[] = $child; - if(!\Blocks::hasPresentation($this->getName())){ // post_block et news_block ont leurs enfants ordonnés avec ORDER BY + if(!Presentation::hasPresentation($this->getName())){ // post_block et news_block ont leurs enfants ordonnés avec ORDER BY $this->sortChildren(false); } } 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 // inverseBy fait le lien avec $node_data dans Node (qui a "mappedBy") #[ORM\OneToOne(targetEntity: Node::class, inversedBy: "node_data")] #[ORM\JoinColumn(name: "node_id", referencedColumnName: "id_node", onDelete: "CASCADE")] - private Node $node; + private ?Node $node; #[ORM\Column(type: "json")] private array $data; @@ -44,18 +44,12 @@ class NodeData #[ORM\OneToMany(mappedBy: 'node_data', targetEntity: AssetEmployment::class, cascade: ['persist', 'remove'])] private Collection $asset_employment; - private int $nb_pages = 1; private array $emails = []; // => noeud "show_emails" - public function __construct(array $data, Node $node, Collection $asset_employment = new ArrayCollection, ?string $presentation = null, ?bool $chrono_order = null) - { + public function __construct(array $data, Node $node, Collection $asset_employment = new ArrayCollection){ $this->data = $data; $this->node = $node; $this->asset_employment = $asset_employment; - if(!empty($presentation) && $presentation === 'grid'){ - $this->grid_cols_min_width = 250; - } - $this->chrono_order = $chrono_order ?? null; } public function getId(): int @@ -82,7 +76,7 @@ class NodeData } // spécifique aux blocs contenant des articles - public function getPresentation(): ?string + /*public function getPresentation(): ?string { return $this->presentation; } @@ -117,6 +111,7 @@ class NodeData { $this->pagination_limit = $pagination_limit; } + private int $nb_pages = 1; public function getNumberOfPages(): int { return $this->nb_pages; @@ -124,13 +119,12 @@ class NodeData public function setNumberOfPages(int $nb_pages): void { $this->nb_pages = $nb_pages; - } + }*/ - /*public function setNode(Node $node): void + public function setNode(?Node $node): void { $this->node = $node; - }*/ - + } public function getNodeDataAssets(): Collection { 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 @@ +data = $data; + $this->node = $node; + /*if(!empty($presentation) && $presentation === 'grid'){ + $this->grid_cols_min_width = 250; + } + $this->chrono_order = $chrono_order ?? null;*/ + } + + /*public function getId(): int + { + return $this->id_presentation; + }*/ + + public function setNode(?Node $node): void + { + $this->node = $node; + } + + // un trait pour ça + public function getData(): array + { + return $this->data; + } + public function updateData(string $key, string|int|bool|array $value = ''): void + { + if($value !== ''){ + $this->data[$key] = $value; + } + // si $value est vide, supprime la clé + elseif(isset($this->data[$key])){ + unset($this->data[$key]); + } + } + + // spécifique aux blocs contenant des articles + public function getPresentation(): ?string + { + return $this->presentation; + } + public function setPresentation(string $presentation): void + { + $this->presentation = $presentation; + } + public function getColsMinWidth(): int + { + $default = 320; // pixels + return $this->grid_cols_min_width === null ? $default : $this->grid_cols_min_width; + } + public function setColsMinWidth(int $columns): void + { + $this->grid_cols_min_width = $columns; + } + public function getChronoOrder(): bool + { + return $this->chrono_order ?? false; + } + public function setChronoOrder(bool $reverse_order): void + { + $this->chrono_order = $reverse_order; + } + + public function getPaginationLimit(): ?int + { + $default = 12; // si 0 pas de pagination, 12 rend bien avec des grilles de 2, 3 ou 4 colonnes + return $this->pagination_limit === null ? $default : $this->pagination_limit; + } + public function setPaginationLimit(int $pagination_limit): void + { + $this->pagination_limit = $pagination_limit; + } + public function getNumberOfPages(): int + { + return $this->nb_pages; + } + public function setNumberOfPages(int $nb_pages): void + { + $this->nb_pages = $nb_pages; + } + + 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' + ]; + static public function hasPresentation(string $block): bool + { + return in_array($block, ['post_block', 'news_block']) ? true : false; + } +} \ No newline at end of file -- cgit v1.2.3