1
0

IManager.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. // use OCP namespace for all classes that are considered public.
  8. // This means that they should be used by apps instead of the internal Nextcloud classes
  9. namespace OCP\Contacts;
  10. /**
  11. * This class provides access to the contacts app. Use this class exclusively if you want to access contacts.
  12. *
  13. * Contacts in general will be expressed as an array of key-value-pairs.
  14. * The keys will match the property names defined in https://tools.ietf.org/html/rfc2426#section-1
  15. *
  16. * Proposed workflow for working with contacts:
  17. * - search for the contacts
  18. * - manipulate the results array
  19. * - createOrUpdate will save the given contacts overwriting the existing data
  20. *
  21. * For updating it is mandatory to keep the id.
  22. * Without an id a new contact will be created.
  23. *
  24. * @since 6.0.0
  25. */
  26. interface IManager {
  27. /**
  28. * This function is used to search and find contacts within the users address books.
  29. * In case $pattern is empty all contacts will be returned.
  30. *
  31. * Example:
  32. * Following function shows how to search for contacts for the name and the email address.
  33. *
  34. * public static function getMatchingRecipient($term) {
  35. * $cm = \OCP\Server::get(\OCP\Contacts\IManager::class);
  36. * // The API is not active -> nothing to do
  37. * if (!$cm->isEnabled()) {
  38. * return array();
  39. * }
  40. *
  41. * $result = $cm->search($term, array('FN', 'EMAIL'));
  42. * $receivers = array();
  43. * foreach ($result as $r) {
  44. * $id = $r['id'];
  45. * $fn = $r['FN'];
  46. * $email = $r['EMAIL'];
  47. * if (!is_array($email)) {
  48. * $email = array($email);
  49. * }
  50. *
  51. * // loop through all email addresses of this contact
  52. * foreach ($email as $e) {
  53. * $displayName = $fn . " <$e>";
  54. * $receivers[] = array(
  55. * 'id' => $id,
  56. * 'label' => $displayName,
  57. * 'value' => $displayName);
  58. * }
  59. * }
  60. *
  61. * return $receivers;
  62. * }
  63. *
  64. *
  65. * @param string $pattern which should match within the $searchProperties
  66. * @param array $searchProperties defines the properties within the query pattern should match
  67. * @param array $options = array() to define the search behavior
  68. * - 'types' boolean (since 15.0.0) If set to true, fields that come with a TYPE property will be an array
  69. * example: ['id' => 5, 'FN' => 'Thomas Tanghus', 'EMAIL' => ['type => 'HOME', 'value' => 'g@h.i']]
  70. * - 'escape_like_param' - If set to false wildcards _ and % are not escaped
  71. * - 'limit' - Set a numeric limit for the search results
  72. * - 'offset' - Set the offset for the limited search results
  73. * - 'enumeration' - (since 23.0.0) Whether user enumeration on system address book is allowed
  74. * - 'fullmatch' - (since 23.0.0) Whether matching on full detail in system address book is allowed
  75. * - 'strict_search' - (since 23.0.0) Whether the search pattern is full string or partial search
  76. * @psalm-param array{types?: bool, escape_like_param?: bool, limit?: int, offset?: int, enumeration?: bool, fullmatch?: bool, strict_search?: bool} $options
  77. * @return array an array of contacts which are arrays of key-value-pairs
  78. * @since 6.0.0
  79. */
  80. public function search($pattern, $searchProperties = [], $options = []);
  81. /**
  82. * This function can be used to delete the contact identified by the given id
  83. *
  84. * @param int $id the unique identifier to a contact
  85. * @param string $addressBookKey identifier of the address book in which the contact shall be deleted
  86. * @return bool successful or not
  87. * @since 6.0.0
  88. */
  89. public function delete($id, $addressBookKey);
  90. /**
  91. * This function is used to create a new contact if 'id' is not given or not present.
  92. * Otherwise the contact will be updated by replacing the entire data set.
  93. *
  94. * @param array $properties this array if key-value-pairs defines a contact
  95. * @param string $addressBookKey identifier of the address book in which the contact shall be created or updated
  96. * @return ?array an array representing the contact just created or updated
  97. * @since 6.0.0
  98. */
  99. public function createOrUpdate($properties, $addressBookKey);
  100. /**
  101. * Check if contacts are available (e.g. contacts app enabled)
  102. *
  103. * @return bool true if enabled, false if not
  104. * @since 6.0.0
  105. */
  106. public function isEnabled();
  107. /**
  108. * Registers an address book
  109. *
  110. * @return void
  111. * @since 6.0.0
  112. */
  113. public function registerAddressBook(\OCP\IAddressBook $addressBook);
  114. /**
  115. * Unregisters an address book
  116. *
  117. * @param \OCP\IAddressBook $addressBook
  118. * @return void
  119. * @since 6.0.0
  120. */
  121. public function unregisterAddressBook(\OCP\IAddressBook $addressBook);
  122. /**
  123. * In order to improve lazy loading a closure can be registered which will be called in case
  124. * address books are actually requested
  125. *
  126. * @param \Closure $callable
  127. * @return void
  128. * @since 6.0.0
  129. */
  130. public function register(\Closure $callable);
  131. /**
  132. * Return a list of the user's addressbooks
  133. *
  134. * @return \OCP\IAddressBook[]
  135. * @since 16.0.0
  136. */
  137. public function getUserAddressBooks();
  138. /**
  139. * removes all registered address book instances
  140. *
  141. * @return void
  142. * @since 6.0.0
  143. */
  144. public function clear();
  145. }