From ef8a7c9973f5014453b1bf5bf8a50156acc51346 Mon Sep 17 00:00:00 2001 From: Ruslan Baidan Date: Mon, 10 Jun 2024 11:23:14 +0200 Subject: [PATCH] Added the relation between objects and rolf tags in the entity. --- src/Entity/ObjectSuperClass.php | 5 +++++ src/Entity/RolfTagSuperClass.php | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/Entity/ObjectSuperClass.php b/src/Entity/ObjectSuperClass.php index 3b172181..721eb1e7 100755 --- a/src/Entity/ObjectSuperClass.php +++ b/src/Entity/ObjectSuperClass.php @@ -219,6 +219,11 @@ public function getRolfTag(): ?RolfTagSuperClass public function setRolfTag(?RolfTagSuperClass $rolfTag) { + if ($rolfTag !== null) { + $rolfTag->addObject($this); + } elseif ($this->rolfTag !== null) { + $this->rolfTag->removeObject($this); + } $this->rolfTag = $rolfTag; return $this; diff --git a/src/Entity/RolfTagSuperClass.php b/src/Entity/RolfTagSuperClass.php index fc7435df..16581432 100755 --- a/src/Entity/RolfTagSuperClass.php +++ b/src/Entity/RolfTagSuperClass.php @@ -41,6 +41,13 @@ class RolfTagSuperClass */ protected $risks; + /** + * @var ArrayCollection|ObjectSuperClass[] + * + * @ORM\OneToMany(targetEntity="MonarcObject", mappedBy="rolfTag") + */ + protected $objects; + /** * @var string * @@ -51,6 +58,7 @@ class RolfTagSuperClass public function __construct() { $this->risks = new ArrayCollection(); + $this->objects = new ArrayCollection(); } public function getId() @@ -83,6 +91,30 @@ public function removeRisk(RolfRiskSuperClass $rolfRisk): self return $this; } + public function getObjects() + { + return $this->objects; + } + + public function addObject(ObjectSuperClass $object): self + { + if (!$this->objects->contains($object)) { + $this->objects->add($object); + $object->setRolfTag($this); + } + + return $this; + } + + public function removeObject(ObjectSuperClass $object): self + { + if ($this->objects->contains($object)) { + $this->objects->removeElement($object); + } + + return $this; + } + public function getCode(): string { return (string)$this->code;