mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
php csfixes
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\Migrations\Main;
|
||||
@@ -12,6 +19,14 @@ use Doctrine\Migrations\AbstractMigration;
|
||||
*/
|
||||
final class Version20220426133048 extends AbstractMigration
|
||||
{
|
||||
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');
|
||||
}
|
||||
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user