SearchOption.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\FullTextSearch\Model;
  8. use JsonSerializable;
  9. use OCP\FullTextSearch\Model\ISearchOption;
  10. /**
  11. * @since 15.0.0
  12. *
  13. * Class ISearchOption
  14. *
  15. * @package OC\FullTextSearch\Model
  16. */
  17. final class SearchOption implements ISearchOption, JsonSerializable {
  18. /**
  19. * *
  20. *
  21. * The array can be empty in case no search options are available.
  22. * The format of the array must be like this:
  23. *
  24. * [
  25. * 'panel' => [
  26. * 'options' => [
  27. * OPTION1,
  28. * OPTION2,
  29. * OPTION3
  30. * ]
  31. * ],
  32. * 'navigation' => [
  33. * 'icon' => 'css-class-of-the-icon',
  34. * 'options' => [
  35. * OPTION1,
  36. * OPTION2,
  37. * OPTION3
  38. * ]
  39. * ]
  40. * ]
  41. *
  42. * - PANEL contains entries that will be displayed in the app itself, when
  43. * a search is initiated.
  44. * - NAVIGATION contains entries that will be available when using the
  45. * FullTextSearch navigation page
  46. * - OPTION is an element that define each option available to the user.
  47. *
  48. * The format for the options must be like this:
  49. *
  50. * [
  51. * 'name' => 'name_of_the_option',
  52. * 'title' => 'Name displayed in the panel',
  53. * 'type' => '',
  54. * 'size' => '' (optional),
  55. * 'placeholder' => '' (optional)
  56. * ]
  57. *
  58. * - NAME is the variable name that is sent to the IFullTextSearchProvider
  59. * when a ISearchRequest is requested. (keys in the array returned by the
  60. * ISearchRequest->getOptions())
  61. * - TYPE can be 'input' or 'checkbox'
  62. * - SIZE is only used in case TYPE='input', default is 'large' but can be
  63. * 'small'
  64. * - PLACEHOLDER is only used in case TYPE='input', default is empty.
  65. */
  66. /**
  67. * ISearchOption constructor.
  68. *
  69. * Some value can be set during the creation of the object.
  70. *
  71. * @since 15.0.0
  72. */
  73. public function __construct(
  74. private string $name = '',
  75. private string $title = '',
  76. private string $type = '',
  77. private string $size = '',
  78. private string $placeholder = '',
  79. ) {
  80. }
  81. /**
  82. * Set the name/key of the option.
  83. * The string should only contain alphanumerical chars and underscore.
  84. * The key can be retrieved when using ISearchRequest::getOption
  85. *
  86. * @see ISearchRequest::getOption
  87. *
  88. * @since 15.0.0
  89. */
  90. public function setName(string $name): ISearchOption {
  91. $this->name = $name;
  92. return $this;
  93. }
  94. /**
  95. * Get the name/key of the option.
  96. *
  97. * @since 15.0.0
  98. */
  99. public function getName(): string {
  100. return $this->name;
  101. }
  102. /**
  103. * Set the title/display name of the option.
  104. *
  105. * @since 15.0.0
  106. */
  107. public function setTitle(string $title): ISearchOption {
  108. $this->title = $title;
  109. return $this;
  110. }
  111. /**
  112. * Get the title of the option.
  113. *
  114. * @since 15.0.0
  115. */
  116. public function getTitle(): string {
  117. return $this->title;
  118. }
  119. /**
  120. * Set the type of the option.
  121. * $type can be ISearchOption::CHECKBOX or ISearchOption::INPUT
  122. *
  123. * @since 15.0.0
  124. */
  125. public function setType(string $type): ISearchOption {
  126. $this->type = $type;
  127. return $this;
  128. }
  129. /**
  130. * Get the type of the option.
  131. *
  132. * @since 15.0.0
  133. */
  134. public function getType(): string {
  135. return $this->type;
  136. }
  137. /**
  138. * In case of Type is INPUT, set the size of the input field.
  139. * Value can be ISearchOption::INPUT_SMALL or not defined.
  140. *
  141. * @since 15.0.0
  142. */
  143. public function setSize(string $size): ISearchOption {
  144. $this->size = $size;
  145. return $this;
  146. }
  147. /**
  148. * Get the size of the INPUT.
  149. *
  150. * @since 15.0.0
  151. */
  152. public function getSize(): string {
  153. return $this->size;
  154. }
  155. /**
  156. * In case of Type is , set the placeholder to be displayed in the input
  157. * field.
  158. *
  159. * @since 15.0.0
  160. */
  161. public function setPlaceholder(string $placeholder): ISearchOption {
  162. $this->placeholder = $placeholder;
  163. return $this;
  164. }
  165. /**
  166. * Get the placeholder.
  167. *
  168. * @since 15.0.0
  169. */
  170. public function getPlaceholder(): string {
  171. return $this->placeholder;
  172. }
  173. /**
  174. * @since 15.0.0
  175. */
  176. public function jsonSerialize(): array {
  177. return [
  178. 'name' => $this->getName(),
  179. 'title' => $this->getTitle(),
  180. 'type' => $this->getType(),
  181. 'size' => $this->getSize(),
  182. 'placeholder' => $this->getPlaceholder()
  183. ];
  184. }
  185. }