1
0

WidgetItems.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\Dashboard\Model;
  8. use JsonSerializable;
  9. use OCP\Dashboard\IAPIWidgetV2;
  10. /**
  11. * Interface WidgetItems
  12. *
  13. * This class is used by {@see IAPIWidgetV2} interface.
  14. * It represents an array of widget items and additional context information that can be provided to clients via the Dashboard API
  15. *
  16. * @see IAPIWidgetV2::getItemsV2
  17. *
  18. * @since 27.1.0
  19. */
  20. class WidgetItems implements JsonSerializable {
  21. /**
  22. * @param $items WidgetItem[]
  23. *
  24. * @since 27.1.0
  25. */
  26. public function __construct(
  27. private array $items = [],
  28. private string $emptyContentMessage = '',
  29. private string $halfEmptyContentMessage = '',
  30. ) {
  31. }
  32. /**
  33. * Items to render in the widgets
  34. *
  35. * @since 27.1.0
  36. *
  37. * @return WidgetItem[]
  38. */
  39. public function getItems(): array {
  40. return $this->items;
  41. }
  42. /**
  43. * The "half" empty content message to show above the list of items.
  44. *
  45. * A non-empty string enables this feature.
  46. * An empty string hides the message and disables this feature.
  47. *
  48. * @since 27.1.0
  49. */
  50. public function getEmptyContentMessage(): string {
  51. return $this->emptyContentMessage;
  52. }
  53. /**
  54. * The empty content message to show in case of no items at all
  55. *
  56. * @since 27.1.0
  57. */
  58. public function getHalfEmptyContentMessage(): string {
  59. return $this->halfEmptyContentMessage;
  60. }
  61. /**
  62. * @since 27.1.0
  63. */
  64. public function jsonSerialize(): array {
  65. $items = array_map(static function (WidgetItem $item) {
  66. return $item->jsonSerialize();
  67. }, $this->getItems());
  68. return [
  69. 'items' => $items,
  70. 'emptyContentMessage' => $this->getEmptyContentMessage(),
  71. 'halfEmptyContentMessage' => $this->getHalfEmptyContentMessage(),
  72. ];
  73. }
  74. }