1
0

RichReminder.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\FilesReminders\Model;
  8. use DateTimeInterface;
  9. use JsonSerializable;
  10. use OCA\FilesReminders\Db\Reminder;
  11. use OCA\FilesReminders\Exception\NodeNotFoundException;
  12. use OCP\Files\IRootFolder;
  13. use OCP\Files\Node;
  14. class RichReminder extends Reminder implements JsonSerializable {
  15. public function __construct(
  16. private Reminder $reminder,
  17. private IRootFolder $root,
  18. ) {
  19. parent::__construct();
  20. }
  21. /**
  22. * @throws NodeNotFoundException
  23. */
  24. public function getNode(): Node {
  25. $node = $this->root->getUserFolder($this->getUserId())->getFirstNodeById($this->getFileId());
  26. if (!$node) {
  27. throw new NodeNotFoundException();
  28. }
  29. return $node;
  30. }
  31. protected function getter(string $name): mixed {
  32. return $this->reminder->getter($name);
  33. }
  34. public function __call(string $methodName, array $args) {
  35. return $this->reminder->__call($methodName, $args);
  36. }
  37. public function jsonSerialize(): array {
  38. return [
  39. 'userId' => $this->getUserId(),
  40. 'fileId' => $this->getFileId(),
  41. 'path' => $this->getNode()->getPath(),
  42. 'dueDate' => $this->getDueDate()->format(DateTimeInterface::ATOM), // ISO 8601
  43. 'updatedAt' => $this->getUpdatedAt()->format(DateTimeInterface::ATOM), // ISO 8601
  44. 'createdAt' => $this->getCreatedAt()->format(DateTimeInterface::ATOM), // ISO 8601
  45. 'notified' => $this->getNotified(),
  46. ];
  47. }
  48. }