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.

246 lines
4.5 KiB

3 years ago
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Julius Härtl <jus@bitgrid.net>
  8. * @author Maxence Lange <maxence@artificial-owl.com>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCP\Dashboard\Model;
  27. use JsonSerializable;
  28. /**
  29. * Interface WidgetSetting
  30. *
  31. * Each setting that can be edited by a user should be defined in a
  32. * WidgetSetting.
  33. *
  34. * When using this framework, the settings interface is generated by the
  35. * Dashboard app.
  36. *
  37. * Each WidgetSetting must be generated and declared in the WidgetTemplate
  38. * during the setup of the widget in the IDashboardWidget using addSetting().
  39. *
  40. * @see IDashboardWidget::getWidgetTemplate
  41. * @see WidgetTemplate::addSetting
  42. *
  43. * @since 15.0.0
  44. * @deprecated 20.0.0
  45. *
  46. */
  47. final class WidgetSetting implements JsonSerializable {
  48. public const TYPE_INPUT = 'input';
  49. public const TYPE_CHECKBOX = 'checkbox';
  50. /** @var string */
  51. private $name = '';
  52. /** @var string */
  53. private $title = '';
  54. /** @var string */
  55. private $type = '';
  56. /** @var string */
  57. private $placeholder = '';
  58. /** @var string */
  59. private $default = '';
  60. /**
  61. * WidgetSetting constructor.
  62. *
  63. * @since 15.0.0
  64. * @deprecated 20.0.0
  65. *
  66. * @param string $type
  67. */
  68. public function __construct(string $type = '') {
  69. $this->type = $type;
  70. }
  71. /**
  72. * Set the name of the setting (full string, no space)
  73. *
  74. * @since 15.0.0
  75. * @deprecated 20.0.0
  76. *
  77. * @param string $name
  78. *
  79. * @return WidgetSetting
  80. */
  81. public function setName(string $name): WidgetSetting {
  82. $this->name = $name;
  83. return $this;
  84. }
  85. /**
  86. * Get the name of the setting
  87. *
  88. * @since 15.0.0
  89. * @deprecated 20.0.0
  90. *
  91. * @return string
  92. */
  93. public function getName(): string {
  94. return $this->name;
  95. }
  96. /**
  97. * Set the title/display name of the setting.
  98. *
  99. * @since 15.0.0
  100. * @deprecated 20.0.0
  101. *
  102. * @param string $title
  103. *
  104. * @return WidgetSetting
  105. */
  106. public function setTitle(string $title): WidgetSetting {
  107. $this->title = $title;
  108. return $this;
  109. }
  110. /**
  111. * Get the title of the setting
  112. *
  113. * @since 15.0.0
  114. * @deprecated 20.0.0
  115. *
  116. * @return string
  117. */
  118. public function getTitle(): string {
  119. return $this->title;
  120. }
  121. /**
  122. * Set the type of the setting (input, checkbox, ...)
  123. *
  124. * @since 15.0.0
  125. * @deprecated 20.0.0
  126. *
  127. * @param string $type
  128. *
  129. * @return WidgetSetting
  130. */
  131. public function setType(string $type): WidgetSetting {
  132. $this->type = $type;
  133. return $this;
  134. }
  135. /**
  136. * Get the type of the setting.
  137. *
  138. * @since 15.0.0
  139. * @deprecated 20.0.0
  140. *
  141. * @return string
  142. */
  143. public function getType(): string {
  144. return $this->type;
  145. }
  146. /**
  147. * Set the placeholder (in case of type=input)
  148. *
  149. * @since 15.0.0
  150. * @deprecated 20.0.0
  151. *
  152. * @param string $text
  153. *
  154. * @return WidgetSetting
  155. */
  156. public function setPlaceholder(string $text): WidgetSetting {
  157. $this->placeholder = $text;
  158. return $this;
  159. }
  160. /**
  161. * Get the placeholder.
  162. *
  163. * @since 15.0.0
  164. * @deprecated 20.0.0
  165. *
  166. * @return string
  167. */
  168. public function getPlaceholder(): string {
  169. return $this->placeholder;
  170. }
  171. /**
  172. * Set the default value of the setting.
  173. *
  174. * @since 15.0.0
  175. * @deprecated 20.0.0
  176. *
  177. * @param string $value
  178. *
  179. * @return WidgetSetting
  180. */
  181. public function setDefault(string $value): WidgetSetting {
  182. $this->default = $value;
  183. return $this;
  184. }
  185. /**
  186. * Get the default value.
  187. *
  188. * @since 15.0.0
  189. * @deprecated 20.0.0
  190. *
  191. * @return string
  192. */
  193. public function getDefault(): string {
  194. return $this->default;
  195. }
  196. /**
  197. * @since 15.0.0
  198. * @deprecated 20.0.0
  199. *
  200. * @return array
  201. */
  202. public function jsonSerialize() {
  203. return [
  204. 'name' => $this->getName(),
  205. 'title' => $this->getTitle(),
  206. 'type' => $this->getTitle(),
  207. 'default' => $this->getDefault(),
  208. 'placeholder' => $this->getPlaceholder()
  209. ];
  210. }
  211. }