diff options
Diffstat (limited to 'src/model/entities/NodeData.php')
| -rw-r--r-- | src/model/entities/NodeData.php | 69 |
1 files changed, 48 insertions, 21 deletions
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 | |||
| 39 | #[ORM\Column(type: "integer", nullable: true)] | 39 | #[ORM\Column(type: "integer", nullable: true)] |
| 40 | private ?int $pagination_limit = null; // pour les post_block et news_block | 40 | private ?int $pagination_limit = null; // pour les post_block et news_block |
| 41 | 41 | ||
| 42 | #[ORM\ManyToMany(targetEntity: Asset::class, inversedBy: "node_data")] // cascade: ['remove'] = très dangereux! | 42 | #[ORM\OneToMany(mappedBy: 'node_data', targetEntity: NodeDataAsset::class, cascade: ['persist', 'remove'])] |
| 43 | #[ORM\JoinTable( | 43 | private Collection $nda_collection; |
| 44 | name: TABLE_PREFIX . "nodedata_asset", | ||
| 45 | joinColumns: [new ORM\JoinColumn(name: "node_data_id", referencedColumnName: "id_node_data", onDelete: "CASCADE")], // onDelete: "CASCADE": très utile | ||
| 46 | inverseJoinColumns: [new ORM\JoinColumn(name: "asset_id", referencedColumnName: "id_asset", onDelete: "CASCADE")] | ||
| 47 | )] | ||
| 48 | private Collection $assets; | ||
| 49 | 44 | ||
| 50 | private int $nb_pages = 1; | 45 | private int $nb_pages = 1; |
| 51 | 46 | ||
| 52 | public function __construct(array $data, Node $node, Collection $assets = new ArrayCollection, ?string $presentation = null, ?bool $chrono_order = null) | 47 | public function __construct(array $data, Node $node, Collection $nda_collection = new ArrayCollection, ?string $presentation = null, ?bool $chrono_order = null) |
| 53 | { | 48 | { |
| 54 | $this->data = $data; | 49 | $this->data = $data; |
| 55 | $this->node = $node; | 50 | $this->node = $node; |
| 56 | $this->assets = $assets; | 51 | $this->nda_collection = $nda_collection; |
| 57 | if(!empty($presentation) && $presentation === 'grid'){ | 52 | if(!empty($presentation) && $presentation === 'grid'){ |
| 58 | $this->grid_cols_min_width = 250; | 53 | $this->grid_cols_min_width = 250; |
| 59 | } | 54 | } |
| @@ -132,22 +127,54 @@ class NodeData | |||
| 132 | { | 127 | { |
| 133 | $this->node = $node; | 128 | $this->node = $node; |
| 134 | }*/ | 129 | }*/ |
| 135 | public function getAssets(): Collection | 130 | |
| 131 | |||
| 132 | public function getNodeDataAssets(): Collection | ||
| 136 | { | 133 | { |
| 137 | return $this->assets; | 134 | return $this->nda_collection; |
| 138 | } | 135 | } |
| 139 | public function addAsset(Asset $asset): void | 136 | public function getNodeDataAssetByRole(string $role): ?NodeDataAsset |
| 140 | { | 137 | { |
| 141 | if(!$this->assets->contains($asset)){ | 138 | foreach($this->nda_collection as $nda){ |
| 142 | $this->assets->add($asset); | 139 | if($nda->getRole() === $role){ |
| 143 | //$asset->addNodeData($this); // autre sens | 140 | return $nda; |
| 141 | } | ||
| 144 | } | 142 | } |
| 143 | return null; | ||
| 145 | } | 144 | } |
| 146 | public function removeAsset(Asset $asset): void | 145 | public function getAssetByRole(string $role): ?Asset |
| 147 | { | 146 | { |
| 148 | $this->assets->removeElement($asset); | 147 | $nda = $this->getNodeDataAssetByRole($role); |
| 149 | /*if($this->assets->removeElement($asset)){ // autre sens | 148 | if($nda === null){ |
| 150 | $asset->removeNodeData($this); | 149 | return null; |
| 151 | }*/ | 150 | } |
| 151 | return $nda->getAsset() ?? null; | ||
| 152 | } | 152 | } |
| 153 | } | 153 | /*public function addNodeDataAsset(NodeDataAsset $nda): self |
| 154 | { | ||
| 155 | if(!$this->nda_collection->contains($nda)){ // sécurité contrainte UNIQUE | ||
| 156 | $this->nda_collection->add($nda); | ||
| 157 | } | ||
| 158 | return $this; | ||
| 159 | }*/ | ||
| 160 | /*public function removeNodeDataAsset(NodeDataAsset $nda): self // inutile on peut faire: $node_data->getNodeDataAssets()->removeElement($nda); | ||
| 161 | { | ||
| 162 | $this->nda_collection->removeElement($nda); | ||
| 163 | // pas de synchro dans NodeDataAsset, les champs de cette table ne sont pas nullables | ||
| 164 | return $this; | ||
| 165 | }*/ | ||
| 166 | |||
| 167 | // LE setter, sélectionne l'asset à utiliser en remplaçant l'entrée dans NodeDataAsset en fonction du rôle | ||
| 168 | // à mettre théoriquement dans une classe metier dans "service" | ||
| 169 | /*public function replaceAssetForRole(string $role, Asset $asset): void | ||
| 170 | { | ||
| 171 | foreach($this->nda_collection as $nda){ | ||
| 172 | if($nda->getRole() === $role){ | ||
| 173 | $this->removeNodeDataAsset($nda); | ||
| 174 | break; | ||
| 175 | } | ||
| 176 | } | ||
| 177 | $this->new_nda = new NodeDataAsset($this, $asset, $role); | ||
| 178 | $this->addNodeDataAsset($this->new_nda); | ||
| 179 | }*/ | ||
| 180 | } \ No newline at end of file | ||
