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.

188 lines
5.7 KiB

3 years ago
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arne Hamann <kontakt+github@arne.email>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  8. * @author Julius Härtl <jus@bitgrid.net>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. * @author Roeland Jago Douma <roeland@famdouma.nl>
  11. * @author Thomas Müller <thomas.mueller@tmit.eu>
  12. *
  13. * @license AGPL-3.0
  14. *
  15. * This code is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU Affero General Public License, version 3,
  17. * as published by the Free Software Foundation.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Affero General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Affero General Public License, version 3,
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>
  26. *
  27. */
  28. /**
  29. * Public interface of ownCloud for apps to use.
  30. * Contacts Class
  31. *
  32. */
  33. // use OCP namespace for all classes that are considered public.
  34. // This means that they should be used by apps instead of the internal ownCloud classes
  35. namespace OCP\Contacts;
  36. /**
  37. * This class provides access to the contacts app. Use this class exclusively if you want to access contacts.
  38. *
  39. * Contacts in general will be expressed as an array of key-value-pairs.
  40. * The keys will match the property names defined in https://tools.ietf.org/html/rfc2426#section-1
  41. *
  42. * Proposed workflow for working with contacts:
  43. * - search for the contacts
  44. * - manipulate the results array
  45. * - createOrUpdate will save the given contacts overwriting the existing data
  46. *
  47. * For updating it is mandatory to keep the id.
  48. * Without an id a new contact will be created.
  49. *
  50. * @since 6.0.0
  51. */
  52. interface IManager {
  53. /**
  54. * This function is used to search and find contacts within the users address books.
  55. * In case $pattern is empty all contacts will be returned.
  56. *
  57. * Example:
  58. * Following function shows how to search for contacts for the name and the email address.
  59. *
  60. * public static function getMatchingRecipient($term) {
  61. * $cm = \OC::$server->getContactsManager();
  62. * // The API is not active -> nothing to do
  63. * if (!$cm->isEnabled()) {
  64. * return array();
  65. * }
  66. *
  67. * $result = $cm->search($term, array('FN', 'EMAIL'));
  68. * $receivers = array();
  69. * foreach ($result as $r) {
  70. * $id = $r['id'];
  71. * $fn = $r['FN'];
  72. * $email = $r['EMAIL'];
  73. * if (!is_array($email)) {
  74. * $email = array($email);
  75. * }
  76. *
  77. * // loop through all email addresses of this contact
  78. * foreach ($email as $e) {
  79. * $displayName = $fn . " <$e>";
  80. * $receivers[] = array(
  81. * 'id' => $id,
  82. * 'label' => $displayName,
  83. * 'value' => $displayName);
  84. * }
  85. * }
  86. *
  87. * return $receivers;
  88. * }
  89. *
  90. *
  91. * @param string $pattern which should match within the $searchProperties
  92. * @param array $searchProperties defines the properties within the query pattern should match
  93. * @param array $options = array() to define the search behavior
  94. * - 'escape_like_param' - If set to false wildcards _ and % are not escaped
  95. * - 'limit' - Set a numeric limit for the search results
  96. * - 'offset' - Set the offset for the limited search results
  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 object $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 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. }