localaddressbook.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * @author Joas Schilling <nickvergessen@owncloud.com>
  4. * @author Morris Jobke <hey@morrisjobke.de>
  5. * @author Thomas Müller <thomas.mueller@tmit.eu>
  6. *
  7. * @copyright Copyright (c) 2015, ownCloud, Inc.
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OC\Contacts;
  24. class LocalAddressBook implements \OCP\IAddressBook {
  25. /**
  26. * @var \OCP\IUserManager
  27. */
  28. private $userManager;
  29. /**
  30. * @param $userManager
  31. */
  32. public function __construct($userManager) {
  33. $this->userManager = $userManager;
  34. }
  35. /**
  36. * @return string defining the technical unique key
  37. */
  38. public function getKey() {
  39. return 'local';
  40. }
  41. /**
  42. * In comparison to getKey() this function returns a human readable (maybe translated) name
  43. *
  44. * @return mixed
  45. */
  46. public function getDisplayName() {
  47. return "Local users";
  48. }
  49. /**
  50. * @param string $pattern which should match within the $searchProperties
  51. * @param array $searchProperties defines the properties within the query pattern should match
  52. * @param array $options - for future use. One should always have options!
  53. * @return array an array of contacts which are arrays of key-value-pairs
  54. */
  55. public function search($pattern, $searchProperties, $options) {
  56. $users = array();
  57. if($pattern == '') {
  58. // Fetch all contacts
  59. $users = $this->userManager->search('');
  60. } else {
  61. foreach($searchProperties as $property) {
  62. $result = array();
  63. if($property === 'FN') {
  64. $result = $this->userManager->searchDisplayName($pattern);
  65. } else if ($property === 'id') {
  66. $result = $this->userManager->search($pattern);
  67. }
  68. if (is_array($result)) {
  69. $users = array_merge($users, $result);
  70. }
  71. }
  72. }
  73. $contacts = array();
  74. foreach($users as $user){
  75. $contact = array(
  76. "id" => $user->getUID(),
  77. "FN" => $user->getDisplayname(),
  78. "EMAIL" => array(),
  79. "IMPP" => array(
  80. "x-owncloud-handle:" . $user->getUID()
  81. )
  82. );
  83. $contacts[] = $contact;
  84. }
  85. return $contacts;
  86. }
  87. /**
  88. * @param array $properties this array if key-value-pairs defines a contact
  89. * @return array an array representing the contact just created or updated
  90. */
  91. public function createOrUpdate($properties) {
  92. return array();
  93. }
  94. /**
  95. * @return int
  96. */
  97. public function getPermissions() {
  98. return \OCP\Constants::PERMISSION_READ;
  99. }
  100. /**
  101. * @param object $id the unique identifier to a contact
  102. * @return bool successful or not
  103. */
  104. public function delete($id) {
  105. return false;
  106. }
  107. }