DashboardService.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Dashboard\Service;
  8. use JsonException;
  9. use OCP\IConfig;
  10. class DashboardService {
  11. public function __construct(
  12. private IConfig $config,
  13. private String $userId,
  14. ) {
  15. }
  16. /**
  17. * @return list<string>
  18. */
  19. public function getLayout(): array {
  20. $systemDefault = $this->config->getAppValue('dashboard', 'layout', 'recommendations,spreed,mail,calendar');
  21. return array_values(array_filter(explode(',', $this->config->getUserValue($this->userId, 'dashboard', 'layout', $systemDefault)), fn (string $value) => $value !== ''));
  22. }
  23. /**
  24. * @return list<string>
  25. */
  26. public function getStatuses() {
  27. $configStatuses = $this->config->getUserValue($this->userId, 'dashboard', 'statuses', '');
  28. try {
  29. // Parse the old format
  30. /** @var array<string, bool> $statuses */
  31. $statuses = json_decode($configStatuses, true, 512, JSON_THROW_ON_ERROR);
  32. // We avoid getting an empty array as it will not produce an object in UI's JS
  33. return array_keys(array_filter($statuses, static fn (bool $value) => $value));
  34. } catch (JsonException $e) {
  35. return array_values(array_filter(explode(',', $configStatuses), fn (string $value) => $value !== ''));
  36. }
  37. }
  38. }