diff options
Diffstat (limited to 'src/Model/Entity/NodeData.php')
| -rw-r--r-- | src/Model/Entity/NodeData.php | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/src/Model/Entity/NodeData.php b/src/Model/Entity/NodeData.php new file mode 100644 index 0000000..d81628d --- /dev/null +++ b/src/Model/Entity/NodeData.php | |||
| @@ -0,0 +1,102 @@ | |||
| 1 | <?php | ||
| 2 | // src/Model/Entity/NodeData.php | ||
| 3 | |||
| 4 | declare(strict_types=1); | ||
| 5 | |||
| 6 | namespace App\Entity; | ||
| 7 | |||
| 8 | use Doctrine\ORM\Mapping as ORM; | ||
| 9 | use Doctrine\Common\Collections\ArrayCollection; // classe | ||
| 10 | use Doctrine\Common\Collections\Collection; // interface | ||
| 11 | |||
| 12 | #[ORM\Entity] | ||
| 13 | #[ORM\Table(name: TABLE_PREFIX . "node_data")] | ||
| 14 | class NodeData | ||
| 15 | { | ||
| 16 | static array $social_networks = ['globe', 'facebook', 'instagram', 'whatsapp', 'snapchat', 'tiktok', 'linkedin', 'github']; // à completer | ||
| 17 | |||
| 18 | #[ORM\Id] | ||
| 19 | #[ORM\GeneratedValue] | ||
| 20 | #[ORM\Column(type: "integer")] | ||
| 21 | private int $id_node_data; | ||
| 22 | |||
| 23 | // onDelete: "CASCADE" supprime les données si le noeud est supprimé | ||
| 24 | // inverseBy fait le lien avec $node_data dans Node (qui a "mappedBy") | ||
| 25 | #[ORM\OneToOne(targetEntity: Node::class, inversedBy: "node_data")] | ||
| 26 | #[ORM\JoinColumn(name: "node_id", referencedColumnName: "id_node", onDelete: "CASCADE")] | ||
| 27 | private ?Node $node; | ||
| 28 | |||
| 29 | #[ORM\Column(type: "json")] | ||
| 30 | private array $data; | ||
| 31 | |||
| 32 | #[ORM\OneToMany(mappedBy: 'node_data', targetEntity: AssetEmployment::class, cascade: ['persist', 'remove'])] | ||
| 33 | private Collection $asset_employment; | ||
| 34 | |||
| 35 | private array $emails = []; // => noeud "show_emails" | ||
| 36 | |||
| 37 | public function __construct(array $data, Node $node, Collection $asset_employment = new ArrayCollection){ | ||
| 38 | $this->data = $data; | ||
| 39 | $this->node = $node; | ||
| 40 | $this->asset_employment = $asset_employment; | ||
| 41 | } | ||
| 42 | |||
| 43 | public function getId(): int | ||
| 44 | { | ||
| 45 | return $this->id_node_data; | ||
| 46 | } | ||
| 47 | public function getData(): array | ||
| 48 | { | ||
| 49 | return $this->data; | ||
| 50 | } | ||
| 51 | /*public function setData(array $data): void // entrée = tableau associatif | ||
| 52 | { | ||
| 53 | $this->data = $data; | ||
| 54 | }*/ | ||
| 55 | public function updateData(string $key, string|int|bool|array $value = ''): void | ||
| 56 | { | ||
| 57 | if($value !== ''){ | ||
| 58 | $this->data[$key] = $value; | ||
| 59 | } | ||
| 60 | // si $value est vide, supprime la clé | ||
| 61 | elseif(isset($this->data[$key])){ | ||
| 62 | unset($this->data[$key]); | ||
| 63 | } | ||
| 64 | } | ||
| 65 | |||
| 66 | public function setNode(?Node $node): void | ||
| 67 | { | ||
| 68 | $this->node = $node; | ||
| 69 | } | ||
| 70 | |||
| 71 | public function getNodeDataAssets(): Collection | ||
| 72 | { | ||
| 73 | return $this->asset_employment; | ||
| 74 | } | ||
| 75 | public function getAssetEmploymentByRole(string $role): ?AssetEmployment | ||
| 76 | { | ||
| 77 | foreach($this->asset_employment as $nda){ | ||
| 78 | if($nda->getRole() === $role){ | ||
| 79 | return $nda; | ||
| 80 | } | ||
| 81 | } | ||
| 82 | return null; | ||
| 83 | } | ||
| 84 | public function getAssetByRole(string $role): ?Asset | ||
| 85 | { | ||
| 86 | $nda = $this->getAssetEmploymentByRole($role); | ||
| 87 | if($nda === null){ | ||
| 88 | return null; | ||
| 89 | } | ||
| 90 | return $nda->getAsset() ?? null; | ||
| 91 | } | ||
| 92 | |||
| 93 | // pour affichage page Courriels | ||
| 94 | public function getEmails(): array // appelée dans ShowEmailsBuilder | ||
| 95 | { | ||
| 96 | return $this->emails; | ||
| 97 | } | ||
| 98 | public function setEmails(array $emails): void // appelée dans Model | ||
| 99 | { | ||
| 100 | $this->emails = $emails; | ||
| 101 | } | ||
| 102 | } \ No newline at end of file | ||
