Card.php 2.7 KB

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