WidgetItem.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2021, Julien Veyssier <eneiluj@posteo.net>
  5. *
  6. * @author Julien Veyssier <eneiluj@posteo.net>
  7. * @author Richard Steinmetz <richard@steinmetz.cloud>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCP\Dashboard\Model;
  26. use JsonSerializable;
  27. /**
  28. * Interface WidgetItem
  29. *
  30. * This class is used by IAPIWidget interface.
  31. * It represents an widget item data that can be provided to clients via the Dashboard API
  32. * @see IAPIWidget::getItems
  33. *
  34. * @since 22.0.0
  35. *
  36. */
  37. final class WidgetItem implements JsonSerializable {
  38. /** @var string */
  39. private $title = '';
  40. /** @var string */
  41. private $subtitle = '';
  42. /** @var string */
  43. private $link = '';
  44. /** @var string */
  45. private $iconUrl = '';
  46. /** @var string
  47. * Timestamp or ID used by the dashboard API to avoid getting already retrieved items
  48. */
  49. private $sinceId = '';
  50. /**
  51. * Overlay icon to show in the bottom right corner of {@see $iconUrl}
  52. *
  53. * @since 27.1.0
  54. */
  55. private string $overlayIconUrl = '';
  56. /**
  57. * WidgetItem constructor
  58. *
  59. * @since 22.0.0
  60. */
  61. public function __construct(string $title = '',
  62. string $subtitle = '',
  63. string $link = '',
  64. string $iconUrl = '',
  65. string $sinceId = '',
  66. string $overlayIconUrl = '') {
  67. $this->title = $title;
  68. $this->subtitle = $subtitle;
  69. $this->iconUrl = $iconUrl;
  70. $this->link = $link;
  71. $this->sinceId = $sinceId;
  72. $this->overlayIconUrl = $overlayIconUrl;
  73. }
  74. /**
  75. * Get the item title
  76. *
  77. * @since 22.0.0
  78. *
  79. * @return string
  80. */
  81. public function getTitle(): string {
  82. return $this->title;
  83. }
  84. /**
  85. * Get the item subtitle
  86. *
  87. * @since 22.0.0
  88. *
  89. * @return string
  90. */
  91. public function getSubtitle(): string {
  92. return $this->subtitle;
  93. }
  94. /**
  95. * Get the item link
  96. *
  97. * @since 22.0.0
  98. *
  99. * @return string
  100. */
  101. public function getLink(): string {
  102. return $this->link;
  103. }
  104. /**
  105. * Get the item icon URL
  106. * The icon should be a square svg or a jpg/png of at least 44x44px
  107. *
  108. * @since 22.0.0
  109. *
  110. * @return string
  111. */
  112. public function getIconUrl(): string {
  113. return $this->iconUrl;
  114. }
  115. /**
  116. * Get the item since ID
  117. *
  118. * @since 22.0.0
  119. *
  120. * @return string
  121. */
  122. public function getSinceId(): string {
  123. return $this->sinceId;
  124. }
  125. /**
  126. * Get the overlay icon url
  127. *
  128. * @since 27.1.0
  129. *
  130. * @return string
  131. */
  132. public function getOverlayIconUrl(): string {
  133. return $this->overlayIconUrl;
  134. }
  135. /**
  136. * @since 22.0.0
  137. *
  138. * @return array
  139. */
  140. public function jsonSerialize(): array {
  141. return [
  142. 'subtitle' => $this->getSubtitle(),
  143. 'title' => $this->getTitle(),
  144. 'link' => $this->getLink(),
  145. 'iconUrl' => $this->getIconUrl(),
  146. 'overlayIconUrl' => $this->getOverlayIconUrl(),
  147. 'sinceId' => $this->getSinceId(),
  148. ];
  149. }
  150. }