You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IManager.php 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Anna Larch <anna@nextcloud.com>
  6. * @author Arne Hamann <kontakt+github@arne.email>
  7. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  8. * @author John Molakvoæ <skjnldsv@protonmail.com>
  9. * @author Julius Härtl <jus@bitgrid.net>
  10. * @author Morris Jobke <hey@morrisjobke.de>
  11. * @author Roeland Jago Douma <roeland@famdouma.nl>
  12. * @author Thomas Müller <thomas.mueller@tmit.eu>
  13. *
  14. * @license AGPL-3.0
  15. *
  16. * This code is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License, version 3,
  18. * as published by the Free Software Foundation.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License, version 3,
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>
  27. *
  28. */
  29. // use OCP namespace for all classes that are considered public.
  30. // This means that they should be used by apps instead of the internal ownCloud classes
  31. namespace OCP\Contacts;
  32. /**
  33. * This class provides access to the contacts app. Use this class exclusively if you want to access contacts.
  34. *
  35. * Contacts in general will be expressed as an array of key-value-pairs.
  36. * The keys will match the property names defined in https://tools.ietf.org/html/rfc2426#section-1
  37. *
  38. * Proposed workflow for working with contacts:
  39. * - search for the contacts
  40. * - manipulate the results array
  41. * - createOrUpdate will save the given contacts overwriting the existing data
  42. *
  43. * For updating it is mandatory to keep the id.
  44. * Without an id a new contact will be created.
  45. *
  46. * @since 6.0.0
  47. */
  48. interface IManager {
  49. /**
  50. * This function is used to search and find contacts within the users address books.
  51. * In case $pattern is empty all contacts will be returned.
  52. *
  53. * Example:
  54. * Following function shows how to search for contacts for the name and the email address.
  55. *
  56. * public static function getMatchingRecipient($term) {
  57. * $cm = \OC::$server->getContactsManager();
  58. * // The API is not active -> nothing to do
  59. * if (!$cm->isEnabled()) {
  60. * return array();
  61. * }
  62. *
  63. * $result = $cm->search($term, array('FN', 'EMAIL'));
  64. * $receivers = array();
  65. * foreach ($result as $r) {
  66. * $id = $r['id'];
  67. * $fn = $r['FN'];
  68. * $email = $r['EMAIL'];
  69. * if (!is_array($email)) {
  70. * $email = array($email);
  71. * }
  72. *
  73. * // loop through all email addresses of this contact
  74. * foreach ($email as $e) {
  75. * $displayName = $fn . " <$e>";
  76. * $receivers[] = array(
  77. * 'id' => $id,
  78. * 'label' => $displayName,
  79. * 'value' => $displayName);
  80. * }
  81. * }
  82. *
  83. * return $receivers;
  84. * }
  85. *
  86. *
  87. * @param string $pattern which should match within the $searchProperties
  88. * @param array $searchProperties defines the properties within the query pattern should match
  89. * @param array $options = array() to define the search behavior
  90. * - 'escape_like_param' - If set to false wildcards _ and % are not escaped
  91. * - 'limit' - Set a numeric limit for the search results
  92. * - 'offset' - Set the offset for the limited search results
  93. * - 'enumeration' - (since 23.0.0) Whether user enumeration on system address book is allowed
  94. * - 'fullmatch' - (since 23.0.0) Whether matching on full detail in system addresss book is allowed
  95. * - 'strict_search' - (since 23.0.0) Whether the search pattern is full string or partial search
  96. * @psalm-param array{escape_like_param?: bool, limit?: int, offset?: int, enumeration?: bool, fullmatch?: bool, strict_search?: bool} $options
  97. * @return array an array of contacts which are arrays of key-value-pairs
  98. * @since 6.0.0
  99. */
  100. public function search($pattern, $searchProperties = [], $options = []);
  101. /**
  102. * This function can be used to delete the contact identified by the given id
  103. *
  104. * @param int $id the unique identifier to a contact
  105. * @param string $address_book_key identifier of the address book in which the contact shall be deleted
  106. * @return bool successful or not
  107. * @since 6.0.0
  108. */
  109. public function delete($id, $address_book_key);
  110. /**
  111. * This function is used to create a new contact if 'id' is not given or not present.
  112. * Otherwise the contact will be updated by replacing the entire data set.
  113. *
  114. * @param array $properties this array if key-value-pairs defines a contact
  115. * @param string $address_book_key identifier of the address book in which the contact shall be created or updated
  116. * @return array an array representing the contact just created or updated
  117. * @since 6.0.0
  118. */
  119. public function createOrUpdate($properties, $address_book_key);
  120. /**
  121. * Check if contacts are available (e.g. contacts app enabled)
  122. *
  123. * @return bool true if enabled, false if not
  124. * @since 6.0.0
  125. */
  126. public function isEnabled();
  127. /**
  128. * Registers an address book
  129. *
  130. * @param \OCP\IAddressBook $address_book
  131. * @return void
  132. * @since 6.0.0
  133. */
  134. public function registerAddressBook(\OCP\IAddressBook $address_book);
  135. /**
  136. * Unregisters an address book
  137. *
  138. * @param \OCP\IAddressBook $address_book
  139. * @return void
  140. * @since 6.0.0
  141. */
  142. public function unregisterAddressBook(\OCP\IAddressBook $address_book);
  143. /**
  144. * In order to improve lazy loading a closure can be registered which will be called in case
  145. * address books are actually requested
  146. *
  147. * @param \Closure $callable
  148. * @return void
  149. * @since 6.0.0
  150. */
  151. public function register(\Closure $callable);
  152. /**
  153. * Return a list of the user's addressbooks display names
  154. *
  155. * @return array
  156. * @since 6.0.0
  157. * @deprecated 16.0.0 - Use `$this->getUserAddressBooks()` instead
  158. */
  159. public function getAddressBooks();
  160. /**
  161. * Return a list of the user's addressbooks
  162. *
  163. * @return \OCP\IAddressBook[]
  164. * @since 16.0.0
  165. */
  166. public function getUserAddressBooks();
  167. /**
  168. * removes all registered address book instances
  169. *
  170. * @return void
  171. * @since 6.0.0
  172. */
  173. public function clear();
  174. }