diff --git a/src/Bundle/ChillActivityBundle/Entity/Activity.php b/src/Bundle/ChillActivityBundle/Entity/Activity.php index 4b329a0a2..db0d5c7d1 100644 --- a/src/Bundle/ChillActivityBundle/Entity/Activity.php +++ b/src/Bundle/ChillActivityBundle/Entity/Activity.php @@ -87,12 +87,6 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac */ private CommentEmbeddable $comment; - /** - * @ORM\Embedded(class="Chill\MainBundle\Entity\Embeddable\PrivateCommentEmbeddable", columnPrefix="privateComment_") - * @Groups({"docgen:read"}) - */ - private PrivateCommentEmbeddable $privateComment; - /** * @ORM\Column(type="datetime") * @Groups({"docgen:read"}) @@ -141,6 +135,12 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac */ private ?Collection $persons = null; + /** + * @ORM\Embedded(class="Chill\MainBundle\Entity\Embeddable\PrivateCommentEmbeddable", columnPrefix="privateComment_") + * @Groups({"docgen:read"}) + */ + private PrivateCommentEmbeddable $privateComment; + /** * @ORM\ManyToMany(targetEntity="Chill\ActivityBundle\Entity\ActivityReason") * @Groups({"docgen:read"}) @@ -321,11 +321,6 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac return $this->comment; } - public function getPrivateComment(): PrivateCommentEmbeddable - { - return $this->privateComment; - } - public function getDate(): DateTime { return $this->date; @@ -413,6 +408,11 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac return []; } + public function getPrivateComment(): PrivateCommentEmbeddable + { + return $this->privateComment; + } + public function getReasons(): Collection { return $this->reasons; @@ -550,13 +550,6 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac return $this; } - public function setPrivateComment(PrivateCommentEmbeddable $privateComment): self - { - $this->privateComment = $privateComment; - - return $this; - } - public function setDate(DateTime $date): self { $this->date = $date; @@ -606,6 +599,13 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac return $this; } + public function setPrivateComment(PrivateCommentEmbeddable $privateComment): self + { + $this->privateComment = $privateComment; + + return $this; + } + public function setReasons(?ArrayCollection $reasons): self { $this->reasons = $reasons; diff --git a/src/Bundle/ChillActivityBundle/Entity/ActivityType.php b/src/Bundle/ChillActivityBundle/Entity/ActivityType.php index deb28184c..845b31ca2 100644 --- a/src/Bundle/ChillActivityBundle/Entity/ActivityType.php +++ b/src/Bundle/ChillActivityBundle/Entity/ActivityType.php @@ -76,16 +76,6 @@ class ActivityType */ private int $commentVisible = self::FIELD_OPTIONAL; - /** - * @ORM\Column(type="string", nullable=false, options={"default": ""}) - */ - private string $privateCommentLabel = ''; - - /** - * @ORM\Column(type="smallint", nullable=false, options={"default": 1}) - */ - private int $privateCommentVisible = self::FIELD_OPTIONAL; - /** * @ORM\Column(type="string", nullable=false, options={"default": ""}) */ @@ -177,6 +167,16 @@ class ActivityType */ private int $personVisible = self::FIELD_REQUIRED; + /** + * @ORM\Column(type="string", nullable=false, options={"default": ""}) + */ + private string $privateCommentLabel = ''; + + /** + * @ORM\Column(type="smallint", nullable=false, options={"default": 1}) + */ + private int $privateCommentVisible = self::FIELD_OPTIONAL; + /** * @ORM\Column(type="string", nullable=false, options={"default": ""}) */ @@ -324,16 +324,6 @@ class ActivityType return $this->commentVisible; } - public function getPrivateCommentLabel(): string - { - return $this->privateCommentLabel; - } - - public function getPrivateCommentVisible(): int - { - return $this->privateCommentVisible; - } - public function getDateLabel(): string { return $this->dateLabel; @@ -436,6 +426,16 @@ class ActivityType return $this->personVisible; } + public function getPrivateCommentLabel(): string + { + return $this->privateCommentLabel; + } + + public function getPrivateCommentVisible(): int + { + return $this->privateCommentVisible; + } + public function getReasonsLabel(): string { return $this->reasonsLabel; @@ -593,20 +593,6 @@ class ActivityType return $this; } - public function setPrivateCommentLabel(string $privateCommentLabel): self - { - $this->privateCommentLabel = $privateCommentLabel; - - return $this; - } - - public function setPrivateCommentVisible(int $privateCommentVisible): self - { - $this->privateCommentVisible = $privateCommentVisible; - - return $this; - } - public function setDateLabel(string $dateLabel): self { $this->dateLabel = $dateLabel; @@ -722,6 +708,20 @@ class ActivityType return $this; } + public function setPrivateCommentLabel(string $privateCommentLabel): self + { + $this->privateCommentLabel = $privateCommentLabel; + + return $this; + } + + public function setPrivateCommentVisible(int $privateCommentVisible): self + { + $this->privateCommentVisible = $privateCommentVisible; + + return $this; + } + public function setReasonsLabel(string $reasonsLabel): self { $this->reasonsLabel = $reasonsLabel; diff --git a/src/Bundle/ChillActivityBundle/Form/ActivityType.php b/src/Bundle/ChillActivityBundle/Form/ActivityType.php index 0fa2fdf76..4361158e5 100644 --- a/src/Bundle/ChillActivityBundle/Form/ActivityType.php +++ b/src/Bundle/ChillActivityBundle/Form/ActivityType.php @@ -252,10 +252,10 @@ class ActivityType extends AbstractType ]); } - if($activityType->isVisible('privateComment')) { + if ($activityType->isVisible('privateComment')) { $builder->add('privateComment', PrivateCommentType::class, [ 'label' => empty($activityType->getLabel('privateComment')) ? 'activity.private comment' : $activityType->getPrivateCommentLabel(), - 'required' => false + 'required' => false, ]); } diff --git a/src/Bundle/ChillActivityBundle/migrations/Version20220425133027.php b/src/Bundle/ChillActivityBundle/migrations/Version20220425133027.php index c29f2d66e..d5243b259 100644 --- a/src/Bundle/ChillActivityBundle/migrations/Version20220425133027.php +++ b/src/Bundle/ChillActivityBundle/migrations/Version20220425133027.php @@ -1,5 +1,12 @@ addSql('ALTER TABLE activitytype DROP privateCommentLabel'); + $this->addSql('ALTER TABLE activitytype DROP privateCommentVisible'); + } + public function getDescription(): string { return 'add private comment option to activity types'; @@ -23,11 +37,4 @@ final class Version20220425133027 extends AbstractMigration $this->addSql('ALTER TABLE activitytype ADD privateCommentLabel VARCHAR(255) DEFAULT \'\' NOT NULL'); $this->addSql('ALTER TABLE activitytype ADD privateCommentVisible SMALLINT DEFAULT 1 NOT NULL'); } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE activitytype DROP privateCommentLabel'); - $this->addSql('ALTER TABLE activitytype DROP privateCommentVisible'); - } } diff --git a/src/Bundle/ChillCalendarBundle/Entity/Calendar.php b/src/Bundle/ChillCalendarBundle/Entity/Calendar.php index 4783e70b6..c40bddb44 100644 --- a/src/Bundle/ChillCalendarBundle/Entity/Calendar.php +++ b/src/Bundle/ChillCalendarBundle/Entity/Calendar.php @@ -71,12 +71,6 @@ class Calendar */ private CommentEmbeddable $comment; - /** - * @ORM\Embedded(class=PrivateCommentEmbeddable::class, columnPrefix="privateComment_") - * @Serializer\Groups({"calendar:read"}) - */ - private PrivateCommentEmbeddable $privateComment; - /** * @ORM\Column(type="datetimetz_immutable") * @Serializer\Groups({"calendar:read"}) @@ -122,6 +116,12 @@ class Calendar */ private Collection $persons; + /** + * @ORM\Embedded(class=PrivateCommentEmbeddable::class, columnPrefix="privateComment_") + * @Serializer\Groups({"calendar:read"}) + */ + private PrivateCommentEmbeddable $privateComment; + /** * @ORM\ManyToMany( * targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty", @@ -216,11 +216,6 @@ class Calendar return $this->comment; } - public function getPrivateComment(): PrivateCommentEmbeddable - { - return $this->privateComment; - } - public function getEndDate(): ?DateTimeImmutable { return $this->endDate; @@ -291,6 +286,11 @@ class Calendar return []; } + public function getPrivateComment(): PrivateCommentEmbeddable + { + return $this->privateComment; + } + /** * @return Collection|ThirdParty[] */ @@ -399,13 +399,6 @@ class Calendar return $this; } - public function setPrivateComment(PrivateCommentEmbeddable $privateComment): self - { - $this->privateComment = $privateComment; - - return $this; - } - public function setEndDate(DateTimeImmutable $endDate): self { $this->endDate = $endDate; @@ -427,6 +420,13 @@ class Calendar return $this; } + public function setPrivateComment(PrivateCommentEmbeddable $privateComment): self + { + $this->privateComment = $privateComment; + + return $this; + } + public function setSendSMS(?bool $sendSMS): self { $this->sendSMS = $sendSMS; diff --git a/src/Bundle/ChillCalendarBundle/Form/CalendarType.php b/src/Bundle/ChillCalendarBundle/Form/CalendarType.php index 7269b2a66..b1dccb5fd 100644 --- a/src/Bundle/ChillCalendarBundle/Form/CalendarType.php +++ b/src/Bundle/ChillCalendarBundle/Form/CalendarType.php @@ -54,7 +54,7 @@ class CalendarType extends AbstractType ]) ->add('privateComment', PrivateCommentType::class, [ 'required' => false, - 'label' => 'private comment' + 'label' => 'private comment', ]) // ->add('cancelReason', EntityType::class, [ // 'required' => false, diff --git a/src/Bundle/ChillMainBundle/Entity/Embeddable/PrivateCommentEmbeddable.php b/src/Bundle/ChillMainBundle/Entity/Embeddable/PrivateCommentEmbeddable.php index f7fd41cb5..cfca2a86c 100644 --- a/src/Bundle/ChillMainBundle/Entity/Embeddable/PrivateCommentEmbeddable.php +++ b/src/Bundle/ChillMainBundle/Entity/Embeddable/PrivateCommentEmbeddable.php @@ -24,15 +24,25 @@ class PrivateCommentEmbeddable */ private ?array $comments = []; + public function getCommentForUser(User $user): string + { + return $this->comments[$user->getId()] ?? ''; + } + public function getComments(): ?array { return $this->comments; } - - public function getCommentForUser(User $user): string + public function merge(PrivateCommentEmbeddable $newComment): self { - return $this->comments[$user->getId()] ?? ''; + $currentComments = null === $this->getComments() ? [] : $this->getComments(); + + $mergedComments = $newComment->getComments() + $currentComments; + + $this->setComments($mergedComments); + + return $this; } public function setCommentForUser(User $user, string $content): self @@ -48,16 +58,4 @@ class PrivateCommentEmbeddable return $this; } - - public function merge(PrivateCommentEmbeddable $newComment): self - { - - $currentComments = null === $this->getComments() ? [] : $this->getComments(); - - $mergedComments = $newComment->getComments() + $currentComments; - - $this->setComments($mergedComments); - - return $this; - } } diff --git a/src/Bundle/ChillMainBundle/Form/DataMapper/PrivateCommentDataMapper.php b/src/Bundle/ChillMainBundle/Form/DataMapper/PrivateCommentDataMapper.php index 5d4cd08cd..2c03c59f1 100644 --- a/src/Bundle/ChillMainBundle/Form/DataMapper/PrivateCommentDataMapper.php +++ b/src/Bundle/ChillMainBundle/Form/DataMapper/PrivateCommentDataMapper.php @@ -19,7 +19,6 @@ use Symfony\Component\Security\Core\Security; final class PrivateCommentDataMapper extends AbstractType implements DataMapperInterface { - private Security $security; public function __construct(Security $security) @@ -40,8 +39,6 @@ final class PrivateCommentDataMapper extends AbstractType implements DataMapperI $forms = iterator_to_array($forms); $forms['comments']->setData($viewData->getCommentForUser($this->security->getUser())); - - } public function mapFormsToData($forms, &$viewData) @@ -50,5 +47,4 @@ final class PrivateCommentDataMapper extends AbstractType implements DataMapperI $viewData->setCommentForUser($this->security->getUser(), $forms['comments']->getData()); } - -} \ No newline at end of file +} diff --git a/src/Bundle/ChillMainBundle/Form/Type/PrivateCommentType.php b/src/Bundle/ChillMainBundle/Form/Type/PrivateCommentType.php index 6ab166fe9..8ce33face 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/PrivateCommentType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/PrivateCommentType.php @@ -11,17 +11,11 @@ declare(strict_types=1); namespace Chill\MainBundle\Form\Type; -use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable; use Chill\MainBundle\Entity\Embeddable\PrivateCommentEmbeddable; use Chill\MainBundle\Form\DataMapper\PrivateCommentDataMapper; -use DateTime; use Symfony\Component\Form\AbstractType; -use Symfony\Component\Form\Extension\Core\Type\CollectionType; -use Symfony\Component\Form\Extension\Core\Type\HiddenType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\Form\FormEvent; -use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -30,10 +24,10 @@ use Symfony\Component\Security\Core\User\UserInterface; class PrivateCommentType extends AbstractType { - protected UserInterface $user; - protected PrivateCommentDataMapper $dataMapper; + protected UserInterface $user; + public function __construct(TokenStorageInterface $tokenStorage, PrivateCommentDataMapper $dataMapper) { $this->user = $tokenStorage->getToken()->getUser(); @@ -44,7 +38,7 @@ class PrivateCommentType extends AbstractType { $builder ->add('comments', ChillTextareaType::class, [ - 'label' => 'private comment' + 'label' => 'private comment', ]) ->setDataMapper($this->dataMapper); } diff --git a/src/Bundle/ChillMainBundle/Serializer/Normalizer/PrivateCommentEmbeddableNormalizer.php b/src/Bundle/ChillMainBundle/Serializer/Normalizer/PrivateCommentEmbeddableNormalizer.php index 447b8ddf8..a1ff7e5ba 100644 --- a/src/Bundle/ChillMainBundle/Serializer/Normalizer/PrivateCommentEmbeddableNormalizer.php +++ b/src/Bundle/ChillMainBundle/Serializer/Normalizer/PrivateCommentEmbeddableNormalizer.php @@ -11,7 +11,6 @@ declare(strict_types=1); namespace Chill\MainBundle\Serializer\Normalizer; -use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable; use Chill\MainBundle\Entity\Embeddable\PrivateCommentEmbeddable; use Symfony\Component\Security\Core\Security; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; @@ -19,7 +18,6 @@ use Symfony\Component\Serializer\Normalizer\NormalizerInterface; class PrivateCommentEmbeddableNormalizer implements NormalizerInterface, DenormalizerInterface { - private Security $security; public function __construct(Security $security) @@ -40,19 +38,18 @@ class PrivateCommentEmbeddableNormalizer implements NormalizerInterface, Denorma return $comment; } - public function supportsDenormalization($data, string $type, ?string $format = null): bool - { - return $type === PrivateCommentEmbeddable::class; - } - public function normalize($comment, $format = null, array $contect = []): string { return $comment->getCommentForUser($this->security->getUser()); } + public function supportsDenormalization($data, string $type, ?string $format = null): bool + { + return PrivateCommentEmbeddable::class === $type; + } + public function supportsNormalization($data, ?string $format = null): bool { return $data instanceof PrivateCommentEmbeddable; } - -} \ No newline at end of file +} diff --git a/src/Bundle/ChillMainBundle/migrations/Version20220426133048.php b/src/Bundle/ChillMainBundle/migrations/Version20220426133048.php index 2f1fbab1a..94f866e9b 100644 --- a/src/Bundle/ChillMainBundle/migrations/Version20220426133048.php +++ b/src/Bundle/ChillMainBundle/migrations/Version20220426133048.php @@ -1,5 +1,12 @@ addSql('ALTER TABLE chill_person_accompanying_period_work DROP privateComment_comments'); + $this->addSql('ALTER TABLE activity DROP privateComment_comments'); + $this->addSql('ALTER TABLE chill_calendar.calendar DROP privateComment_comments'); + } + public function getDescription(): string { return 'add private embeddable comment to activity, calendar and accompanyingperiod work'; @@ -24,12 +39,4 @@ final class Version20220426133048 extends AbstractMigration $this->addSql('ALTER TABLE chill_calendar.calendar ADD privateComment_comments JSON DEFAULT NULL'); $this->addSql('ALTER TABLE chill_person_accompanying_period_work ADD privateComment_comments JSON DEFAULT NULL'); } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE chill_person_accompanying_period_work DROP privateComment_comments'); - $this->addSql('ALTER TABLE activity DROP privateComment_comments'); - $this->addSql('ALTER TABLE chill_calendar.calendar DROP privateComment_comments'); - } } diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php index 8ea1028f8..9c0eade3b 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php @@ -13,7 +13,6 @@ namespace Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\MainBundle\Doctrine\Model\TrackCreationInterface; use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface; -use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable; use Chill\MainBundle\Entity\Embeddable\PrivateCommentEmbeddable; use Chill\MainBundle\Entity\User; use Chill\PersonBundle\AccompanyingPeriod\SocialIssueConsistency\AccompanyingPeriodLinkedWithSocialIssuesEntityInterface; @@ -136,12 +135,6 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues */ private string $note = ''; - /** - * @ORM\Embedded(class="Chill\MainBundle\Entity\Embeddable\PrivateCommentEmbeddable", columnPrefix="privateComment_") - * @Serializer\Groups({"read", "accompanying_period_work:edit"}) - */ - private PrivateCommentEmbeddable $privateComment; - /** * @ORM\ManyToMany(targetEntity=Person::class) * @ORM\JoinTable(name="chill_person_accompanying_period_work_person") @@ -151,6 +144,12 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues */ private Collection $persons; + /** + * @ORM\Embedded(class="Chill\MainBundle\Entity\Embeddable\PrivateCommentEmbeddable", columnPrefix="privateComment_") + * @Serializer\Groups({"read", "accompanying_period_work:edit"}) + */ + private PrivateCommentEmbeddable $privateComment; + /** * @ORM\ManyToMany(targetEntity=User::class) * @ORM\JoinTable(name="chill_person_accompanying_period_work_referrer") @@ -332,16 +331,16 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues return $this->note; } - public function getPrivateComment(): PrivateCommentEmbeddable - { - return $this->privateComment; - } - public function getPersons(): Collection { return $this->persons; } + public function getPrivateComment(): PrivateCommentEmbeddable + { + return $this->privateComment; + } + /** * @return Collection|User[] */