PredefinedStatusController.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\UserStatus\Controller;
  8. use OCA\UserStatus\ResponseDefinitions;
  9. use OCA\UserStatus\Service\PredefinedStatusService;
  10. use OCP\AppFramework\Http;
  11. use OCP\AppFramework\Http\Attribute\ApiRoute;
  12. use OCP\AppFramework\Http\Attribute\NoAdminRequired;
  13. use OCP\AppFramework\Http\DataResponse;
  14. use OCP\AppFramework\OCSController;
  15. use OCP\IRequest;
  16. /**
  17. * @package OCA\UserStatus\Controller
  18. *
  19. * @psalm-import-type UserStatusPredefined from ResponseDefinitions
  20. */
  21. class PredefinedStatusController extends OCSController {
  22. /** @var PredefinedStatusService */
  23. private $predefinedStatusService;
  24. /**
  25. * AStatusController constructor.
  26. *
  27. * @param string $appName
  28. * @param IRequest $request
  29. * @param PredefinedStatusService $predefinedStatusService
  30. */
  31. public function __construct(string $appName,
  32. IRequest $request,
  33. PredefinedStatusService $predefinedStatusService) {
  34. parent::__construct($appName, $request);
  35. $this->predefinedStatusService = $predefinedStatusService;
  36. }
  37. /**
  38. * Get all predefined messages
  39. *
  40. * @return DataResponse<Http::STATUS_OK, UserStatusPredefined[], array{}>
  41. *
  42. * 200: Predefined statuses returned
  43. */
  44. #[NoAdminRequired]
  45. #[ApiRoute(verb: 'GET', url: '/api/v1/predefined_statuses/')]
  46. public function findAll():DataResponse {
  47. // Filtering out the invisible one, that should only be set by API
  48. return new DataResponse(array_filter($this->predefinedStatusService->getDefaultStatuses(), function (array $status) {
  49. return !array_key_exists('visible', $status) || $status['visible'] === true;
  50. }));
  51. }
  52. }