diff --git a/src/Bundle/ChillMainBundle/Entity/Notification.php b/src/Bundle/ChillMainBundle/Entity/Notification.php index 1fa4e668e..d7e7075ed 100644 --- a/src/Bundle/ChillMainBundle/Entity/Notification.php +++ b/src/Bundle/ChillMainBundle/Entity/Notification.php @@ -35,6 +35,12 @@ class Notification private ?ArrayCollection $addressesOnLoad = null; + /** + * @ORM\OneToMany(targetEntity=NotificationComment::class, mappedBy="notification", orphanRemoval=true) + * @ORM\OrderBy({"createdAt": "ASC"}) + */ + private Collection $comments; + /** * @ORM\Column(type="datetime_immutable") */ @@ -80,6 +86,7 @@ class Notification { $this->addressees = new ArrayCollection(); $this->unreadBy = new ArrayCollection(); + $this->comments = new ArrayCollection(); $this->setDate(new DateTimeImmutable()); } @@ -93,6 +100,16 @@ class Notification return $this; } + public function addComment(NotificationComment $comment): self + { + if (!$this->comments->contains($comment)) { + $this->comments[] = $comment; + $comment->setNotification($this); + } + + return $this; + } + public function addUnreadBy(User $user): self { if (!$this->unreadBy->contains($user)) { @@ -115,6 +132,11 @@ class Notification return $this->addressees; } + public function getComments(): Collection + { + return $this->comments; + } + public function getDate(): ?DateTimeImmutable { return $this->date; @@ -192,6 +214,13 @@ class Notification return $this; } + public function removeComment(NotificationComment $comment): self + { + $this->comments->removeElement($comment); + + return $this; + } + public function removeUnreadBy(User $user): self { $this->unreadBy->removeElement($user); diff --git a/src/Bundle/ChillMainBundle/Entity/NotificationComment.php b/src/Bundle/ChillMainBundle/Entity/NotificationComment.php new file mode 100644 index 000000000..73157eb01 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Entity/NotificationComment.php @@ -0,0 +1,137 @@ +content; + } + + public function getId(): ?int + { + return $this->id; + } + + public function getNotification(): ?Notification + { + return $this->notification; + } + + public function getUpdateAt(): ?DateTimeImmutable + { + return $this->updateAt; + } + + public function setContent(string $content): self + { + $this->content = $content; + + return $this; + } + + public function setCreatedAt(DateTimeInterface $datetime): self + { + $this->createdAt = $datetime; + + return $this; + } + + public function setCreatedBy(User $user): self + { + $this->createdBy = $user; + + return $this; + } + + /** + * @internal use Notification::addComment + */ + public function setNotification(?Notification $notification): self + { + $this->notification = $notification; + + return $this; + } + + public function setUpdateAt(?DateTimeImmutable $updateAt): self + { + $this->updateAt = $updateAt; + + return $this; + } + + public function setUpdatedAt(DateTimeInterface $datetime): self + { + $this->updateAt = $datetime; + + return $this; + } + + public function setUpdatedBy(User $user): self + { + $this->updatedBy = $user; + + return $this; + } +} diff --git a/src/Bundle/ChillMainBundle/migrations/Version20211228215919.php b/src/Bundle/ChillMainBundle/migrations/Version20211228215919.php new file mode 100644 index 000000000..12e7b747d --- /dev/null +++ b/src/Bundle/ChillMainBundle/migrations/Version20211228215919.php @@ -0,0 +1,43 @@ +addSql('DROP SEQUENCE chill_main_notification_comment_id_seq CASCADE'); + $this->addSql('DROP TABLE chill_main_notification_comment'); + } + + public function getDescription(): string + { + return 'Notifications: add comment on notifications'; + } + + public function up(Schema $schema): void + { + $this->addSql('CREATE SEQUENCE chill_main_notification_comment_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE TABLE chill_main_notification_comment (id INT NOT NULL, notification_id INT NOT NULL, content TEXT NOT NULL, createdAt TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, updateAt TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, createdBy_id INT DEFAULT NULL, updatedBy_id INT DEFAULT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX IDX_983BD2CFEF1A9D84 ON chill_main_notification_comment (notification_id)'); + $this->addSql('CREATE INDEX IDX_983BD2CF3174800F ON chill_main_notification_comment (createdBy_id)'); + $this->addSql('CREATE INDEX IDX_983BD2CF65FF1AEC ON chill_main_notification_comment (updatedBy_id)'); + $this->addSql('COMMENT ON COLUMN chill_main_notification_comment.createdAt IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('COMMENT ON COLUMN chill_main_notification_comment.updateAt IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('ALTER TABLE chill_main_notification_comment ADD CONSTRAINT FK_983BD2CFEF1A9D84 FOREIGN KEY (notification_id) REFERENCES chill_main_notification (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE chill_main_notification_comment ADD CONSTRAINT FK_983BD2CF3174800F FOREIGN KEY (createdBy_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE chill_main_notification_comment ADD CONSTRAINT FK_983BD2CF65FF1AEC FOREIGN KEY (updatedBy_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + } +}