TeamResource.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCP\Teams;
  7. /**
  8. * @since 29.0.0
  9. */
  10. class TeamResource implements \JsonSerializable {
  11. /**
  12. * @since 29.0.0
  13. */
  14. public function __construct(
  15. private ITeamResourceProvider $teamResourceProvider,
  16. private string $resourceId,
  17. private string $label,
  18. private string $url,
  19. private ?string $iconSvg = null,
  20. private ?string $iconURL = null,
  21. private ?string $iconEmoji = null,
  22. ) {
  23. }
  24. /**
  25. * Returns the provider details for the current resource
  26. *
  27. * @since 29.0.0
  28. */
  29. public function getProvider(): ITeamResourceProvider {
  30. return $this->teamResourceProvider;
  31. }
  32. /**
  33. * Unique id of the resource (e.g. primary key id)
  34. * @since 29.0.0
  35. */
  36. public function getId(): string {
  37. return $this->resourceId;
  38. }
  39. /**
  40. * User visible label when listing resources
  41. *
  42. * @since 29.0.0
  43. */
  44. public function getLabel(): string {
  45. return $this->label;
  46. }
  47. /**
  48. * Absolute url to navigate the user to the resource
  49. *
  50. * @since 29.0.0
  51. */
  52. public function getUrl(): string {
  53. return $this->url;
  54. }
  55. /**
  56. * Svg icon to show next to the name for the resource
  57. *
  58. * From all icons the first one returning not null will be picked in order: iconEmoji, iconSvg, iconUrl
  59. *
  60. * @since 29.0.0
  61. */
  62. public function getIconSvg(): ?string {
  63. return $this->iconSvg;
  64. }
  65. /**
  66. * Image url of the icon to show next to the name for the resource
  67. *
  68. * From all icons the first one returning not null will be picked in order: iconEmoji, iconSvg, iconUrl
  69. *
  70. * @since 29.0.0
  71. */
  72. public function getIconURL(): ?string {
  73. return $this->iconURL;
  74. }
  75. /**
  76. * Emoji show next to the name for the resource
  77. *
  78. * From all icons the first one returning not null will be picked in order: iconEmoji, iconSvg, iconUrl
  79. *
  80. * @since 29.0.0
  81. */
  82. public function getIconEmoji(): ?string {
  83. return $this->iconEmoji;
  84. }
  85. /**
  86. * @since 29.0.0
  87. */
  88. public function jsonSerialize(): array {
  89. return [
  90. 'id' => $this->resourceId,
  91. 'label' => $this->label,
  92. 'url' => $this->url,
  93. 'iconSvg' => $this->iconSvg,
  94. 'iconURL' => $this->iconURL,
  95. 'iconEmoji' => $this->iconEmoji,
  96. 'provider' => [
  97. 'id' => $this->teamResourceProvider->getId(),
  98. 'name' => $this->teamResourceProvider->getName(),
  99. 'icon' => $this->teamResourceProvider->getIconSvg(),
  100. ]
  101. ];
  102. }
  103. }