1
0

VersionEntity.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2022 Louis Chmn <louis@chmn.me>
  5. *
  6. * @author Louis Chmn <louis@chmn.me>
  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 OCA\Files_Versions\Db;
  25. use JsonSerializable;
  26. use OCP\AppFramework\Db\Entity;
  27. use OCP\DB\Types;
  28. /**
  29. * @method int getFileId()
  30. * @method void setFileId(int $fileId)
  31. * @method int getTimestamp()
  32. * @method void setTimestamp(int $timestamp)
  33. * @method int getSize()
  34. * @method void setSize(int $size)
  35. * @method int getMimetype()
  36. * @method void setMimetype(int $mimetype)
  37. * @method array|null getMetadata()
  38. * @method void setMetadata(array $metadata)
  39. */
  40. class VersionEntity extends Entity implements JsonSerializable {
  41. protected ?int $fileId = null;
  42. protected ?int $timestamp = null;
  43. protected ?int $size = null;
  44. protected ?int $mimetype = null;
  45. protected ?array $metadata = null;
  46. public function __construct() {
  47. $this->addType('id', Types::INTEGER);
  48. $this->addType('file_id', Types::INTEGER);
  49. $this->addType('timestamp', Types::INTEGER);
  50. $this->addType('size', Types::INTEGER);
  51. $this->addType('mimetype', Types::INTEGER);
  52. $this->addType('metadata', Types::JSON);
  53. }
  54. public function jsonSerialize(): array {
  55. return [
  56. 'id' => $this->id,
  57. 'file_id' => $this->fileId,
  58. 'timestamp' => $this->timestamp,
  59. 'size' => $this->size,
  60. 'mimetype' => $this->mimetype,
  61. 'metadata' => $this->metadata,
  62. ];
  63. }
  64. public function getLabel(): string {
  65. return $this->metadata['label'] ?? '';
  66. }
  67. public function setLabel(string $label): void {
  68. $this->metadata['label'] = $label;
  69. $this->markFieldUpdated('metadata');
  70. }
  71. }