Card.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
  5. *
  6. * @author 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
  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. namespace OCA\ContactsInteraction;
  24. use OCA\ContactsInteraction\Db\RecentContact;
  25. use Sabre\CardDAV\ICard;
  26. use Sabre\DAV\Exception\NotImplemented;
  27. use Sabre\DAVACL\ACLTrait;
  28. use Sabre\DAVACL\IACL;
  29. class Card implements ICard, IACL {
  30. use ACLTrait;
  31. /** @var RecentContact */
  32. private $contact;
  33. /** @var string */
  34. private $principal;
  35. /** @var array */
  36. private $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. $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. }