Bladeren bron

complete entities relations

olinox14 2 maanden geleden
bovenliggende
commit
b66e52c01b
5 gewijzigde bestanden met toevoegingen van 131 en 4 verwijderingen
  1. 37 2
      api/src/Entity/Galaxy.php
  2. 18 0
      api/src/Entity/Planet.php
  3. 2 2
      api/src/Entity/Player.php
  4. 37 0
      api/src/Entity/Sector.php
  5. 37 0
      api/src/Entity/System.php

+ 37 - 2
api/src/Entity/Galaxy.php

@@ -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;
     }
 }

+ 18 - 0
api/src/Entity/Planet.php

@@ -24,6 +24,10 @@ class Planet
     #[ORM\Column(length: 100, nullable: false)]
     private string $name;
 
+    #[ORM\ManyToOne(targetEntity: System::class, inversedBy: 'planets')]
+    #[ORM\JoinColumn(nullable: true)]
+    private ?System $system = null;
+
     #[ORM\Column(length: 24, enumType: PlanetTypeEnum::class, options: ['default' => PlanetTypeEnum::UNINHABITABLE])]
     private PlanetTypeEnum $type;
 
@@ -56,6 +60,20 @@ class Planet
         return $this;
     }
 
+    public function getSystem(): ?System
+    {
+        return $this->system;
+    }
+
+    public function setSystem(?System $system): self
+    {
+        $this->system = $system;
+        if ($system && !$system->getPlanets()->contains($this)) {
+            $system->addPlanet($this);
+        }
+        return $this;
+    }
+
     public function getType(): PlanetTypeEnum
     {
         return $this->type;

+ 2 - 2
api/src/Entity/Player.php

@@ -20,11 +20,11 @@ class Player
     #[ORM\Column]
     private ?int $id = null;
 
-    #[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'gameParticipations')]
+    #[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'players')]
     #[ORM\JoinColumn(nullable: false)]
     private User $user;
 
-    #[ORM\ManyToOne(targetEntity: Game::class, inversedBy: 'gameParticipations')]
+    #[ORM\ManyToOne(targetEntity: Game::class, inversedBy: 'players')]
     #[ORM\JoinColumn(nullable: false)]
     private Game $game;
 

+ 37 - 0
api/src/Entity/Sector.php

@@ -27,6 +27,10 @@ class Sector
     #[ORM\OneToMany(targetEntity: System::class, mappedBy: 'sector', orphanRemoval: true)]
     private Collection $systems;
 
+    #[ORM\ManyToOne(targetEntity: Galaxy::class, inversedBy: 'sectors')]
+    #[ORM\JoinColumn(nullable: true)]
+    private ?Galaxy $galaxy = null;
+
     #[ORM\Column(length: 24, enumType: SectorStatusEnum::class, options: ['default' => SectorStatusEnum::UNEXPLORED])]
     private SectorStatusEnum $status = SectorStatusEnum::UNEXPLORED;
 
@@ -68,6 +72,39 @@ class Sector
         return $this;
     }
 
+    public function addSystem(System $system): self
+    {
+        if (!$this->systems->contains($system)) {
+            $this->systems->add($system);
+            $system->setSector($this);
+        }
+        return $this;
+    }
+
+    public function removeSystem(System $system): self
+    {
+        if ($this->systems->removeElement($system)) {
+            if ($system->getSector() === $this) {
+                $system->setSector(null);
+            }
+        }
+        return $this;
+    }
+
+    public function getGalaxy(): ?Galaxy
+    {
+        return $this->galaxy;
+    }
+
+    public function setGalaxy(?Galaxy $galaxy): self
+    {
+        $this->galaxy = $galaxy;
+        if ($galaxy && !$galaxy->getSectors()->contains($this)) {
+            $galaxy->addSector($this);
+        }
+        return $this;
+    }
+
     public function getStatus(): SectorStatusEnum
     {
         return $this->status;

+ 37 - 0
api/src/Entity/System.php

@@ -28,6 +28,10 @@ class System
     #[ORM\OneToMany(targetEntity: Planet::class, mappedBy: 'system', orphanRemoval: true)]
     private Collection $planets;
 
+    #[ORM\ManyToOne(targetEntity: Sector::class, inversedBy: 'systems')]
+    #[ORM\JoinColumn(nullable: true)]
+    private ?Sector $sector = null;
+
     #[ORM\Column(length: 20, enumType: StarTypeEnum::class, options: ['default' => StarTypeEnum::RED_DWARF])]
     private StarTypeEnum $starType = StarTypeEnum::RED_DWARF;
 
@@ -76,6 +80,39 @@ class System
         return $this;
     }
 
+    public function addPlanet(Planet $planet): self
+    {
+        if (!$this->planets->contains($planet)) {
+            $this->planets->add($planet);
+            $planet->setSystem($this);
+        }
+        return $this;
+    }
+
+    public function removePlanet(Planet $planet): self
+    {
+        if ($this->planets->removeElement($planet)) {
+            if ($planet->getSystem() === $this) {
+                $planet->setSystem(null);
+            }
+        }
+        return $this;
+    }
+
+    public function getSector(): ?Sector
+    {
+        return $this->sector;
+    }
+
+    public function setSector(?Sector $sector): self
+    {
+        $this->sector = $sector;
+        if ($sector && !$sector->getSystems()->contains($this)) {
+            $sector->addSystem($this);
+        }
+        return $this;
+    }
+
     public function getStarType(): StarTypeEnum
     {
         return $this->starType;