aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/Command/GetAbsenceCommand.php
blob: 50d8df4ab38f86056a80bfd2c2e9ad7525d4764f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php

declare(strict_types=1);

/**
 * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-only
 */

namespace OCA\DAV\Command;

use OCA\DAV\Service\AbsenceService;
use OCP\IUserManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class GetAbsenceCommand extends Command {

	public function __construct(
		private IUserManager $userManager,
		private AbsenceService $absenceService,
	) {
		parent::__construct();
	}

	protected function configure(): void {
		$this->setName('dav:absence:get');
		$this->addArgument(
			'user-id',
			InputArgument::REQUIRED,
			'User ID of the affected account'
		);
	}

	public function execute(InputInterface $input, OutputInterface $output): int {
		$userId = $input->getArgument('user-id');

		$user = $this->userManager->get($userId);
		if ($user === null) {
			$output->writeln('<error>User not found</error>');
			return 1;
		}

		$absence = $this->absenceService->getAbsence($userId);
		if ($absence === null) {
			$output->writeln('<info>No absence set</info>');
			return 0;
		}

		$output->writeln('<info>Start day:</info> ' . $absence->getFirstDay());
		$output->writeln('<info>End day:</info> ' . $absence->getLastDay());
		$output->writeln('<info>Short message:</info> ' . $absence->getStatus());
		$output->writeln('<info>Message:</info> ' . $absence->getMessage());
		$output->writeln('<info>Replacement user:</info> ' . ($absence->getReplacementUserId() ?? 'none'));
		$output->writeln('<info>Replacement display name:</info> ' . ($absence->getReplacementUserDisplayName() ?? 'none'));

		return 0;
	}

}