From 5311271ae590460b986e3e09edcdc665b73710ca Mon Sep 17 00:00:00 2001 From: polo Date: Fri, 24 Oct 2025 02:27:19 +0200 Subject: =?UTF-8?q?entit=C3=A9=20pour=20table=20interm=C3=A9diaire=20?= =?UTF-8?q?=C3=A0=203=20champs=20entre=20NodeData=20et=20Asset,=20table=20?= =?UTF-8?q?Asset=20repens=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/entities/NodeData.php | 69 ++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 21 deletions(-) (limited to 'src/model/entities/NodeData.php') diff --git a/src/model/entities/NodeData.php b/src/model/entities/NodeData.php index 9db866e..47e7208 100644 --- a/src/model/entities/NodeData.php +++ b/src/model/entities/NodeData.php @@ -39,21 +39,16 @@ class NodeData #[ORM\Column(type: "integer", nullable: true)] private ?int $pagination_limit = null; // pour les post_block et news_block - #[ORM\ManyToMany(targetEntity: Asset::class, inversedBy: "node_data")] // cascade: ['remove'] = très dangereux! - #[ORM\JoinTable( - name: TABLE_PREFIX . "nodedata_asset", - joinColumns: [new ORM\JoinColumn(name: "node_data_id", referencedColumnName: "id_node_data", onDelete: "CASCADE")], // onDelete: "CASCADE": très utile - inverseJoinColumns: [new ORM\JoinColumn(name: "asset_id", referencedColumnName: "id_asset", onDelete: "CASCADE")] - )] - private Collection $assets; + #[ORM\OneToMany(mappedBy: 'node_data', targetEntity: NodeDataAsset::class, cascade: ['persist', 'remove'])] + private Collection $nda_collection; private int $nb_pages = 1; - public function __construct(array $data, Node $node, Collection $assets = new ArrayCollection, ?string $presentation = null, ?bool $chrono_order = null) + public function __construct(array $data, Node $node, Collection $nda_collection = new ArrayCollection, ?string $presentation = null, ?bool $chrono_order = null) { $this->data = $data; $this->node = $node; - $this->assets = $assets; + $this->nda_collection = $nda_collection; if(!empty($presentation) && $presentation === 'grid'){ $this->grid_cols_min_width = 250; } @@ -132,22 +127,54 @@ class NodeData { $this->node = $node; }*/ - public function getAssets(): Collection + + + public function getNodeDataAssets(): Collection { - return $this->assets; + return $this->nda_collection; } - public function addAsset(Asset $asset): void + public function getNodeDataAssetByRole(string $role): ?NodeDataAsset { - if(!$this->assets->contains($asset)){ - $this->assets->add($asset); - //$asset->addNodeData($this); // autre sens + foreach($this->nda_collection as $nda){ + if($nda->getRole() === $role){ + return $nda; + } } + return null; } - public function removeAsset(Asset $asset): void + public function getAssetByRole(string $role): ?Asset { - $this->assets->removeElement($asset); - /*if($this->assets->removeElement($asset)){ // autre sens - $asset->removeNodeData($this); - }*/ + $nda = $this->getNodeDataAssetByRole($role); + if($nda === null){ + return null; + } + return $nda->getAsset() ?? null; } -} + /*public function addNodeDataAsset(NodeDataAsset $nda): self + { + if(!$this->nda_collection->contains($nda)){ // sécurité contrainte UNIQUE + $this->nda_collection->add($nda); + } + return $this; + }*/ + /*public function removeNodeDataAsset(NodeDataAsset $nda): self // inutile on peut faire: $node_data->getNodeDataAssets()->removeElement($nda); + { + $this->nda_collection->removeElement($nda); + // pas de synchro dans NodeDataAsset, les champs de cette table ne sont pas nullables + return $this; + }*/ + + // LE setter, sélectionne l'asset à utiliser en remplaçant l'entrée dans NodeDataAsset en fonction du rôle + // à mettre théoriquement dans une classe metier dans "service" + /*public function replaceAssetForRole(string $role, Asset $asset): void + { + foreach($this->nda_collection as $nda){ + if($nda->getRole() === $role){ + $this->removeNodeDataAsset($nda); + break; + } + } + $this->new_nda = new NodeDataAsset($this, $asset, $role); + $this->addNodeDataAsset($this->new_nda); + }*/ +} \ No newline at end of file -- cgit v1.2.3