This commit is contained in:
2022-05-27 15:48:50 +02:00
parent 54a3e2b2ef
commit 5e5a855578
5 changed files with 55 additions and 26 deletions

View File

@@ -13,6 +13,7 @@ namespace Chill\MainBundle\Entity\Embeddable;
use Chill\MainBundle\Entity\User;
use Doctrine\ORM\Mapping as ORM;
use function array_key_exists;
/**
* @ORM\Embeddable
@@ -21,6 +22,7 @@ class PrivateCommentEmbeddable
{
/**
* @ORM\Column(type="json", nullable=false, options={"default": "{}"})
*
* @var array<int, string>
*/
private array $comments = [];
@@ -30,17 +32,17 @@ class PrivateCommentEmbeddable
return $this->comments[$user->getId()] ?? '';
}
public function hasCommentForUser(User $user): bool
{
return array_key_exists($user->getId(), $this->comments)
&& "" !== $this->comments[$user->getId()];
}
public function getComments(): ?array
{
return $this->comments;
}
public function hasCommentForUser(User $user): bool
{
return array_key_exists($user->getId(), $this->comments)
&& '' !== $this->comments[$user->getId()];
}
public function merge(PrivateCommentEmbeddable $newComment): self
{
$currentComments = null === $this->getComments() ? [] : $this->getComments();