IManager.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  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, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. /**
  25. * Public interface of ownCloud for apps to use.
  26. * Contacts Class
  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 - for future use. One should always have options!
  90. * @return array an array of contacts which are arrays of key-value-pairs
  91. * @since 6.0.0
  92. */
  93. public function search($pattern, $searchProperties = array(), $options = array());
  94. /**
  95. * This function can be used to delete the contact identified by the given id
  96. *
  97. * @param object $id the unique identifier to a contact
  98. * @param string $address_book_key identifier of the address book in which the contact shall be deleted
  99. * @return bool successful or not
  100. * @since 6.0.0
  101. */
  102. public function delete($id, $address_book_key);
  103. /**
  104. * This function is used to create a new contact if 'id' is not given or not present.
  105. * Otherwise the contact will be updated by replacing the entire data set.
  106. *
  107. * @param array $properties this array if key-value-pairs defines a contact
  108. * @param string $address_book_key identifier of the address book in which the contact shall be created or updated
  109. * @return array an array representing the contact just created or updated
  110. * @since 6.0.0
  111. */
  112. public function createOrUpdate($properties, $address_book_key);
  113. /**
  114. * Check if contacts are available (e.g. contacts app enabled)
  115. *
  116. * @return bool true if enabled, false if not
  117. * @since 6.0.0
  118. */
  119. public function isEnabled();
  120. /**
  121. * Registers an address book
  122. *
  123. * @param \OCP\IAddressBook $address_book
  124. * @return void
  125. * @since 6.0.0
  126. */
  127. public function registerAddressBook(\OCP\IAddressBook $address_book);
  128. /**
  129. * Unregisters an address book
  130. *
  131. * @param \OCP\IAddressBook $address_book
  132. * @return void
  133. * @since 6.0.0
  134. */
  135. public function unregisterAddressBook(\OCP\IAddressBook $address_book);
  136. /**
  137. * In order to improve lazy loading a closure can be registered which will be called in case
  138. * address books are actually requested
  139. *
  140. * @param \Closure $callable
  141. * @return void
  142. * @since 6.0.0
  143. */
  144. public function register(\Closure $callable);
  145. /**
  146. * Return a list of the user's addressbooks display names
  147. *
  148. * @return array
  149. * @since 6.0.0
  150. * @deprecated 16.0.0 - Use `$this->getUserAddressBooks()` instead
  151. */
  152. public function getAddressBooks();
  153. /**
  154. * Return a list of the user's addressbooks
  155. *
  156. * @return IAddressBook[]
  157. * @since 16.0.0
  158. */
  159. public function getUserAddressBooks();
  160. /**
  161. * removes all registered address book instances
  162. *
  163. * @return void
  164. * @since 6.0.0
  165. */
  166. public function clear();
  167. }