diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index d82857bdb..29355b5b8 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -77,9 +77,9 @@ class AccompanyingPeriod /** * @var Collection - * @ORM\ManyToMany( - * targetEntity="Chill\PersonBundle\Entity\Person", - * mappedBy="accompanyingPeriods") + * + * @ORM\OneToMany(targetEntity=AccompanyingPeriodParticipation::class, + * mappedBy="accompanyingPeriod") */ private $persons; diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriodParticipation.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriodParticipation.php new file mode 100644 index 000000000..4a2fe3b44 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriodParticipation.php @@ -0,0 +1,65 @@ +, + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Chill\PersonBundle\Entity; + +use Chill\PersonBundle\Repository\AccompanyingPeriodParticipationRepository; +use Chill\PersonBundle\Entity\AccompanyingPeriod; +use Chill\PersonBundle\Entity\Person; +use Doctrine\ORM\Mapping as ORM; + +/** + * AccompanyingPeriodParticipation Class + * + * @package Chill\PersonBundle\Entity + * @ORM\Entity(repositoryClass=AccompanyingPeriodParticipationRepository::class) + * @ORM\Table(name="chill_person_accompanying_period_participation") + */ +class AccompanyingPeriodParticipation +{ + /** + * @ORM\Id + * @ORM\GeneratedValue + * @ORM\Column(type="integer") + */ + private $id; + + /** + * @ORM\ManyToOne(targetEntity=Person::class, + * inversedBy="accompanyingPeriods") + * @ORM\JoinColumn(name="person_id", referencedColumnName="id", nullable=false) + */ + private $person; + + /** + * @ORM\ManyToOne(targetEntity=AccompanyingPeriod::class, + * inversedBy="persons") + * @ORM\JoinColumn(name="accompanyingperiod_id", referencedColumnName="id", nullable=false) + */ + private $accompanyingPeriod; + + + public function getId(): ?int + { + return $this->id; + } +} diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index b3a3f5628..bd89fbcea 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -42,7 +42,6 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface; * name="person_names", * columns={"firstName", "lastName"} * )}) - * sf4 check index name * @ORM\HasLifecycleCallbacks() */ class Person implements HasCenterInterface @@ -204,17 +203,13 @@ class Person implements HasCenterInterface /** * The person's accompanying periods (when the person was accompanied by the center) - * @var ArrayCollection + * @var Collection * - * @ORM\ManyToMany( - * targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod", - * inversedBy="persons", + * @ORM\OneToMany(targetEntity=AccompanyingPeriodParticipation::class, + * mappedBy="person", * cascade={"persist", "remove", "merge", "detach"}) - * @ORM\JoinTable( - * name="persons_accompanying_periods" - * ) */ - private $accompanyingPeriods; //TO-CHANGE in accompanyingHistory + private $accompanyingPeriods; /** * A remark over the person diff --git a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriodParticipationRepository.php b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriodParticipationRepository.php new file mode 100644 index 000000000..8d767b6ab --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriodParticipationRepository.php @@ -0,0 +1,70 @@ +, + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Chill\PersonBundle\Repository; + +use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation; +use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; +use Doctrine\Persistence\ManagerRegistry; + +/** + * @method AccompanyingPeriodParticipation|null find($id, $lockMode = null, $lockVersion = null) + * @method AccompanyingPeriodParticipation|null findOneBy(array $criteria, array $orderBy = null) + * @method AccompanyingPeriodParticipation[] findAll() + * @method AccompanyingPeriodParticipation[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + */ +class AccompanyingPeriodParticipationRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, AccompanyingPeriodParticipation::class); + } + + // /** + // * @return AccompanyingPeriodParticipation[] Returns an array of AccompanyingPeriodParticipation objects + // */ + /* + public function findByExampleField($value) + { + return $this->createQueryBuilder('a') + ->andWhere('a.exampleField = :val') + ->setParameter('val', $value) + ->orderBy('a.id', 'ASC') + ->setMaxResults(10) + ->getQuery() + ->getResult() + ; + } + */ + + /* + public function findOneBySomeField($value): ?AccompanyingPeriodParticipation + { + return $this->createQueryBuilder('a') + ->andWhere('a.exampleField = :val') + ->setParameter('val', $value) + ->getQuery() + ->getOneOrNullResult() + ; + } + */ +} diff --git a/src/Bundle/ChillPersonBundle/migrations/Version20210331084527.php b/src/Bundle/ChillPersonBundle/migrations/Version20210331084527.php new file mode 100644 index 000000000..c42da9874 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/migrations/Version20210331084527.php @@ -0,0 +1,59 @@ +addSql('ALTER TABLE persons_accompanying_periods DROP CONSTRAINT persons_accompanying_periods_pkey'); + $this->addSql('ALTER TABLE persons_accompanying_periods RENAME TO chill_person_accompanying_period_participation'); + + // 2 + // NOT NECCESSARY $this->addSql('CREATE SEQUENCE chill_person_accompanying_period_participation_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('ALTER TABLE chill_person_accompanying_period_participation ADD COLUMN id SERIAL NOT NULL PRIMARY KEY'); + // TO CHECK !! automatically complete missing values allowing not null clause + // but add strange "id serial (10) default nextval('chill_person_accompanying_period_participation_id_seq':: regclass )" in column definition + + // 3 + $this->addSql('ALTER TABLE chill_person_accompanying_period_participation DROP CONSTRAINT fk_49a3871f217bbb47'); + $this->addSql('ALTER TABLE chill_person_accompanying_period_participation DROP CONSTRAINT fk_49a3871f550b0c53'); + $this->addSql('ALTER TABLE chill_person_accompanying_period_participation ADD CONSTRAINT FK_A59DF89F217BBB47 FOREIGN KEY (person_id) REFERENCES chill_person_person (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE chill_person_accompanying_period_participation ADD CONSTRAINT FK_A59DF89F550B0C53 FOREIGN KEY (accompanyingperiod_id) REFERENCES chill_person_accompanying_period (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER INDEX idx_49a3871f217bbb47 RENAME TO IDX_A59DF89F217BBB47'); + $this->addSql('ALTER INDEX idx_49a3871f550b0c53 RENAME TO IDX_A59DF89F550B0C53'); + } + + public function down(Schema $schema) : void + { + // 3 + $this->addSql('ALTER TABLE chill_person_accompanying_period_participation DROP CONSTRAINT FK_A59DF89F217BBB47'); + $this->addSql('ALTER TABLE chill_person_accompanying_period_participation DROP CONSTRAINT FK_A59DF89F550B0C53'); + $this->addSql('ALTER TABLE chill_person_accompanying_period_participation ADD CONSTRAINT fk_49a3871f217bbb47 FOREIGN KEY (person_id) REFERENCES chill_person_person (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE chill_person_accompanying_period_participation ADD CONSTRAINT fk_49a3871f550b0c53 FOREIGN KEY (accompanyingperiod_id) REFERENCES chill_person_accompanying_period (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER INDEX idx_a59df89f550b0c53 RENAME TO idx_49a3871f550b0c53'); + $this->addSql('ALTER INDEX idx_a59df89f217bbb47 RENAME TO idx_49a3871f217bbb47'); + + // 2 + $this->addSql('DROP SEQUENCE chill_person_accompanying_period_participation_id_seq CASCADE'); + $this->addSql('ALTER TABLE chill_person_accompanying_period_participation DROP id'); + + // 1 + $this->addSql('ALTER TABLE chill_person_accompanying_period_participation RENAME TO persons_accompanying_periods'); + $this->addSql('ALTER TABLE persons_accompanying_periods ADD CONSTRAINT persons_accompanying_periods_pkey PRIMARY KEY (person_id, accompanyingperiod_id)'); + } +}