contacts.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. /**
  3. * @author Bart Visscher <bartv@thisnet.nl>
  4. * @author Morris Jobke <hey@morrisjobke.de>
  5. * @author Robin McCorkell <robin@mccorkell.me.uk>
  6. * @author Thomas Müller <thomas.mueller@tmit.eu>
  7. *
  8. * @copyright Copyright (c) 2016, ownCloud, Inc.
  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 {
  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. * @deprecated 8.1.0 use methods of \OCP\Contacts\IManager - \OC::$server->getContactsManager();
  47. * @since 5.0.0
  48. */
  49. class Contacts {
  50. /**
  51. * This function is used to search and find contacts within the users address books.
  52. * In case $pattern is empty all contacts will be returned.
  53. *
  54. * Example:
  55. * Following function shows how to search for contacts for the name and the email address.
  56. *
  57. * public static function getMatchingRecipient($term) {
  58. * // The API is not active -> nothing to do
  59. * if (!\OCP\Contacts::isEnabled()) {
  60. * return array();
  61. * }
  62. *
  63. * $result = \OCP\Contacts::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. * @deprecated 8.1.0 use search() of \OCP\Contacts\IManager - \OC::$server->getContactsManager();
  92. * @since 5.0.0
  93. */
  94. public static function search($pattern, $searchProperties = array(), $options = array()) {
  95. $cm = \OC::$server->getContactsManager();
  96. return $cm->search($pattern, $searchProperties, $options);
  97. }
  98. /**
  99. * This function can be used to delete the contact identified by the given id
  100. *
  101. * @param object $id the unique identifier to a contact
  102. * @param string $address_book_key
  103. * @return bool successful or not
  104. * @deprecated 8.1.0 use delete() of \OCP\Contacts\IManager - \OC::$server->getContactsManager();
  105. * @since 5.0.0
  106. */
  107. public static function delete($id, $address_book_key) {
  108. $cm = \OC::$server->getContactsManager();
  109. return $cm->delete($id, $address_book_key);
  110. }
  111. /**
  112. * This function is used to create a new contact if 'id' is not given or not present.
  113. * Otherwise the contact will be updated by replacing the entire data set.
  114. *
  115. * @param array $properties this array if key-value-pairs defines a contact
  116. * @param string $address_book_key identifier of the address book in which the contact shall be created or updated
  117. * @return array an array representing the contact just created or updated
  118. * @deprecated 8.1.0 use createOrUpdate() of \OCP\Contacts\IManager - \OC::$server->getContactsManager();
  119. * @since 5.0.0
  120. */
  121. public static function createOrUpdate($properties, $address_book_key) {
  122. $cm = \OC::$server->getContactsManager();
  123. return $cm->createOrUpdate($properties, $address_book_key);
  124. }
  125. /**
  126. * Check if contacts are available (e.g. contacts app enabled)
  127. *
  128. * @return bool true if enabled, false if not
  129. * @deprecated 8.1.0 use isEnabled() of \OCP\Contacts\IManager - \OC::$server->getContactsManager();
  130. * @since 5.0.0
  131. */
  132. public static function isEnabled() {
  133. $cm = \OC::$server->getContactsManager();
  134. return $cm->isEnabled();
  135. }
  136. /**
  137. * @param \OCP\IAddressBook $address_book
  138. * @deprecated 8.1.0 use registerAddressBook() of \OCP\Contacts\IManager - \OC::$server->getContactsManager();
  139. * @since 5.0.0
  140. */
  141. public static function registerAddressBook(\OCP\IAddressBook $address_book) {
  142. $cm = \OC::$server->getContactsManager();
  143. $cm->registerAddressBook($address_book);
  144. }
  145. /**
  146. * @param \OCP\IAddressBook $address_book
  147. * @deprecated 8.1.0 use unregisterAddressBook() of \OCP\Contacts\IManager - \OC::$server->getContactsManager();
  148. * @since 5.0.0
  149. */
  150. public static function unregisterAddressBook(\OCP\IAddressBook $address_book) {
  151. $cm = \OC::$server->getContactsManager();
  152. $cm->unregisterAddressBook($address_book);
  153. }
  154. /**
  155. * @return array
  156. * @deprecated 8.1.0 use getAddressBooks() of \OCP\Contacts\IManager - \OC::$server->getContactsManager();
  157. * @since 5.0.0
  158. */
  159. public static function getAddressBooks() {
  160. $cm = \OC::$server->getContactsManager();
  161. return $cm->getAddressBooks();
  162. }
  163. /**
  164. * removes all registered address book instances
  165. * @deprecated 8.1.0 use clear() of \OCP\Contacts\IManager - \OC::$server->getContactsManager();
  166. * @since 5.0.0
  167. */
  168. public static function clear() {
  169. $cm = \OC::$server->getContactsManager();
  170. $cm->clear();
  171. }
  172. }
  173. }