src/Entity/Messaging/Conversation.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Messaging;
  3. use App\Entity\AdminUser;
  4. use App\Entity\User;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. /**
  10.  * @ORM\Entity(repositoryClass="App\Repository\App\Messaging\ConversationRepository")
  11.  */
  12. class Conversation
  13. {
  14.     public const STATUS_WAIT_CUSTOMER 'WAIT_CUSTOMER';
  15.     public const STATUS_WAIT_SCP 'WAIT_SCP';
  16.     public const STATUS_TERMINATE 'TERMINATE';
  17.     /**
  18.      * @ORM\Id
  19.      * @ORM\GeneratedValue
  20.      * @ORM\Column(type="integer")
  21.      */
  22.     protected $id;
  23.     /**
  24.      * @ORM\Column(type="string", length=255)
  25.      * @Assert\NotBlank
  26.      */
  27.     protected $status self::STATUS_WAIT_SCP;
  28.     /**
  29.      * @ORM\Column(type="datetime")
  30.      * @Assert\NotBlank
  31.      */
  32.     protected $updatedAt;
  33.     /**
  34.      * @ORM\Column(type="datetime")
  35.      * @Assert\NotBlank
  36.      */
  37.     protected $viewAt;
  38.     /**
  39.      * @ORM\Column(type="string", length=255)
  40.      * @Assert\NotBlank
  41.      */
  42.     protected $object;
  43.     /**
  44.      * @ORM\ManyToOne(targetEntity="App\Entity\Messaging\Subject", inversedBy="conversations")
  45.      */
  46.     protected $subject;
  47.     /**
  48.      * @ORM\Column(type="json", nullable=true)
  49.      *
  50.      * @var array
  51.      */
  52.     protected $contractNumbers = [];
  53.     /**
  54.      * @ORM\Column(type="boolean", nullable=true)
  55.      */
  56.     protected $allContracts;
  57.     /**
  58.      * @ORM\ManyToOne(targetEntity="App\Entity\Messaging\Team")
  59.      */
  60.     protected $team;
  61.     /**
  62.      * @ORM\ManyToOne(targetEntity="App\Entity\User")
  63.      * @ORM\JoinColumn(nullable=false, name="customer_user")
  64.      * @Assert\NotBlank
  65.      */
  66.     protected $user;
  67.     /**
  68.      * @ORM\OneToMany(targetEntity="App\Entity\Messaging\Message", mappedBy="conversation", orphanRemoval=true, cascade={"persist"})
  69.      * @ORM\OrderBy({"date" = "ASC"})
  70.      */
  71.     protected $messages;
  72.     /**
  73.      * @ORM\Column(type="boolean")
  74.      * @Assert\Type(type="boolean")
  75.      */
  76.     protected $claim false;
  77.     /**
  78.      * @ORM\Column(type="boolean")
  79.      * @Assert\Type(type="boolean")
  80.      */
  81.     protected $hasAttachments false;
  82.     public function __construct(
  83.         User|AdminUser|null $user null,
  84.         ?Subject            $subject null
  85.     ) {
  86.         if (null !== $subject) {
  87.             $this->setSubject($subject);
  88.         }
  89.         if (null !== $user) {
  90.             $this->setUser($user);
  91.         }
  92.         $this->messages = new ArrayCollection();
  93.         $now = new \DateTimeImmutable();
  94.         $this->viewAt $now;
  95.         $this->updatedAt $now;
  96.     }
  97.     public function getId(): ?int
  98.     {
  99.         return $this->id;
  100.     }
  101.     public function getStatus(): ?string
  102.     {
  103.         return $this->status;
  104.     }
  105.     public function setStatus(string $status): self
  106.     {
  107.         $this->status $status;
  108.         return $this;
  109.     }
  110.     public function getUpdatedAt(): ?\DateTimeInterface
  111.     {
  112.         return $this->updatedAt;
  113.     }
  114.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  115.     {
  116.         $this->updatedAt $updatedAt;
  117.         return $this;
  118.     }
  119.     public function getViewAt(): ?\DateTimeInterface
  120.     {
  121.         return $this->viewAt;
  122.     }
  123.     public function setViewAt(\DateTimeInterface $viewAt): self
  124.     {
  125.         $this->viewAt $viewAt;
  126.         return $this;
  127.     }
  128.     public function getObject(): ?string
  129.     {
  130.         $theme $this->subject?->getTheme()?->getLabel();
  131.         if (!is_null($theme)) {
  132.             return str_replace(sprintf('{%s}'Theme::THEME_STAMP), $theme$this->object);
  133.         }
  134.         return $this->object;
  135.     }
  136.     public function setObject(string $object): self
  137.     {
  138.         $this->object $object;
  139.         return $this;
  140.     }
  141.     public function getSubject(): ?Subject
  142.     {
  143.         return $this->subject;
  144.     }
  145.     public function setSubject(?Subject $subject): self
  146.     {
  147.         $this->subject $subject;
  148.         return $this;
  149.     }
  150.     /**
  151.      * The contractId property was removed, but the getter could still be needed
  152.      * for compatibility (eg. serialization)
  153.      */
  154.     public function getContractId(): ?string
  155.     {
  156.         return null;
  157.     }
  158.     public function getContractNumbers(): ?array
  159.     {
  160.         return $this->contractNumbers;
  161.     }
  162.     public function setContractNumbers(array $contractNumbers): self
  163.     {
  164.         $this->contractNumbers $contractNumbers;
  165.         return $this;
  166.     }
  167.     public function isAllContracts()
  168.     {
  169.         return $this->allContracts;
  170.     }
  171.     public function setAllContracts(?bool $allContracts): self
  172.     {
  173.         $this->allContracts $allContracts;
  174.         return $this;
  175.     }
  176.     public function getTeam(): ?Team
  177.     {
  178.         return $this->team;
  179.     }
  180.     public function setTeam(?Team $team): self
  181.     {
  182.         $this->team $team;
  183.         return $this;
  184.     }
  185.     public function getUser(): User|AdminUser|null
  186.     {
  187.         return $this->user;
  188.     }
  189.     public function setUser(User|AdminUser|null $user): self
  190.     {
  191.         $this->user $user;
  192.         return $this;
  193.     }
  194.     public function setClaim(bool $claim): self
  195.     {
  196.         $this->claim $claim;
  197.         return $this;
  198.     }
  199.     public function isClaim(): bool
  200.     {
  201.         return $this->claim;
  202.     }
  203.     /**
  204.      * @return Collection|Message[]
  205.      */
  206.     public function getMessages(): Collection
  207.     {
  208.         return $this->messages;
  209.     }
  210.     public function addMessage(Message $message): self
  211.     {
  212.         if (!$this->messages->contains($message)) {
  213.             $this->messages[] = $message;
  214.             $this->setUpdatedAt(new \DateTimeImmutable());
  215.             $message->setConversation($this);
  216.         }
  217.         return $this;
  218.     }
  219.     public function removeMessage(Message $message): self
  220.     {
  221.         if ($this->messages->contains($message)) {
  222.             $this->messages->removeElement($message);
  223.             // set the owning side to null (unless already changed)
  224.             if ($message->getConversation() === $this) {
  225.                 $message->setConversation(null);
  226.             }
  227.         }
  228.         return $this;
  229.     }
  230.     public function hasAttachments(): bool
  231.     {
  232.         return $this->hasAttachments;
  233.     }
  234.     public function setHasAttachments(bool $hasAttachments): self
  235.     {
  236.         $this->hasAttachments $hasAttachments;
  237.         return $this;
  238.     }
  239.     public function isRead(): bool
  240.     {
  241.         return $this->getViewAt() > $this->getUpdatedAt();
  242.     }
  243.     public function getEntityName(): string
  244.     {
  245.         return 'Conversation';
  246.     }
  247. }