You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
3.0 KiB

3 years ago
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  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\Search;
  26. use JsonSerializable;
  27. /**
  28. * Represents an entry in a list of results an app returns for a unified search
  29. * query.
  30. *
  31. * The app providing the results has to extend this class for customization. In
  32. * most cases apps do not have to add any additional code.
  33. *
  34. * @example ``class MailResultEntry extends SearchResultEntry {}`
  35. *
  36. * This approach was chosen over a final class as it allows Nextcloud to later
  37. * add new optional properties of an entry without having to break the usage of
  38. * this class in apps.
  39. *
  40. * @since 20.0.0
  41. */
  42. class SearchResultEntry implements JsonSerializable {
  43. /**
  44. * @var string
  45. * @since 20.0.0
  46. */
  47. protected $thumbnailUrl;
  48. /**
  49. * @var string
  50. * @since 20.0.0
  51. */
  52. protected $title;
  53. /**
  54. * @var string
  55. * @since 20.0.0
  56. */
  57. protected $subline;
  58. /**
  59. * @var string
  60. * @since 20.0.0
  61. */
  62. protected $resourceUrl;
  63. /**
  64. * @var string
  65. * @since 20.0.0
  66. */
  67. protected $icon;
  68. /**
  69. * @var boolean
  70. * @since 20.0.0
  71. */
  72. protected $rounded;
  73. /**
  74. * @param string $thumbnailUrl a relative or absolute URL to the thumbnail or icon of the entry
  75. * @param string $title a main title of the entry
  76. * @param string $subline the secondary line of the entry
  77. * @param string $resourceUrl the URL where the user can find the detail, like a deep link inside the app
  78. * @param string $icon the icon class or url to the icon
  79. * @param boolean $rounded is the thumbnail rounded
  80. *
  81. * @since 20.0.0
  82. */
  83. public function __construct(string $thumbnailUrl,
  84. string $title,
  85. string $subline,
  86. string $resourceUrl,
  87. string $icon = '',
  88. bool $rounded = false) {
  89. $this->thumbnailUrl = $thumbnailUrl;
  90. $this->title = $title;
  91. $this->subline = $subline;
  92. $this->resourceUrl = $resourceUrl;
  93. $this->icon = $icon;
  94. $this->rounded = $rounded;
  95. }
  96. /**
  97. * @return array
  98. *
  99. * @since 20.0.0
  100. */
  101. public function jsonSerialize(): array {
  102. return [
  103. 'thumbnailUrl' => $this->thumbnailUrl,
  104. 'title' => $this->title,
  105. 'subline' => $this->subline,
  106. 'resourceUrl' => $this->resourceUrl,
  107. 'icon' => $this->icon,
  108. 'rounded' => $this->rounded,
  109. ];
  110. }
  111. }