src/Entity/Messaging/Message.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Messaging;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Validator\Constraints as Assert;
  7. /**
  8.  * @ORM\Entity(repositoryClass="App\Repository\App\Messaging\MessageRepository")
  9.  * @ORM\EntityListeners({"App\EventSubscriber\Messaging\MessageEntitySubscriber"})
  10.  */
  11. class Message
  12. {
  13.     public const CUSTOMER_TYPE 'CUSTOMER_TYPE';
  14.     public const SCP_TYPE 'SCP_TYPE';
  15.     /**
  16.      * @ORM\Id
  17.      * @ORM\GeneratedValue
  18.      * @ORM\Column(type="integer")
  19.      */
  20.     protected $id;
  21.     /**
  22.      * @ORM\Column(type="datetime")
  23.      * @Assert\NotBlank
  24.      */
  25.     protected $date;
  26.     /**
  27.      * @ORM\Column(type="text")
  28.      * @Assert\NotBlank(groups={"front"})
  29.      */
  30.     protected $content;
  31.     /**
  32.      * @ORM\Column(type="string", length=255)
  33.      * @Assert\NotBlank
  34.      */
  35.     protected $type;
  36.     /**
  37.      * @ORM\ManyToOne(targetEntity="App\Entity\Messaging\Conversation", inversedBy="messages")
  38.      * @ORM\JoinColumn(nullable=false)
  39.      */
  40.     protected $conversation;
  41.     /**
  42.      * @ORM\OneToMany(targetEntity="App\Entity\Messaging\MessageFile", mappedBy="message", orphanRemoval=true, cascade={"persist"})
  43.      * @Assert\Valid
  44.      */
  45.     protected $messageFiles;
  46.     /**
  47.      * @ORM\Column(type="integer", nullable=true)
  48.      */
  49.     protected $sender;
  50.     public function __construct(string $type)
  51.     {
  52.         $this->date = new \DateTimeImmutable();
  53.         $this->messageFiles = new ArrayCollection();
  54.         $this->setType($type);
  55.     }
  56.     public function getId(): ?int
  57.     {
  58.         return $this->id;
  59.     }
  60.     public function getDate(): ?\DateTimeInterface
  61.     {
  62.         return $this->date;
  63.     }
  64.     public function setDate(\DateTimeInterface $date): self
  65.     {
  66.         $this->date $date;
  67.         return $this;
  68.     }
  69.     public function getContent(): ?string
  70.     {
  71.         return $this->content;
  72.     }
  73.     public function setContent(?string $content): self
  74.     {
  75.         $this->content $content;
  76.         return $this;
  77.     }
  78.     public function getType(): ?string
  79.     {
  80.         return $this->type;
  81.     }
  82.     public function setType(string $type): self
  83.     {
  84.         $this->type $type;
  85.         return $this;
  86.     }
  87.     public function getConversation(): ?Conversation
  88.     {
  89.         return $this->conversation;
  90.     }
  91.     public function setConversation(?Conversation $conversation): self
  92.     {
  93.         $this->conversation $conversation;
  94.         return $this;
  95.     }
  96.     /**
  97.      * @return Collection|MessageFile[]
  98.      */
  99.     public function getMessageFiles(): Collection
  100.     {
  101.         return $this->messageFiles;
  102.     }
  103.     public function addMessageFile(MessageFile $messageFile): self
  104.     {
  105.         if (!$this->messageFiles->contains($messageFile)) {
  106.             $this->messageFiles[] = $messageFile;
  107.             $messageFile->setMessage($this);
  108.         }
  109.         return $this;
  110.     }
  111.     public function removeMessageFile(MessageFile $messageFile): self
  112.     {
  113.         if ($this->messageFiles->contains($messageFile)) {
  114.             $this->messageFiles->removeElement($messageFile);
  115.             if ($messageFile->getMessage() === $this) {
  116.                 $messageFile->setMessage(null);
  117.             }
  118.         }
  119.         return $this;
  120.     }
  121.     public function setSender(int $sender): self
  122.     {
  123.         $this->sender $sender;
  124.         return $this;
  125.     }
  126.     public function getSender(): ?int
  127.     {
  128.         return $this->sender;
  129.     }
  130. }