FrontMenuItem.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace Webkul\BagistoApi\Models;
  3. use ApiPlatform\Metadata\ApiProperty;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use ApiPlatform\Metadata\Get;
  6. use ApiPlatform\Metadata\GetCollection;
  7. use ApiPlatform\Metadata\GraphQl\Query;
  8. use ApiPlatform\Metadata\GraphQl\QueryCollection;
  9. use Longyi\FrontMenu\Models\FrontMenuItem as BaseFrontMenuItem;
  10. use Webkul\BagistoApi\Resolver\BaseQueryItemResolver;
  11. use Webkul\BagistoApi\Resolver\FrontMenuTreeResolver;
  12. use Webkul\BagistoApi\State\CursorAwareCollectionProvider;
  13. #[ApiResource(
  14. routePrefix: '/api/shop',
  15. shortName: 'frontMenu',
  16. operations: [
  17. new Get(),
  18. new GetCollection(
  19. provider: CursorAwareCollectionProvider::class,
  20. paginationEnabled: true,
  21. paginationClientItemsPerPage: true,
  22. paginationItemsPerPage: 15,
  23. paginationMaximumItemsPerPage: 100,
  24. ),
  25. ],
  26. graphQlOperations: [
  27. new Query(resolver: BaseQueryItemResolver::class),
  28. new QueryCollection(provider: CursorAwareCollectionProvider::class),
  29. new QueryCollection(
  30. name: 'tree',
  31. paginationEnabled: false,
  32. resolver: FrontMenuTreeResolver::class,
  33. ),
  34. ],
  35. )]
  36. class FrontMenuItem extends BaseFrontMenuItem
  37. {
  38. /**
  39. * Unique identifier.
  40. */
  41. #[ApiProperty(identifier: true, writable: false)]
  42. public function getId(): int
  43. {
  44. return (int) $this->id;
  45. }
  46. /**
  47. * Menu name.
  48. */
  49. #[ApiProperty(readable: true, writable: false)]
  50. public function getName(): ?string
  51. {
  52. return $this->name;
  53. }
  54. /**
  55. * Unique slug.
  56. */
  57. #[ApiProperty(readable: true, writable: false)]
  58. public function getSlug(): ?string
  59. {
  60. return $this->slug;
  61. }
  62. /**
  63. * Menu URL.
  64. */
  65. #[ApiProperty(readable: true, writable: false)]
  66. public function getUrl(): ?string
  67. {
  68. return $this->url;
  69. }
  70. /**
  71. * Menu image.
  72. */
  73. #[ApiProperty(readable: true, writable: false)]
  74. public function getImage(): ?string
  75. {
  76. return $this->image;
  77. }
  78. /**
  79. * Menu banner.
  80. */
  81. #[ApiProperty(readable: true, writable: false)]
  82. public function getBanner(): ?string
  83. {
  84. return $this->banner;
  85. }
  86. /**
  87. * Parent menu id.
  88. */
  89. #[ApiProperty(readable: true, writable: false)]
  90. public function getParentId(): ?int
  91. {
  92. return $this->parent_id ? (int) $this->parent_id : null;
  93. }
  94. /**
  95. * Sort order.
  96. */
  97. #[ApiProperty(readable: true, writable: false)]
  98. public function getSortOrder(): int
  99. {
  100. return (int) $this->sort_order;
  101. }
  102. /**
  103. * Status.
  104. */
  105. #[ApiProperty(readable: true, writable: false)]
  106. public function getStatus(): bool
  107. {
  108. return (bool) $this->status;
  109. }
  110. /**
  111. * Children menu items (hierarchical).
  112. */
  113. #[ApiProperty(readableLink: true, writable: false, description: 'Child menu items')]
  114. public function getChildren()
  115. {
  116. return $this->children;
  117. }
  118. }