WidgetItem.php 2.9 KB

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