|
|
@@ -24,6 +24,10 @@ class Galaxy
|
|
|
#[ORM\OneToMany(targetEntity: Sector::class, mappedBy: 'galaxy', orphanRemoval: true)]
|
|
|
private Collection $sectors;
|
|
|
|
|
|
+ #[ORM\OneToOne(inversedBy: 'galaxy', targetEntity: Game::class)]
|
|
|
+ #[ORM\JoinColumn(nullable: true)]
|
|
|
+ private ?Game $game = null;
|
|
|
+
|
|
|
public function __construct()
|
|
|
{
|
|
|
$this->sectors = new ArrayCollection();
|
|
|
@@ -56,9 +60,40 @@ class Galaxy
|
|
|
return $this->sectors;
|
|
|
}
|
|
|
|
|
|
- public function setSectors(Collection $sectors): self
|
|
|
+ public function addSector(Sector $sector): self
|
|
|
+ {
|
|
|
+ if (!$this->sectors->contains($sector)) {
|
|
|
+ $this->sectors->add($sector);
|
|
|
+ $sector->setGalaxy($this);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function removeSector(Sector $sector): self
|
|
|
+ {
|
|
|
+ if ($this->sectors->removeElement($sector)) {
|
|
|
+ // Set the owning side to null (unless already changed)
|
|
|
+ if ($sector->getGalaxy() === $this) {
|
|
|
+ $sector->setGalaxy(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getGame(): ?Game
|
|
|
+ {
|
|
|
+ return $this->game;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function setGame(?Game $game): self
|
|
|
{
|
|
|
- $this->sectors = $sectors;
|
|
|
+ $this->game = $game;
|
|
|
+ // ensure inverse side is synced
|
|
|
+ if ($game && $game->getGalaxy() !== $this) {
|
|
|
+ $game->setGalaxy($this);
|
|
|
+ }
|
|
|
return $this;
|
|
|
}
|
|
|
}
|