UserController.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * @author Lukas Reschke <lukas@owncloud.com>
  4. * @author Morris Jobke <hey@morrisjobke.de>
  5. *
  6. * @copyright Copyright (c) 2016, ownCloud, Inc.
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OC\Core\Controller;
  23. use \OCP\AppFramework\Controller;
  24. use \OCP\AppFramework\Http\JSONResponse;
  25. use \OCP\IRequest;
  26. class UserController extends Controller {
  27. /**
  28. * @var \OCP\IUserManager
  29. */
  30. protected $userManager;
  31. /**
  32. * @var \OC_Defaults
  33. */
  34. protected $defaults;
  35. public function __construct($appName,
  36. IRequest $request,
  37. $userManager,
  38. $defaults
  39. ) {
  40. parent::__construct($appName, $request);
  41. $this->userManager = $userManager;
  42. $this->defaults = $defaults;
  43. }
  44. /**
  45. * Lookup user display names
  46. *
  47. * @NoAdminRequired
  48. *
  49. * @param array $users
  50. *
  51. * @return JSONResponse
  52. */
  53. public function getDisplayNames($users) {
  54. $result = array();
  55. foreach ($users as $user) {
  56. $userObject = $this->userManager->get($user);
  57. if (is_object($userObject)) {
  58. $result[$user] = $userObject->getDisplayName();
  59. } else {
  60. $result[$user] = $user;
  61. }
  62. }
  63. $json = array(
  64. 'users' => $result,
  65. 'status' => 'success'
  66. );
  67. return new JSONResponse($json);
  68. }
  69. }