1
0

IManager.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. * - 'types' boolean (since 15.0.0) If set to true, fields that come with a TYPE property will be an array
  91. * example: ['id' => 5, 'FN' => 'Thomas Tanghus', 'EMAIL' => ['type => 'HOME', 'value' => 'g@h.i']]
  92. * - 'escape_like_param' - If set to false wildcards _ and % are not escaped
  93. * - 'limit' - Set a numeric limit for the search results
  94. * - 'offset' - Set the offset for the limited search results
  95. * - 'enumeration' - (since 23.0.0) Whether user enumeration on system address book is allowed
  96. * - 'fullmatch' - (since 23.0.0) Whether matching on full detail in system address book is allowed
  97. * - 'strict_search' - (since 23.0.0) Whether the search pattern is full string or partial search
  98. * @psalm-param array{types?: bool, escape_like_param?: bool, limit?: int, offset?: int, enumeration?: bool, fullmatch?: bool, strict_search?: bool} $options
  99. * @return array an array of contacts which are arrays of key-value-pairs
  100. * @since 6.0.0
  101. */
  102. public function search($pattern, $searchProperties = [], $options = []);
  103. /**
  104. * This function can be used to delete the contact identified by the given id
  105. *
  106. * @param int $id the unique identifier to a contact
  107. * @param string $address_book_key identifier of the address book in which the contact shall be deleted
  108. * @return bool successful or not
  109. * @since 6.0.0
  110. */
  111. public function delete($id, $address_book_key);
  112. /**
  113. * This function is used to create a new contact if 'id' is not given or not present.
  114. * Otherwise the contact will be updated by replacing the entire data set.
  115. *
  116. * @param array $properties this array if key-value-pairs defines a contact
  117. * @param string $address_book_key identifier of the address book in which the contact shall be created or updated
  118. * @return array an array representing the contact just created or updated
  119. * @since 6.0.0
  120. */
  121. public function createOrUpdate($properties, $address_book_key);
  122. /**
  123. * Check if contacts are available (e.g. contacts app enabled)
  124. *
  125. * @return bool true if enabled, false if not
  126. * @since 6.0.0
  127. */
  128. public function isEnabled();
  129. /**
  130. * Registers an address book
  131. *
  132. * @param \OCP\IAddressBook $address_book
  133. * @return void
  134. * @since 6.0.0
  135. */
  136. public function registerAddressBook(\OCP\IAddressBook $address_book);
  137. /**
  138. * Unregisters an address book
  139. *
  140. * @param \OCP\IAddressBook $address_book
  141. * @return void
  142. * @since 6.0.0
  143. */
  144. public function unregisterAddressBook(\OCP\IAddressBook $address_book);
  145. /**
  146. * In order to improve lazy loading a closure can be registered which will be called in case
  147. * address books are actually requested
  148. *
  149. * @param \Closure $callable
  150. * @return void
  151. * @since 6.0.0
  152. */
  153. public function register(\Closure $callable);
  154. /**
  155. * Return a list of the user's addressbooks
  156. *
  157. * @return \OCP\IAddressBook[]
  158. * @since 16.0.0
  159. */
  160. public function getUserAddressBooks();
  161. /**
  162. * removes all registered address book instances
  163. *
  164. * @return void
  165. * @since 6.0.0
  166. */
  167. public function clear();
  168. }