1
0

WidgetItem.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\Dashboard\Model;
  8. use JsonSerializable;
  9. /**
  10. * Interface WidgetItem
  11. *
  12. * This class is used by IAPIWidget interface.
  13. * It represents an widget item data that can be provided to clients via the Dashboard API
  14. * @see IAPIWidget::getItems
  15. *
  16. * @since 22.0.0
  17. *
  18. */
  19. final class WidgetItem implements JsonSerializable {
  20. /** @var string */
  21. private $title = '';
  22. /** @var string */
  23. private $subtitle = '';
  24. /** @var string */
  25. private $link = '';
  26. /** @var string */
  27. private $iconUrl = '';
  28. /** @var string
  29. * Timestamp or ID used by the dashboard API to avoid getting already retrieved items
  30. */
  31. private $sinceId = '';
  32. /**
  33. * Overlay icon to show in the bottom right corner of {@see $iconUrl}
  34. *
  35. * @since 27.1.0
  36. */
  37. private string $overlayIconUrl = '';
  38. /**
  39. * WidgetItem constructor
  40. *
  41. * @since 22.0.0
  42. */
  43. public function __construct(string $title = '',
  44. string $subtitle = '',
  45. string $link = '',
  46. string $iconUrl = '',
  47. string $sinceId = '',
  48. string $overlayIconUrl = '') {
  49. $this->title = $title;
  50. $this->subtitle = $subtitle;
  51. $this->iconUrl = $iconUrl;
  52. $this->link = $link;
  53. $this->sinceId = $sinceId;
  54. $this->overlayIconUrl = $overlayIconUrl;
  55. }
  56. /**
  57. * Get the item title
  58. *
  59. * @since 22.0.0
  60. *
  61. * @return string
  62. */
  63. public function getTitle(): string {
  64. return $this->title;
  65. }
  66. /**
  67. * Get the item subtitle
  68. *
  69. * @since 22.0.0
  70. *
  71. * @return string
  72. */
  73. public function getSubtitle(): string {
  74. return $this->subtitle;
  75. }
  76. /**
  77. * Get the item link
  78. *
  79. * @since 22.0.0
  80. *
  81. * @return string
  82. */
  83. public function getLink(): string {
  84. return $this->link;
  85. }
  86. /**
  87. * Get the item icon URL
  88. * The icon should be a square svg or a jpg/png of at least 44x44px
  89. *
  90. * @since 22.0.0
  91. *
  92. * @return string
  93. */
  94. public function getIconUrl(): string {
  95. return $this->iconUrl;
  96. }
  97. /**
  98. * Get the item since ID
  99. *
  100. * @since 22.0.0
  101. *
  102. * @return string
  103. */
  104. public function getSinceId(): string {
  105. return $this->sinceId;
  106. }
  107. /**
  108. * Get the overlay icon url
  109. *
  110. * @since 27.1.0
  111. *
  112. * @return string
  113. */
  114. public function getOverlayIconUrl(): string {
  115. return $this->overlayIconUrl;
  116. }
  117. /**
  118. * @since 22.0.0
  119. * @return array{
  120. * subtitle: string,
  121. * title: string,
  122. * link: string,
  123. * iconUrl: string,
  124. * overlayIconUrl: string,
  125. * sinceId: string,
  126. * }
  127. */
  128. public function jsonSerialize(): array {
  129. return [
  130. 'subtitle' => $this->getSubtitle(),
  131. 'title' => $this->getTitle(),
  132. 'link' => $this->getLink(),
  133. 'iconUrl' => $this->getIconUrl(),
  134. 'overlayIconUrl' => $this->getOverlayIconUrl(),
  135. 'sinceId' => $this->getSinceId(),
  136. ];
  137. }
  138. }