Template.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. /**
  24. * @since 21.0.0
  25. */
  26. public function __construct(string $templateType, string $templateId, File $file) {
  27. $this->templateType = $templateType;
  28. $this->templateId = $templateId;
  29. $this->file = $file;
  30. }
  31. /**
  32. * @since 21.0.0
  33. */
  34. public function setCustomPreviewUrl(string $previewUrl): void {
  35. $this->previewUrl = $previewUrl;
  36. }
  37. /**
  38. * @since 21.0.0
  39. */
  40. public function setHasPreview(bool $hasPreview): void {
  41. $this->hasPreview = $hasPreview;
  42. }
  43. /**
  44. * @since 21.0.0
  45. */
  46. public function jsonSerialize(): array {
  47. return [
  48. 'templateType' => $this->templateType,
  49. 'templateId' => $this->templateId,
  50. 'basename' => $this->file->getName(),
  51. 'etag' => $this->file->getEtag(),
  52. 'fileid' => $this->file->getId(),
  53. 'filename' => $this->templateId,
  54. 'lastmod' => $this->file->getMTime(),
  55. 'mime' => $this->file->getMimetype(),
  56. 'size' => $this->file->getSize(),
  57. 'type' => $this->file->getType(),
  58. 'hasPreview' => $this->hasPreview,
  59. 'previewUrl' => $this->previewUrl
  60. ];
  61. }
  62. }