DolibarrDocDownload.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\ApiResources\Dolibarr;
  4. use ApiPlatform\Metadata\ApiProperty;
  5. use ApiPlatform\Metadata\ApiResource;
  6. use ApiPlatform\Metadata\Get;
  7. use App\Enum\Dolibarr\DolibarrDocTypeEnum;
  8. use App\State\Provider\Dolibarr\DolibarrDocDownloadProvider;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. /**
  11. * Demande de téléchargement d'un fichier depuis Dolibarr (facture, bon de commande, etc).
  12. */
  13. #[ApiResource(
  14. operations: [
  15. new Get(
  16. uriTemplate: '/dolibarr/download/{dolibarrDocType}/{ref}',
  17. requirements: [
  18. 'ref' => '[\w-]+',
  19. ],
  20. security: '(is_granted("ROLE_ADMIN_CORE") or
  21. is_granted("ROLE_ADMINISTRATIF_MANAGER_CORE") or
  22. is_granted("ROLE_PEDAGOGICS_MANAGER_CORE") or
  23. is_granted("ROLE_FINANCIAL_MANAGER_CORE"))',
  24. provider: DolibarrDocDownloadProvider::class
  25. ),
  26. ]
  27. )]
  28. class DolibarrDocDownload
  29. {
  30. /**
  31. * Id 'bidon' ajouté par défaut pour permettre la construction
  32. * de l'IRI par api platform.
  33. */
  34. #[ApiProperty(identifier: true)]
  35. protected int $id = 0;
  36. /**
  37. * Type de fichier à télécharger.
  38. */
  39. #[Assert\Type(type: DolibarrDocTypeEnum::class)]
  40. protected DolibarrDocTypeEnum $dolibarrDocType;
  41. /**
  42. * The dolibarr reference of the document (ex: CO2502-0380, FA2101-02988, ...)
  43. * Must be URL Encoded.
  44. */
  45. protected string $ref;
  46. public function getId(): int
  47. {
  48. return $this->id;
  49. }
  50. public function setId(int $id): self
  51. {
  52. $this->id = $id;
  53. return $this;
  54. }
  55. public function getDolibarrDocType(): DolibarrDocTypeEnum
  56. {
  57. return $this->dolibarrDocType;
  58. }
  59. public function setDolibarrDocType(DolibarrDocTypeEnum $dolibarrDocType): self
  60. {
  61. $this->dolibarrDocType = $dolibarrDocType;
  62. return $this;
  63. }
  64. public function getRef(): string
  65. {
  66. return $this->ref;
  67. }
  68. public function setRef(string $ref): self
  69. {
  70. $this->ref = $ref;
  71. return $this;
  72. }
  73. }