You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PredefinedStatusController.php 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2020, Georg Ehrke
  5. *
  6. * @author Georg Ehrke <oc.list@georgehrke.com>
  7. * @author Kate Döen <kate.doeen@nextcloud.com>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCA\UserStatus\Controller;
  26. use OCA\UserStatus\ResponseDefinitions;
  27. use OCA\UserStatus\Service\PredefinedStatusService;
  28. use OCP\AppFramework\Http;
  29. use OCP\AppFramework\Http\DataResponse;
  30. use OCP\AppFramework\OCSController;
  31. use OCP\IRequest;
  32. /**
  33. * @package OCA\UserStatus\Controller
  34. *
  35. * @psalm-import-type UserStatusPredefined from ResponseDefinitions
  36. */
  37. class PredefinedStatusController extends OCSController {
  38. /** @var PredefinedStatusService */
  39. private $predefinedStatusService;
  40. /**
  41. * AStatusController constructor.
  42. *
  43. * @param string $appName
  44. * @param IRequest $request
  45. * @param PredefinedStatusService $predefinedStatusService
  46. */
  47. public function __construct(string $appName,
  48. IRequest $request,
  49. PredefinedStatusService $predefinedStatusService) {
  50. parent::__construct($appName, $request);
  51. $this->predefinedStatusService = $predefinedStatusService;
  52. }
  53. /**
  54. * Get all predefined messages
  55. *
  56. * @NoAdminRequired
  57. *
  58. * @return DataResponse<Http::STATUS_OK, UserStatusPredefined[], array{}>
  59. *
  60. * 200: Predefined statuses returned
  61. */
  62. public function findAll():DataResponse {
  63. // Filtering out the invisible one, that should only be set by API
  64. return new DataResponse(array_filter($this->predefinedStatusService->getDefaultStatuses(), function (array $status) {
  65. return !array_key_exists('visible', $status) || $status['visible'] === true;
  66. }));
  67. }
  68. }