1
0

Template.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2021 Julius Härtl <jus@bitgrid.net>
  5. *
  6. * @author Julius Härtl <jus@bitgrid.net>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCP\Files\Template;
  25. use OCP\Files\File;
  26. /**
  27. * @since 21.0.0
  28. */
  29. final class Template implements \JsonSerializable {
  30. /** @var string */
  31. private $templateType;
  32. /** @var string */
  33. private $templateId;
  34. /** @var File */
  35. private $file;
  36. /** @var bool */
  37. private $hasPreview = false;
  38. /** @var string|null */
  39. private $previewUrl = null;
  40. /**
  41. * @since 21.0.0
  42. */
  43. public function __construct(string $templateType, string $templateId, File $file) {
  44. $this->templateType = $templateType;
  45. $this->templateId = $templateId;
  46. $this->file = $file;
  47. }
  48. /**
  49. * @since 21.0.0
  50. */
  51. public function setCustomPreviewUrl(string $previewUrl): void {
  52. $this->previewUrl = $previewUrl;
  53. }
  54. /**
  55. * @since 21.0.0
  56. */
  57. public function setHasPreview(bool $hasPreview): void {
  58. $this->hasPreview = $hasPreview;
  59. }
  60. /**
  61. * @since 21.0.0
  62. */
  63. public function jsonSerialize(): array {
  64. return [
  65. 'templateType' => $this->templateType,
  66. 'templateId' => $this->templateId,
  67. 'basename' => $this->file->getName(),
  68. 'etag' => $this->file->getEtag(),
  69. 'fileid' => $this->file->getId(),
  70. 'filename' => $this->templateId,
  71. 'lastmod' => $this->file->getMTime(),
  72. 'mime' => $this->file->getMimetype(),
  73. 'size' => $this->file->getSize(),
  74. 'type' => $this->file->getType(),
  75. 'hasPreview' => $this->hasPreview,
  76. 'previewUrl' => $this->previewUrl
  77. ];
  78. }
  79. }