From 87518f9ebcf9a6318d54d2603451ab376cb1a1ea Mon Sep 17 00:00:00 2001 From: Mysaa Date: Tue, 31 Jan 2023 14:54:17 +0100 Subject: [PATCH] Fix de quelques erreurs Doctrine et ajout des noms des Places --- migrations/Version20230131135243.php | 37 ++++++++++++ src/Entity/Corridor.php | 1 + src/Entity/Cylinder.php | 2 +- src/Entity/Place.php | 6 +- src/Entity/PlaceName.php | 87 ++++++++++++++++++++++++++++ src/Entity/Room.php | 2 +- src/Entity/ThreeDObjectFile.php | 4 +- 7 files changed, 134 insertions(+), 5 deletions(-) create mode 100644 migrations/Version20230131135243.php create mode 100644 src/Entity/PlaceName.php diff --git a/migrations/Version20230131135243.php b/migrations/Version20230131135243.php new file mode 100644 index 0000000..6345b73 --- /dev/null +++ b/migrations/Version20230131135243.php @@ -0,0 +1,37 @@ +addSql('CREATE SEQUENCE place_name_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE TABLE place_name (id INT NOT NULL, room_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX IDX_94960EEA54177093 ON place_name (room_id)'); + $this->addSql('ALTER TABLE place_name ADD CONSTRAINT FK_94960EEA54177093 FOREIGN KEY (room_id) REFERENCES place (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('CREATE SCHEMA public'); + $this->addSql('DROP SEQUENCE place_name_id_seq CASCADE'); + $this->addSql('ALTER TABLE place_name DROP CONSTRAINT FK_94960EEA54177093'); + $this->addSql('DROP TABLE place_name'); + } +} diff --git a/src/Entity/Corridor.php b/src/Entity/Corridor.php index 1929831..133ad74 100644 --- a/src/Entity/Corridor.php +++ b/src/Entity/Corridor.php @@ -3,6 +3,7 @@ namespace App\Entity; use App\Repository\CorridorRepository; +use Doctrine\ORM\Mapping as ORM; #[ORM\Entity(repositoryClass: CorridorRepository::class)] class Corridor extends Place diff --git a/src/Entity/Cylinder.php b/src/Entity/Cylinder.php index 2d73e7b..cf26c3c 100644 --- a/src/Entity/Cylinder.php +++ b/src/Entity/Cylinder.php @@ -16,7 +16,7 @@ class Cylinder #[ORM\Column(type: "float")] private $height; - #[ORM\OneToOne(targetEntity: PlaneSurface::class, cascade: {"persist", "remove"})] + #[ORM\OneToOne(targetEntity: PlaneSurface::class, cascade: ["persist", "remove"])] #[ORM\JoinColumn(nullable: false)] private $cylinderbase; diff --git a/src/Entity/Place.php b/src/Entity/Place.php index 76366aa..d32186c 100644 --- a/src/Entity/Place.php +++ b/src/Entity/Place.php @@ -8,9 +8,10 @@ use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity(repositoryClass: PlaceRepository::class)] +#[ORM\MappedSuperclass] #[ORM\InheritanceType("JOINED")] #[ORM\DiscriminatorColumn(name: "type", type: "string")] -#[ORM\DiscriminatorMap({"room": "Room","corridor": "Corridor"})] +#[ORM\DiscriminatorMap(["room" => Room::class, "corridor" => Corridor::class])] class Place { #[ORM\Id] @@ -23,6 +24,9 @@ class Place #[ORM\ManyToMany(targetEntity: Place::class, mappedBy: "connection")] private $connectedPlaces; + + #[ORM\OneToMany(targetEntity: PlaceName::class, mappedBy: "place")] + private $names; public function __construct() { diff --git a/src/Entity/PlaceName.php b/src/Entity/PlaceName.php new file mode 100644 index 0000000..b99d576 --- /dev/null +++ b/src/Entity/PlaceName.php @@ -0,0 +1,87 @@ +polyhedronface = new ArrayCollection(); + } + + public function getId(): ?int + { + return $this->id; + } + + /** + * @return Collection + */ + public function getPolyhedronface(): Collection + { + return $this->polyhedronface; + } + + public function addPolyhedronface(PlaneSurface $polyhedronface): self + { + if (!$this->polyhedronface->contains($polyhedronface)) { + $this->polyhedronface[] = $polyhedronface; + $polyhedronface->setPolyhedron($this); + } + + return $this; + } + + public function removePolyhedronface(PlaneSurface $polyhedronface): self + { + if ($this->polyhedronface->removeElement($polyhedronface)) { + // set the owning side to null (unless already changed) + if ($polyhedronface->getPolyhedron() === $this) { + $polyhedronface->setPolyhedron(null); + } + } + + return $this; + } + + public function getRoom(): ?Room + { + return $this->room; + } + + public function setRoom(?Room $room): self + { + $this->room = $room; + + return $this; + } + + public function getName(): ?string + { + return $this->name; + } + + public function setName(?string $name): self + { + $this->name = $name; + + return $this; + } +} diff --git a/src/Entity/Room.php b/src/Entity/Room.php index df9473d..512e68c 100644 --- a/src/Entity/Room.php +++ b/src/Entity/Room.php @@ -23,7 +23,7 @@ class Room extends Place #[ORM\OneToMany(targetEntity: Cylinder::class, mappedBy: "room")] private $CylinderRepresentation; - + public function __construct() { parent::__construct(); diff --git a/src/Entity/ThreeDObjectFile.php b/src/Entity/ThreeDObjectFile.php index f6a4960..79d293a 100644 --- a/src/Entity/ThreeDObjectFile.php +++ b/src/Entity/ThreeDObjectFile.php @@ -13,10 +13,10 @@ class ThreeDObjectFile #[ORM\Column(type: "integer")] private $id; - #[@ORM\Column(type: "string", length: 255)] + #[ORM\Column(type: "string", length: 255)] private $filename; - #[@ORM\ManyToOne(targetEntity: Room::class, inversedBy: "ComplexRepresentation")] + #[ORM\ManyToOne(targetEntity: Room::class, inversedBy: "ComplexRepresentation")] private $room; public function getId(): ?int