src/Entity/Discussion.php line 48

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  4. use ApiPlatform\Metadata\ApiFilter;
  5. use ApiPlatform\Metadata\ApiResource;
  6. use ApiPlatform\Metadata\Get;
  7. use ApiPlatform\Metadata\GetCollection;
  8. use ApiPlatform\Metadata\Post;
  9. use App\Controller\Action\DiscussionListController;
  10. use App\Controller\Action\DiscussionPostController;
  11. use App\Repository\DiscussionRepository;
  12. use App\State\DiscussionPostProcessor;
  13. use Doctrine\Common\Collections\Collection;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use Symfony\Component\Serializer\Annotation\Groups;
  16. #[ORM\Entity(repositoryClassDiscussionRepository::class)]
  17. #[ApiResource(
  18.     operations: [
  19.         new Get(),
  20.         new GetCollection(),
  21.         new Post(),
  22.         new Post(
  23.             uriTemplate'discussions/new_discussion',
  24.             controllerDiscussionPostController::class,
  25.             name'_api_/discussions/new_discussion',
  26.         ),
  27.         new GetCollection(
  28.             uriTemplate'discussion/list',
  29.             controllerDiscussionListController::class,
  30.             readfalse,
  31.             writefalse,
  32.             name'_api_/discussion/list'
  33.         )
  34.     ],
  35.     normalizationContext: ['groups' => ['discussion.get']],
  36.     denormalizationContext: ['groups' => ['discussion.write']]
  37. )]
  38. #[ApiFilter(
  39.     SearchFilter::class,
  40.     properties: [
  41.         'type' => 'exact',
  42.         'site' => 'exact',
  43.     ]
  44. )]
  45. class Discussion
  46. {
  47.     #[ORM\Id]
  48.     #[ORM\GeneratedValue]
  49.     #[ORM\Column]
  50.     #[Groups(['discussion.write','discussion.get'])]
  51.     private ?int $id null;
  52.     #[ORM\Column(type"text"nullabletrue)]
  53.     #[Groups(['discussion.write','discussion.get'])]
  54.     private ?string $topic null;
  55.     #[ORM\Column(type"datetime"nullabletrue)]
  56.     #[Groups(['discussion.write','discussion.get'])]
  57.     private \DateTimeInterface $createdAt;
  58.     #[ORM\ManyToOne(inversedBy'discussions')]
  59.     #[Groups(['discussion.write','discussion.get'])]
  60.     private ?User $user null;
  61.     #[ORM\ManyToOne(inversedBy'discussions')]
  62.     private ?Document $document null;
  63.     #[ORM\OneToMany(mappedBy'discussion'targetEntityMessage::class)]
  64.     private Collection $messages;
  65.     #[ORM\ManyToOne]
  66.     #[ORM\JoinColumn(nullablefalse)]
  67.     #[Groups(['discussion.get'])]
  68.     private ?Site $site null;
  69.     #[ORM\Column(type"string"length255nullabletrue)]
  70.     #[Groups(['discussion.write','discussion.get'])]
  71.     private ?string $type null;
  72.     #[ORM\Column(nullabletrue)]
  73.     #[Groups(['discussion.write','discussion.get'])]
  74.     private ?\DateTimeImmutable $updatedAt null;
  75.     public function __construct()
  76.     {
  77.         $this->createdAt = new \DateTime();
  78.     }
  79.     /**
  80.      * @return int|null
  81.      */
  82.     public function getId(): ?int
  83.     {
  84.         return $this->id;
  85.     }
  86.     /**
  87.      * @param int|null $id
  88.      */
  89.     public function setId(?int $id): void
  90.     {
  91.         $this->id $id;
  92.     }
  93.     /**
  94.      * @return string|null
  95.      */
  96.     public function getTopic(): ?string
  97.     {
  98.         return $this->topic;
  99.     }
  100.     /**
  101.      * @param string $topic
  102.      */
  103.     public function setTopic(?string $topic): void
  104.     {
  105.         $this->topic $topic;
  106.     }
  107.     /**
  108.      * @return \DateTimeInterface
  109.      */
  110.     public function getCreatedAt(): \DateTimeInterface
  111.     {
  112.         return $this->createdAt;
  113.     }
  114.     /**
  115.      * @param \DateTimeInterface $createdAt
  116.      */
  117.     public function setCreatedAt(\DateTimeInterface $createdAt): void
  118.     {
  119.         $this->createdAt $createdAt;
  120.     }
  121.     public function getUser(): ?User
  122.     {
  123.         return $this->user;
  124.     }
  125.     public function setUser(?User $user): self
  126.     {
  127.         $this->user $user;
  128.         return $this;
  129.     }
  130.     public function getDocument(): ?Document
  131.     {
  132.         return $this->document;
  133.     }
  134.     public function setDocument(?Document $document): self
  135.     {
  136.         $this->document $document;
  137.         return $this;
  138.     }
  139.     /**
  140.      * @return Collection<int, Discussion>
  141.      */
  142.     public function getMessages(): Collection
  143.     {
  144.         return $this->messages;
  145.     }
  146.     public function addMessage(Message $message): self
  147.     {
  148.         if (!$this->messages->contains($message)) {
  149.             $this->messages->add($message);
  150.         }
  151.         return $this;
  152.     }
  153.     public function removeMessage(Message $message): self
  154.     {
  155.         $this->messages->removeElement($message);
  156.         return $this;
  157.     }
  158.     public function getSite(): ?Site
  159.     {
  160.         return $this->site;
  161.     }
  162.     public function setSite(?Site $site): self
  163.     {
  164.         $this->site $site;
  165.         return $this;
  166.     }
  167.     /**
  168.      * @return string|null
  169.      */
  170.     public function getType(): ?string
  171.     {
  172.         return $this->type;
  173.     }
  174.     /**
  175.      * @param string|null $type
  176.      */
  177.     public function setType(?string $type): void
  178.     {
  179.         $this->type $type;
  180.     }
  181.     public function getUpdatedAt(): ?\DateTimeImmutable
  182.     {
  183.         return $this->updatedAt;
  184.     }
  185.     public function setUpdatedAt(?\DateTimeImmutable $updatedAt): self
  186.     {
  187.         $this->updatedAt $updatedAt;
  188.         return $this;
  189.     }
  190. }