<?php
namespace App\Entity;
use App\Repository\UserSurveyCommentRepository;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=UserSurveyCommentRepository::class)
*/
class UserSurveyComment
{
public const TYPES = [
'problem' => 'Problème',
'resolution' => 'Résolution du problème',
'CMU' => "demande de CMU"
];
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="userSurveyComments")
* @ORM\JoinColumn(nullable=false)
*/
private $user;
/**
* @ORM\ManyToOne(targetEntity=UserSurvey::class, inversedBy="userSurveyComments")
* @ORM\JoinColumn(nullable=false)
*/
private $userSurvey;
/**
* @ORM\Column(type="datetime")
*/
private $dateAdd;
/**
* @ORM\Column(type="datetime")
*/
private $dateUpdate;
/**
* @ORM\Column(type="string", length=5000, nullable=true)
*/
private $Comment;
/**
* @ORM\Column(type="boolean")
*/
private $isArchived = false;
/**
* @ORM\ManyToOne(targetEntity=UserSurveyComment::class, inversedBy="replies")
*/
private $replyTo;
/**
* @ORM\OneToMany(targetEntity=UserSurveyComment::class, mappedBy="replyTo", orphanRemoval=true, cascade={"all"})
*/
private $replies;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $type;
public function __construct()
{
$this->setDateAdd(new DateTime());
$this->setDateUpdate(new DateTime());
$this->replies = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getUserSurvey(): ?UserSurvey
{
return $this->userSurvey;
}
public function setUserSurvey(?UserSurvey $userSurvey): self
{
$this->userSurvey = $userSurvey;
return $this;
}
public function getDateAdd(): ?\DateTimeInterface
{
return $this->dateAdd;
}
public function setDateAdd(\DateTimeInterface $dateAdd): self
{
$this->dateAdd = $dateAdd;
return $this;
}
public function getDateUpdate(): ?\DateTimeInterface
{
return $this->dateUpdate;
}
public function setDateUpdate(\DateTimeInterface $dateUpdate): self
{
$this->dateUpdate = $dateUpdate;
return $this;
}
public function getComment(): ?string
{
return $this->Comment;
}
public function setComment(string $Comment): self
{
$this->Comment = $Comment;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getReplies(): Collection
{
return $this->replies;
}
public function addReply(self $reply): self
{
if (!$this->replies->contains($reply)) {
$this->replies[] = $reply;
$reply->setReplyTo($this);
}
return $this;
}
public function removeReply(self $reply): self
{
if ($this->replies->removeElement($reply)) {
// set the owning side to null (unless already changed)
if ($reply->getReplyTo() === $this) {
$reply->setReplyTo(null);
}
}
return $this;
}
public function getReplyTo(): ?self
{
return $this->replyTo;
}
public function setReplyTo(?self $replyTo): self
{
$this->replyTo = $replyTo;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getNotArchivedReplies(): Collection
{
$notArchivedComments = [];
foreach ($this->replies as $comment) {
if (true !== $comment->getIsArchived()) {
$notArchivedComments[] = $comment;
}
}
return new ArrayCollection($notArchivedComments);
}
public function getIsArchived(): ?bool
{
return $this->isArchived;
}
public function setIsArchived(bool $isArchived): self
{
$this->isArchived = $isArchived;
return $this;
}
public function getTypeLabel(): string
{
if (array_key_exists($this->getType(), self::TYPES)) {
return self::TYPES[$this->getType()];
}
return '';
}
public function getType(): ?string
{
return $this->type;
}
public function setType(?string $type): self
{
if (in_array($type, array_keys(self::TYPES))) {
$this->type = $type;
}
return $this;
}
}