IManager.php 5.2 KB

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