TeamResource.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2024 Julius Härtl <jus@bitgrid.net>
  4. *
  5. * @author Julius Härtl <jus@bitgrid.net>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. namespace OCP\Teams;
  23. /**
  24. * @since 29.0.0
  25. */
  26. class TeamResource implements \JsonSerializable {
  27. /**
  28. * @since 29.0.0
  29. */
  30. public function __construct(
  31. private ITeamResourceProvider $teamResourceProvider,
  32. private string $resourceId,
  33. private string $label,
  34. private string $url,
  35. private ?string $iconSvg = null,
  36. private ?string $iconURL = null,
  37. private ?string $iconEmoji = null,
  38. ) {
  39. }
  40. /**
  41. * Returns the provider details for the current resource
  42. *
  43. * @since 29.0.0
  44. */
  45. public function getProvider(): ITeamResourceProvider {
  46. return $this->teamResourceProvider;
  47. }
  48. /**
  49. * Unique id of the resource (e.g. primary key id)
  50. * @since 29.0.0
  51. */
  52. public function getId(): string {
  53. return $this->resourceId;
  54. }
  55. /**
  56. * User visible label when listing resources
  57. *
  58. * @since 29.0.0
  59. */
  60. public function getLabel(): string {
  61. return $this->label;
  62. }
  63. /**
  64. * Absolute url to navigate the user to the resource
  65. *
  66. * @since 29.0.0
  67. */
  68. public function getUrl(): string {
  69. return $this->url;
  70. }
  71. /**
  72. * Svg icon to show next to the name for the resource
  73. *
  74. * From all icons the first one returning not null will be picked in order: iconEmoji, iconSvg, iconUrl
  75. *
  76. * @since 29.0.0
  77. */
  78. public function getIconSvg(): ?string {
  79. return $this->iconSvg;
  80. }
  81. /**
  82. * Image url of the icon to show next to the name for the resource
  83. *
  84. * From all icons the first one returning not null will be picked in order: iconEmoji, iconSvg, iconUrl
  85. *
  86. * @since 29.0.0
  87. */
  88. public function getIconURL(): ?string {
  89. return $this->iconURL;
  90. }
  91. /**
  92. * Emoji show next to the name for the resource
  93. *
  94. * From all icons the first one returning not null will be picked in order: iconEmoji, iconSvg, iconUrl
  95. *
  96. * @since 29.0.0
  97. */
  98. public function getIconEmoji(): ?string {
  99. return $this->iconEmoji;
  100. }
  101. /**
  102. * @since 29.0.0
  103. */
  104. public function jsonSerialize(): array {
  105. return [
  106. 'id' => $this->resourceId,
  107. 'label' => $this->label,
  108. 'url' => $this->url,
  109. 'iconSvg' => $this->iconSvg,
  110. 'iconURL' => $this->iconURL,
  111. 'iconEmoji' => $this->iconEmoji,
  112. 'provider' => [
  113. 'id' => $this->teamResourceProvider->getId(),
  114. 'name' => $this->teamResourceProvider->getName(),
  115. 'icon' => $this->teamResourceProvider->getIconSvg(),
  116. ]
  117. ];
  118. }
  119. }