improvements on private comments

This commit is contained in:
2022-05-27 15:39:32 +02:00
parent e19cac168b
commit 014c460eef
12 changed files with 125 additions and 79 deletions

View File

@@ -20,15 +20,22 @@ use Doctrine\ORM\Mapping as ORM;
class PrivateCommentEmbeddable
{
/**
* @ORM\Column(type="json", nullable=true)
* @ORM\Column(type="json", nullable=false, options={"default": "{}"})
* @var array<int, string>
*/
private ?array $comments = [];
private array $comments = [];
public function getCommentForUser(User $user): string
{
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;
@@ -47,7 +54,7 @@ class PrivateCommentEmbeddable
public function setCommentForUser(User $user, string $content): self
{
$this->comments[$user->getId()] = $content;
$this->comments[$user->getId()] = trim($content);
return $this;
}