1
0

Card.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. private RecentContact $contact;
  35. private string $principal;
  36. private array $acls;
  37. public function __construct(RecentContact $contact, string $principal, array $acls) {
  38. $this->contact = $contact;
  39. $this->principal = $principal;
  40. $this->acls = $acls;
  41. }
  42. /**
  43. * @inheritDoc
  44. */
  45. public function getOwner(): ?string {
  46. return $this->principal;
  47. }
  48. /**
  49. * @inheritDoc
  50. */
  51. public function getACL(): array {
  52. return $this->acls;
  53. }
  54. /**
  55. * @inheritDoc
  56. */
  57. public function setAcls(array $acls): void {
  58. throw new NotImplemented();
  59. }
  60. /**
  61. * @inheritDoc
  62. */
  63. public function put($data): ?string {
  64. throw new NotImplemented();
  65. }
  66. /**
  67. * @inheritDoc
  68. */
  69. public function get() {
  70. return $this->contact->getCard();
  71. }
  72. /**
  73. * @inheritDoc
  74. */
  75. public function getContentType(): ?string {
  76. return 'text/vcard; charset=utf-8';
  77. }
  78. /**
  79. * @inheritDoc
  80. */
  81. public function getETag(): ?string {
  82. return '"' . md5((string) $this->getLastModified()) . '"';
  83. }
  84. /**
  85. * @inheritDoc
  86. */
  87. public function getSize(): int {
  88. throw new NotImplemented();
  89. }
  90. /**
  91. * @inheritDoc
  92. */
  93. public function delete(): void {
  94. throw new NotImplemented();
  95. }
  96. /**
  97. * @inheritDoc
  98. */
  99. public function getName(): string {
  100. return (string) $this->contact->getId();
  101. }
  102. /**
  103. * @inheritDoc
  104. */
  105. public function setName($name): void {
  106. throw new NotImplemented();
  107. }
  108. /**
  109. * @inheritDoc
  110. */
  111. public function getLastModified(): ?int {
  112. return $this->contact->getLastContact();
  113. }
  114. }