src/Entity/Forum/Thread.php line 17

  1. <?php
  2. namespace App\Entity\Forum;
  3. use App\Entity\Common\Owner;
  4. use App\Entity\Traits\TrackerFields;
  5. use App\Entity\Traits\UserCreatedInterface;
  6. use App\Entity\Traits\UserUpdatedInterface;
  7. use App\Model\Common\HaveOwnerInterface;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. #[ORM\Table(name'forum_thread')]
  12. #[ORM\Entity(repositoryClass'App\Repository\Forum\ThreadRepository')]
  13. #[ORM\HasLifecycleCallbacks]
  14. class Thread implements UserCreatedInterfaceUserUpdatedInterfaceHaveOwnerInterface
  15. {
  16.     use TrackerFields;
  17.     /**
  18.      * @var int|null
  19.      */
  20.     #[ORM\Id]
  21.     #[ORM\GeneratedValue(strategy'AUTO')]
  22.     #[ORM\Column(type'integer')]
  23.     private $id;
  24.     /**
  25.      * @var string|null
  26.      */
  27.     #[ORM\Column(type'string')]
  28.     private $caption;
  29.     /**
  30.      * @var Owner
  31.      */
  32.     #[ORM\Embedded(class: 'App\Entity\Common\Owner')]
  33.     private $owner;
  34.     /**
  35.      * @var Post|null
  36.      */
  37.     #[ORM\ManyToOne(targetEntity'App\Entity\Forum\Post'cascade: ['persist'])]
  38.     #[ORM\JoinColumn(nullabletrue)]
  39.     private $lastMessage;
  40.     /**
  41.      * @var Collection
  42.      */
  43.     #[ORM\OneToMany(targetEntity'App\Entity\Forum\Post'mappedBy'thread')]
  44.     #[ORM\OrderBy(['created_at' => 'ASC'])]
  45.     private $messages;
  46.     public function __construct()
  47.     {
  48.         $this->owner = new Owner();
  49.         $this->messages = new ArrayCollection();
  50.     }
  51.     /**
  52.      * @return Owner
  53.      */
  54.     public function getOwner(): Owner
  55.     {
  56.         return $this->owner;
  57.     }
  58.     /**
  59.      * @param Owner $owner
  60.      */
  61.     public function setOwner(Owner $owner): void
  62.     {
  63.         $this->owner $owner;
  64.     }
  65.     /**
  66.      * @return int|null
  67.      */
  68.     public function getId(): ?int
  69.     {
  70.         return $this->id;
  71.     }
  72.     /**
  73.      * @param int|null $id
  74.      */
  75.     public function setId(?int $id): void
  76.     {
  77.         $this->id $id;
  78.     }
  79.     /**
  80.      * @return string|null
  81.      */
  82.     public function getCaption(): ?string
  83.     {
  84.         return $this->caption;
  85.     }
  86.     /**
  87.      * @param string|null $caption
  88.      */
  89.     public function setCaption(?string $caption): void
  90.     {
  91.         $this->caption $caption;
  92.     }
  93.     /**
  94.      * @return Post|null
  95.      */
  96.     public function getLastMessage(): ?Post
  97.     {
  98.         return $this->lastMessage;
  99.     }
  100.     /**
  101.      * @param Post|null $lastMessage
  102.      */
  103.     public function setLastMessage(?Post $lastMessage): void
  104.     {
  105.         $this->lastMessage $lastMessage;
  106.     }
  107.     /**
  108.      * @return Collection
  109.      */
  110.     public function getMessages(): Collection
  111.     {
  112.         return $this->messages;
  113.     }
  114.     /**
  115.      * @param Collection $messages
  116.      */
  117.     public function setMessages(Collection $messages): void
  118.     {
  119.         $this->messages $messages;
  120.     }
  121. }