1
0

Card.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Georg Ehrke <oc.list@georgehrke.com>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\ContactsInteraction;
  27. use OCA\ContactsInteraction\Db\RecentContact;
  28. use Sabre\CardDAV\ICard;
  29. use Sabre\DAV\Exception\NotImplemented;
  30. use Sabre\DAVACL\ACLTrait;
  31. use Sabre\DAVACL\IACL;
  32. class Card implements ICard, IACL {
  33. use ACLTrait;
  34. public function __construct(
  35. private RecentContact $contact,
  36. private string $principal,
  37. private array $acls,
  38. ) {
  39. }
  40. /**
  41. * @inheritDoc
  42. */
  43. public function getOwner(): ?string {
  44. return $this->principal;
  45. }
  46. /**
  47. * @inheritDoc
  48. */
  49. public function getACL(): array {
  50. return $this->acls;
  51. }
  52. /**
  53. * @inheritDoc
  54. */
  55. public function setAcls(array $acls): void {
  56. throw new NotImplemented();
  57. }
  58. /**
  59. * @inheritDoc
  60. */
  61. public function put($data): ?string {
  62. throw new NotImplemented();
  63. }
  64. /**
  65. * @inheritDoc
  66. */
  67. public function get(): string {
  68. return $this->contact->getCard();
  69. }
  70. /**
  71. * @inheritDoc
  72. */
  73. public function getContentType(): ?string {
  74. return 'text/vcard; charset=utf-8';
  75. }
  76. /**
  77. * @inheritDoc
  78. */
  79. public function getETag(): ?string {
  80. return '"' . md5((string) $this->getLastModified()) . '"';
  81. }
  82. /**
  83. * @inheritDoc
  84. */
  85. public function getSize(): int {
  86. throw new NotImplemented();
  87. }
  88. /**
  89. * @inheritDoc
  90. */
  91. public function delete(): void {
  92. throw new NotImplemented();
  93. }
  94. /**
  95. * @inheritDoc
  96. */
  97. public function getName(): string {
  98. return (string) $this->contact->getId();
  99. }
  100. /**
  101. * @inheritDoc
  102. */
  103. public function setName($name): void {
  104. throw new NotImplemented();
  105. }
  106. /**
  107. * @inheritDoc
  108. */
  109. public function getLastModified(): ?int {
  110. return $this->contact->getLastContact();
  111. }
  112. }