FiltersDTO.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Dto;
  3. use App\Entity\User;
  4. use Symfony\Component\Validator\Constraints as Assert;
  5. class FiltersDTO
  6. {
  7. public function __construct(
  8. #[Assert\NotBlank()]
  9. #[Assert\GreaterThanOrEqual(10)]
  10. #[Assert\LessThanOrEqual(100)]
  11. public int $limit = 25,
  12. public ?User $userName = null,
  13. public null|int|string $note = 0,
  14. #[Assert\NotBlank()]
  15. public string $sortBy = 'dateSubmited',
  16. #[Assert\Choice(['ASC', 'DESC'])]
  17. public string $sortOrder = 'DESC',
  18. public ?User $userWantToView = null,
  19. public int $page = 1
  20. )
  21. {
  22. $this->note = $this->note === '' ? null : (int)$this->note;
  23. }
  24. public function toArray(): array
  25. {
  26. return [
  27. 'limit' => $this->limit,
  28. 'username' => $this->userName,
  29. 'sortBy' => $this->sortBy,
  30. 'sortOrder' => $this->sortOrder,
  31. 'note' => (int)$this->note,
  32. 'userWantToView' => $this->userWantToView,
  33. 'page' => $this->page
  34. ];
  35. }
  36. }