diff --git a/migrations/Version20260129122052.php b/migrations/Version20260129122052.php new file mode 100644 index 0000000..9b256af --- /dev/null +++ b/migrations/Version20260129122052.php @@ -0,0 +1,40 @@ +addSql('CREATE TABLE etat_lieux (id SERIAL NOT NULL, contrat_id INT DEFAULT NULL, prestataire_id INT DEFAULT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_D8D384171823061F ON etat_lieux (contrat_id)'); + $this->addSql('CREATE INDEX IDX_D8D38417BE3DB2B7 ON etat_lieux (prestataire_id)'); + $this->addSql('CREATE TABLE prestaire (id SERIAL NOT NULL, email VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, surname VARCHAR(255) NOT NULL, phone VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('ALTER TABLE etat_lieux ADD CONSTRAINT FK_D8D384171823061F FOREIGN KEY (contrat_id) REFERENCES contrats (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE etat_lieux ADD CONSTRAINT FK_D8D38417BE3DB2B7 FOREIGN KEY (prestataire_id) REFERENCES prestaire (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('ALTER TABLE etat_lieux DROP CONSTRAINT FK_D8D384171823061F'); + $this->addSql('ALTER TABLE etat_lieux DROP CONSTRAINT FK_D8D38417BE3DB2B7'); + $this->addSql('DROP TABLE etat_lieux'); + $this->addSql('DROP TABLE prestaire'); + } +} diff --git a/src/Entity/Contrats.php b/src/Entity/Contrats.php index 9c1fa03..0e2f9d4 100644 --- a/src/Entity/Contrats.php +++ b/src/Entity/Contrats.php @@ -143,6 +143,9 @@ class Contrats #[ORM\Column(length: 255, nullable: true)] private ?string $cautionState = null; + #[ORM\OneToOne(mappedBy: 'contrat', cascade: ['persist', 'remove'])] + private ?EtatLieux $etatLieux = null; + public function __construct() { $this->contratsPayments = new ArrayCollection(); @@ -830,6 +833,28 @@ class Contrats return $this; } + public function getEtatLieux(): ?EtatLieux + { + return $this->etatLieux; + } + + public function setEtatLieux(?EtatLieux $etatLieux): static + { + // unset the owning side of the relation if necessary + if ($etatLieux === null && $this->etatLieux !== null) { + $this->etatLieux->setContrat(null); + } + + // set the owning side of the relation if necessary + if ($etatLieux !== null && $etatLieux->getContrat() !== $this) { + $etatLieux->setContrat($this); + } + + $this->etatLieux = $etatLieux; + + return $this; + } + } diff --git a/src/Entity/EtatLieux.php b/src/Entity/EtatLieux.php new file mode 100644 index 0000000..5b03a56 --- /dev/null +++ b/src/Entity/EtatLieux.php @@ -0,0 +1,50 @@ +id; + } + + public function getContrat(): ?Contrats + { + return $this->contrat; + } + + public function setContrat(?Contrats $contrat): static + { + $this->contrat = $contrat; + + return $this; + } + + public function getPrestataire(): ?Prestaire + { + return $this->prestataire; + } + + public function setPrestataire(?Prestaire $prestataire): static + { + $this->prestataire = $prestataire; + + return $this; + } +} diff --git a/src/Entity/Prestaire.php b/src/Entity/Prestaire.php new file mode 100644 index 0000000..f85cd0f --- /dev/null +++ b/src/Entity/Prestaire.php @@ -0,0 +1,123 @@ + + */ + #[ORM\OneToMany(targetEntity: EtatLieux::class, mappedBy: 'prestataire')] + private Collection $etatLieuxes; + + #[ORM\Column(length: 255)] + private ?string $email = null; + + #[ORM\Column(length: 255)] + private ?string $name = null; + + #[ORM\Column(length: 255)] + private ?string $surname = null; + + #[ORM\Column(length: 255)] + private ?string $phone = null; + + public function __construct() + { + $this->etatLieuxes = new ArrayCollection(); + } + + public function getId(): ?int + { + return $this->id; + } + + /** + * @return Collection + */ + public function getEtatLieuxes(): Collection + { + return $this->etatLieuxes; + } + + public function addEtatLieux(EtatLieux $etatLieux): static + { + if (!$this->etatLieuxes->contains($etatLieux)) { + $this->etatLieuxes->add($etatLieux); + $etatLieux->setPrestataire($this); + } + + return $this; + } + + public function removeEtatLieux(EtatLieux $etatLieux): static + { + if ($this->etatLieuxes->removeElement($etatLieux)) { + // set the owning side to null (unless already changed) + if ($etatLieux->getPrestataire() === $this) { + $etatLieux->setPrestataire(null); + } + } + + return $this; + } + + public function getEmail(): ?string + { + return $this->email; + } + + public function setEmail(string $email): static + { + $this->email = $email; + + return $this; + } + + public function getName(): ?string + { + return $this->name; + } + + public function setName(string $name): static + { + $this->name = $name; + + return $this; + } + + public function getSurname(): ?string + { + return $this->surname; + } + + public function setSurname(string $surname): static + { + $this->surname = $surname; + + return $this; + } + + public function getPhone(): ?string + { + return $this->phone; + } + + public function setPhone(string $phone): static + { + $this->phone = $phone; + + return $this; + } +} diff --git a/src/Repository/EtatLieuxRepository.php b/src/Repository/EtatLieuxRepository.php new file mode 100644 index 0000000..3368719 --- /dev/null +++ b/src/Repository/EtatLieuxRepository.php @@ -0,0 +1,43 @@ + + */ +class EtatLieuxRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, EtatLieux::class); + } + + // /** + // * @return EtatLieux[] Returns an array of EtatLieux objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('e') + // ->andWhere('e.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('e.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?EtatLieux + // { + // return $this->createQueryBuilder('e') + // ->andWhere('e.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/src/Repository/PrestaireRepository.php b/src/Repository/PrestaireRepository.php new file mode 100644 index 0000000..190154a --- /dev/null +++ b/src/Repository/PrestaireRepository.php @@ -0,0 +1,43 @@ + + */ +class PrestaireRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Prestaire::class); + } + + // /** + // * @return Prestaire[] Returns an array of Prestaire objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('p') + // ->andWhere('p.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('p.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?Prestaire + // { + // return $this->createQueryBuilder('p') + // ->andWhere('p.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +}