imanager.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. /**
  3. * @author Bart Visscher <bartv@thisnet.nl>
  4. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Robin McCorkell <rmccorkell@karoshi.org.uk>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. *
  9. * @copyright Copyright (c) 2015, ownCloud, Inc.
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. /**
  26. * Public interface of ownCloud for apps to use.
  27. * Contacts Class
  28. *
  29. */
  30. // use OCP namespace for all classes that are considered public.
  31. // This means that they should be used by apps instead of the internal ownCloud classes
  32. namespace OCP\Contacts {
  33. /**
  34. * This class provides access to the contacts app. Use this class exclusively if you want to access contacts.
  35. *
  36. * Contacts in general will be expressed as an array of key-value-pairs.
  37. * The keys will match the property names defined in https://tools.ietf.org/html/rfc2426#section-1
  38. *
  39. * Proposed workflow for working with contacts:
  40. * - search for the contacts
  41. * - manipulate the results array
  42. * - createOrUpdate will save the given contacts overwriting the existing data
  43. *
  44. * For updating it is mandatory to keep the id.
  45. * Without an id a new contact will be created.
  46. *
  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. */
  92. function search($pattern, $searchProperties = array(), $options = array());
  93. /**
  94. * This function can be used to delete the contact identified by the given id
  95. *
  96. * @param object $id the unique identifier to a contact
  97. * @param string $address_book_key identifier of the address book in which the contact shall be deleted
  98. * @return bool successful or not
  99. */
  100. function delete($id, $address_book_key);
  101. /**
  102. * This function is used to create a new contact if 'id' is not given or not present.
  103. * Otherwise the contact will be updated by replacing the entire data set.
  104. *
  105. * @param array $properties this array if key-value-pairs defines a contact
  106. * @param string $address_book_key identifier of the address book in which the contact shall be created or updated
  107. * @return array an array representing the contact just created or updated
  108. */
  109. function createOrUpdate($properties, $address_book_key);
  110. /**
  111. * Check if contacts are available (e.g. contacts app enabled)
  112. *
  113. * @return bool true if enabled, false if not
  114. */
  115. function isEnabled();
  116. /**
  117. * Registers an address book
  118. *
  119. * @param \OCP\IAddressBook $address_book
  120. * @return void
  121. */
  122. function registerAddressBook(\OCP\IAddressBook $address_book);
  123. /**
  124. * Unregisters an address book
  125. *
  126. * @param \OCP\IAddressBook $address_book
  127. * @return void
  128. */
  129. function unregisterAddressBook(\OCP\IAddressBook $address_book);
  130. /**
  131. * In order to improve lazy loading a closure can be registered which will be called in case
  132. * address books are actually requested
  133. *
  134. * @param \Closure $callable
  135. * @return void
  136. */
  137. function register(\Closure $callable);
  138. /**
  139. * @return array
  140. */
  141. function getAddressBooks();
  142. /**
  143. * removes all registered address book instances
  144. * @return void
  145. */
  146. function clear();
  147. }
  148. }