diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/Evaluation.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/Evaluation.php index aeb8d0a8d..57498e6cb 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/Evaluation.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/Evaluation.php @@ -12,6 +12,8 @@ declare(strict_types=1); namespace Chill\PersonBundle\Entity\SocialWork; use DateInterval; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation as Serializer; @@ -45,12 +47,13 @@ class Evaluation private ?DateInterval $notificationDelay = null; /** - * @ORM\ManyToOne( + * @ORM\ManyToMany( * targetEntity=SocialAction::class, * inversedBy="evaluations" * ) + * @ORM\JoinTable(name="chill_person_social_work_evaluation_action") */ - private ?SocialAction $socialAction = null; + private Collection $socialActions; /** * @ORM\Column(type="json") @@ -59,6 +62,11 @@ class Evaluation */ private array $title = []; + public function __construct() + { + $this->socialActions = new ArrayCollection(); + } + public function getDelay(): ?DateInterval { return $this->delay; @@ -74,11 +82,6 @@ class Evaluation return $this->notificationDelay; } - public function getSocialAction(): ?SocialAction - { - return $this->socialAction; - } - public function getTitle(): array { return $this->title; @@ -91,16 +94,27 @@ class Evaluation return $this; } - public function setNotificationDelay(DateInterval $notificationDelay): self + public function addSocialAction(SocialAction $socialAction): self { - $this->notificationDelay = $notificationDelay; + if (!$this->socialActions->contains($socialAction)) { + $this->socialActions->add($socialAction); + } return $this; } - public function setSocialAction(?SocialAction $socialAction): self + public function removeSocialAction(SocialAction $socialAction): self { - $this->socialAction = $socialAction; + if ($this->socialActions->contains($socialAction)) { + $this->socialActions->remove($socialAction); + } + + return $this; + } + + public function setNotificationDelay(DateInterval $notificationDelay): self + { + $this->notificationDelay = $notificationDelay; return $this; } diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php index 64e4e79d8..693a44eee 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php @@ -92,6 +92,7 @@ class SocialAction $this->children = new ArrayCollection(); $this->goals = new ArrayCollection(); $this->results = new ArrayCollection(); + $this->evaluations = new ArrayCollection(); } public function addChild(self $child): self diff --git a/src/Bundle/ChillPersonBundle/migrations/Version20211213203147.php b/src/Bundle/ChillPersonBundle/migrations/Version20211213203147.php new file mode 100644 index 000000000..863dd8c03 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/migrations/Version20211213203147.php @@ -0,0 +1,43 @@ +addSql('CREATE TABLE chill_person_social_work_evaluation_action (evaluation_id INT NOT NULL, socialaction_id INT NOT NULL, PRIMARY KEY(evaluation_id, socialaction_id))'); + $this->addSql('CREATE INDEX IDX_DF34CCFB456C5646 ON chill_person_social_work_evaluation_action (evaluation_id)'); + $this->addSql('CREATE INDEX IDX_DF34CCFB3DC32179 ON chill_person_social_work_evaluation_action (socialaction_id)'); + $this->addSql('ALTER TABLE chill_person_social_work_evaluation_action ADD CONSTRAINT FK_DF34CCFB456C5646 FOREIGN KEY (evaluation_id) REFERENCES chill_person_social_work_evaluation (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE chill_person_social_work_evaluation_action ADD CONSTRAINT FK_DF34CCFB3DC32179 FOREIGN KEY (socialaction_id) REFERENCES chill_person_social_action (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + + $this->addSql('INSERT INTO chill_person_social_work_evaluation_action (evaluation_id, socialaction_id) '. + 'SELECT id, socialaction_ID FROM chill_person_social_work_evaluation'); + + $this->addSql('ALTER TABLE chill_person_social_work_evaluation DROP CONSTRAINT fk_2e23f3febf32a3da'); + $this->addSql('DROP INDEX idx_2e23f3febf32a3da'); + $this->addSql('ALTER TABLE chill_person_social_work_evaluation DROP socialaction_id'); + } + + public function down(Schema $schema): void + { + $this->addSql('DROP TABLE chill_person_social_work_evaluation_action'); + $this->addSql('ALTER TABLE chill_person_social_work_evaluation ADD socialaction_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE chill_person_social_work_evaluation ADD CONSTRAINT fk_2e23f3febf32a3da FOREIGN KEY (socialaction_id) REFERENCES chill_person_social_action (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE INDEX idx_2e23f3febf32a3da ON chill_person_social_work_evaluation (socialaction_id)'); + } +}