usercontroller.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Copyright (c) 2014 Jörn Dreyer <jfd@owncloud.com>
  4. * Copyright (c) 2014 Lukas Reschke <lukas@owncloud.com>
  5. * This file is licensed under the Affero General Public License version 3 or
  6. * later.
  7. * See the COPYING-README file.
  8. */
  9. namespace OC\Core\User;
  10. use \OCP\AppFramework\Controller;
  11. use \OCP\AppFramework\Http\JSONResponse;
  12. use \OCP\IRequest;
  13. class UserController extends Controller {
  14. /**
  15. * @var \OCP\IUserManager
  16. */
  17. protected $userManager;
  18. /**
  19. * @var \OC_Defaults
  20. */
  21. protected $defaults;
  22. public function __construct($appName,
  23. IRequest $request,
  24. $userManager,
  25. $defaults
  26. ) {
  27. parent::__construct($appName, $request);
  28. $this->userManager = $userManager;
  29. $this->defaults = $defaults;
  30. }
  31. /**
  32. * Lookup user display names
  33. *
  34. * @NoAdminRequired
  35. *
  36. * @param array $users
  37. *
  38. * @return JSONResponse
  39. */
  40. public function getDisplayNames($users) {
  41. $result = array();
  42. foreach ($users as $user) {
  43. $userObject = $this->userManager->get($user);
  44. if (is_object($userObject)) {
  45. $result[$user] = $userObject->getDisplayName();
  46. } else {
  47. $result[$user] = $user;
  48. }
  49. }
  50. $json = array(
  51. 'users' => $result,
  52. 'status' => 'success'
  53. );
  54. return new JSONResponse($json);
  55. }
  56. }