1
0

Template.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\Files\Template;
  8. use OCP\Files\File;
  9. /**
  10. * @since 21.0.0
  11. */
  12. final class Template implements \JsonSerializable {
  13. /** @var string */
  14. private $templateType;
  15. /** @var string */
  16. private $templateId;
  17. /** @var File */
  18. private $file;
  19. /** @var bool */
  20. private $hasPreview = false;
  21. /** @var string|null */
  22. private $previewUrl = null;
  23. /** @var array */
  24. private $fields = [];
  25. /**
  26. * @since 21.0.0
  27. */
  28. public function __construct(string $templateType, string $templateId, File $file) {
  29. $this->templateType = $templateType;
  30. $this->templateId = $templateId;
  31. $this->file = $file;
  32. }
  33. /**
  34. * @since 21.0.0
  35. */
  36. public function setCustomPreviewUrl(string $previewUrl): void {
  37. $this->previewUrl = $previewUrl;
  38. }
  39. /**
  40. * @since 21.0.0
  41. */
  42. public function setHasPreview(bool $hasPreview): void {
  43. $this->hasPreview = $hasPreview;
  44. }
  45. /**
  46. * @since 30.0.0
  47. */
  48. public function setFields(array $fields): void {
  49. $this->fields = $fields;
  50. }
  51. /**
  52. * @since 21.0.0
  53. */
  54. public function jsonSerialize(): array {
  55. return [
  56. 'templateType' => $this->templateType,
  57. 'templateId' => $this->templateId,
  58. 'basename' => $this->file->getName(),
  59. 'etag' => $this->file->getEtag(),
  60. 'fileid' => $this->file->getId(),
  61. 'filename' => $this->templateId,
  62. 'lastmod' => $this->file->getMTime(),
  63. 'mime' => $this->file->getMimetype(),
  64. 'size' => $this->file->getSize(),
  65. 'type' => $this->file->getType(),
  66. 'hasPreview' => $this->hasPreview,
  67. 'previewUrl' => $this->previewUrl,
  68. 'fields' => $this->fields
  69. ];
  70. }
  71. }