From f61af9d02a17b31dda4926245666c7a5f4fbf94e Mon Sep 17 00:00:00 2001 From: nobohan Date: Wed, 5 May 2021 11:44:55 +0200 Subject: [PATCH] add household and householdmembers entities + migration --- .../Entity/Household/Household.php | 24 +++ .../Entity/Household/HouseholdMembers.php | 153 ++++++++++++++++++ .../Household/HouseholdMembersRepository.php | 50 ++++++ .../Household/HouseholdRepository.php | 50 ++++++ .../migrations/Version20210505093408.php | 41 +++++ 5 files changed, 318 insertions(+) create mode 100644 src/Bundle/ChillPersonBundle/Entity/Household/Household.php create mode 100644 src/Bundle/ChillPersonBundle/Entity/Household/HouseholdMembers.php create mode 100644 src/Bundle/ChillPersonBundle/Repository/Household/HouseholdMembersRepository.php create mode 100644 src/Bundle/ChillPersonBundle/Repository/Household/HouseholdRepository.php create mode 100644 src/Bundle/ChillPersonBundle/migrations/Version20210505093408.php diff --git a/src/Bundle/ChillPersonBundle/Entity/Household/Household.php b/src/Bundle/ChillPersonBundle/Entity/Household/Household.php new file mode 100644 index 000000000..304321ac8 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Entity/Household/Household.php @@ -0,0 +1,24 @@ +id; + } +} diff --git a/src/Bundle/ChillPersonBundle/Entity/Household/HouseholdMembers.php b/src/Bundle/ChillPersonBundle/Entity/Household/HouseholdMembers.php new file mode 100644 index 000000000..80864ecd0 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Entity/Household/HouseholdMembers.php @@ -0,0 +1,153 @@ +id; + } + + public function getPosition(): ?string + { + return $this->position; + } + + public function setPosition(?string $position): self + { + $this->position = $position; + + return $this; + } + + public function getStartDate(): ?\DateTimeInterface + { + return $this->startDate; + } + + public function setStartDate(\DateTimeInterface $startDate): self + { + $this->startDate = $startDate; + + return $this; + } + + public function getEndDate(): ?\DateTimeInterface + { + return $this->endDate; + } + + public function setEndDate(\DateTimeInterface $endDate): self + { + $this->endDate = $endDate; + + return $this; + } + + public function getComment(): ?string + { + return $this->comment; + } + + public function setComment(?string $comment): self + { + $this->comment = $comment; + + return $this; + } + + public function getSharedHousehold(): ?bool + { + return $this->sharedHousehold; + } + + public function setSharedHousehold(bool $sharedHousehold): self + { + $this->sharedHousehold = $sharedHousehold; + + return $this; + } + + public function getPerson(): ?Person + { + return $this->person; + } + + public function setPerson(?Person $person): self + { + $this->person = $person; + + return $this; + } + + public function getHousehold(): ?Household + { + return $this->household; + } + + public function setHousehold(?Household $household): self + { + $this->household = $household; + + return $this; + } +} diff --git a/src/Bundle/ChillPersonBundle/Repository/Household/HouseholdMembersRepository.php b/src/Bundle/ChillPersonBundle/Repository/Household/HouseholdMembersRepository.php new file mode 100644 index 000000000..feea6d44d --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Repository/Household/HouseholdMembersRepository.php @@ -0,0 +1,50 @@ +createQueryBuilder('h') + ->andWhere('h.exampleField = :val') + ->setParameter('val', $value) + ->orderBy('h.id', 'ASC') + ->setMaxResults(10) + ->getQuery() + ->getResult() + ; + } + */ + + /* + public function findOneBySomeField($value): ?HouseholdMembers + { + return $this->createQueryBuilder('h') + ->andWhere('h.exampleField = :val') + ->setParameter('val', $value) + ->getQuery() + ->getOneOrNullResult() + ; + } + */ +} diff --git a/src/Bundle/ChillPersonBundle/Repository/Household/HouseholdRepository.php b/src/Bundle/ChillPersonBundle/Repository/Household/HouseholdRepository.php new file mode 100644 index 000000000..38522806c --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Repository/Household/HouseholdRepository.php @@ -0,0 +1,50 @@ +createQueryBuilder('h') + ->andWhere('h.exampleField = :val') + ->setParameter('val', $value) + ->orderBy('h.id', 'ASC') + ->setMaxResults(10) + ->getQuery() + ->getResult() + ; + } + */ + + /* + public function findOneBySomeField($value): ?Household + { + return $this->createQueryBuilder('h') + ->andWhere('h.exampleField = :val') + ->setParameter('val', $value) + ->getQuery() + ->getOneOrNullResult() + ; + } + */ +} diff --git a/src/Bundle/ChillPersonBundle/migrations/Version20210505093408.php b/src/Bundle/ChillPersonBundle/migrations/Version20210505093408.php new file mode 100644 index 000000000..cf5a93164 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/migrations/Version20210505093408.php @@ -0,0 +1,41 @@ +addSql('CREATE SEQUENCE Household_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE HouseholdMembers_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE TABLE Household (id INT NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE TABLE HouseholdMembers (id INT NOT NULL, person_id INT DEFAULT NULL, household_id INT DEFAULT NULL, position VARCHAR(255) DEFAULT NULL, startDate DATE NOT NULL, endDate DATE NOT NULL, comment VARCHAR(255) DEFAULT NULL, sharedHousehold BOOLEAN NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX IDX_4D1FB288217BBB47 ON HouseholdMembers (person_id)'); + $this->addSql('CREATE INDEX IDX_4D1FB288E79FF843 ON HouseholdMembers (household_id)'); + $this->addSql('ALTER TABLE HouseholdMembers ADD CONSTRAINT FK_4D1FB288217BBB47 FOREIGN KEY (person_id) REFERENCES chill_person_person (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE HouseholdMembers ADD CONSTRAINT FK_4D1FB288E79FF843 FOREIGN KEY (household_id) REFERENCES Household (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE HouseholdMembers DROP CONSTRAINT FK_4D1FB288E79FF843'); + $this->addSql('ALTER TABLE HouseholdMembers DROP CONSTRAINT FK_4D1FB288217BBB47'); + $this->addSql('DROP SEQUENCE Household_id_seq CASCADE'); + $this->addSql('DROP SEQUENCE HouseholdMembers_id_seq CASCADE'); + $this->addSql('DROP TABLE Household'); + $this->addSql('DROP TABLE HouseholdMembers'); + } +}